Completion to pass nameFilter to getDescriptors() calls
This commit is contained in:
@@ -33,11 +33,16 @@ import org.jetbrains.jet.lang.resolve.descriptorUtil.isExtension
|
|||||||
|
|
||||||
public object TipsManager{
|
public object TipsManager{
|
||||||
|
|
||||||
public fun getReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext, visibilityFilter: (DeclarationDescriptor) -> Boolean): Collection<DeclarationDescriptor> {
|
public fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||||
return getReferenceVariants(expression, context).filter(visibilityFilter)
|
context: BindingContext,
|
||||||
|
nameFilter: (String) -> Boolean,
|
||||||
|
visibilityFilter: (DeclarationDescriptor) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
|
return getReferenceVariants(expression, context, nameFilter).filter(visibilityFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext): Collection<DeclarationDescriptor> {
|
private fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||||
|
context: BindingContext,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
val receiverExpression = expression.getReceiverExpression()
|
val receiverExpression = expression.getReceiverExpression()
|
||||||
val parent = expression.getParent()
|
val parent = expression.getParent()
|
||||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||||
@@ -58,7 +63,7 @@ public object TipsManager{
|
|||||||
if (qualifier != null) {
|
if (qualifier != null) {
|
||||||
//TODO: filter out extensions!
|
//TODO: filter out extensions!
|
||||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||||
qualifier.scope.getDescriptors(JetScope.DescriptorKind.NON_EXTENSIONS).filterTo(descriptors, ::filterIfInfix)
|
qualifier.scope.getDescriptors(JetScope.DescriptorKind.NON_EXTENSIONS, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||||
}
|
}
|
||||||
|
|
||||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||||
@@ -81,7 +86,7 @@ public object TipsManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }))
|
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
||||||
@@ -90,7 +95,7 @@ public object TipsManager{
|
|||||||
receiverDescriptor.getType().getMemberScope().getDescriptors().filterTo(descriptorsSet) { !it.isExtension }
|
receiverDescriptor.getType().getMemberScope().getDescriptors().filterTo(descriptorsSet) { !it.isExtension }
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptorsSet.addAll(resolutionScope.getDescriptors())
|
descriptorsSet.addAll(resolutionScope.getDescriptors({ true }, nameFilter))
|
||||||
|
|
||||||
descriptorsSet.excludeNotCallableExtensions(resolutionScope, context, context.getDataFlowInfo(expression))
|
descriptorsSet.excludeNotCallableExtensions(resolutionScope, context, context.getDataFlowInfo(expression))
|
||||||
|
|
||||||
@@ -98,9 +103,11 @@ public object TipsManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getPackageReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext): Collection<DeclarationDescriptor> {
|
public fun getPackageReferenceVariants(expression: JetSimpleNameExpression,
|
||||||
|
context: BindingContext,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }))
|
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>,
|
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>,
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
|||||||
|
|
||||||
protected abstract fun doComplete()
|
protected abstract fun doComplete()
|
||||||
|
|
||||||
|
protected fun getReferenceVariants(): Collection<DeclarationDescriptor> {
|
||||||
|
return TipsManager.getReferenceVariants(jetReference!!.expression,
|
||||||
|
bindingContext!!,
|
||||||
|
{ prefixMatcher.prefixMatches(it) },
|
||||||
|
{ isVisibleDescriptor(it) })
|
||||||
|
}
|
||||||
|
|
||||||
protected fun shouldRunTopLevelCompletion(): Boolean {
|
protected fun shouldRunTopLevelCompletion(): Boolean {
|
||||||
if (!configuration.completeNonImportedDeclarations) return false
|
if (!configuration.completeNonImportedDeclarations) return false
|
||||||
|
|
||||||
@@ -193,8 +200,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addReferenceVariants(filterCondition: (DeclarationDescriptor) -> Boolean = { true }) {
|
private fun addReferenceVariants(filterCondition: (DeclarationDescriptor) -> Boolean = { true }) {
|
||||||
val descriptors = TipsManager.getReferenceVariants(jetReference!!.expression, bindingContext!!) { isVisibleDescriptor(it) }
|
collector.addDescriptorElements(getReferenceVariants().filter { filterCondition(it) }, suppressAutoInsertion = false)
|
||||||
collector.addDescriptorElements(descriptors.filter { filterCondition(it) }, suppressAutoInsertion = false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +216,11 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
|||||||
|
|
||||||
val filter = result.declarationFilter
|
val filter = result.declarationFilter
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
TipsManager.getReferenceVariants(jetReference.expression, bindingContext!!) { isVisibleDescriptor(it) }
|
getReferenceVariants().forEach {
|
||||||
.forEach { if (prefixMatcher.prefixMatches(it.getName().asString())) collector.addElements(filter(it)) }
|
if (prefixMatcher.prefixMatches(it.getName().asString())) {
|
||||||
|
collector.addElements(filter(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,13 @@ object PackageDirectiveCompletion {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val prefixLength = parameters.getOffset() - ref.expression.getTextOffset()
|
val prefixLength = parameters.getOffset() - ref.expression.getTextOffset()
|
||||||
var result = result.withPrefixMatcher(PlainPrefixMatcher(name.substring(0, prefixLength)))
|
val prefixMatcher = PlainPrefixMatcher(name.substring(0, prefixLength))
|
||||||
|
val result = result.withPrefixMatcher(prefixMatcher)
|
||||||
|
|
||||||
val resolveSession = ref.expression.getLazyResolveSession()
|
val resolveSession = ref.expression.getLazyResolveSession()
|
||||||
val bindingContext = resolveSession.resolveToElement(ref.expression)
|
val bindingContext = resolveSession.resolveToElement(ref.expression)
|
||||||
|
|
||||||
val variants = TipsManager.getPackageReferenceVariants(ref.expression, bindingContext)
|
val variants = TipsManager.getPackageReferenceVariants(ref.expression, bindingContext, { prefixMatcher.prefixMatches(it) })
|
||||||
for (variant in variants) {
|
for (variant in variants) {
|
||||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant)
|
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant)
|
||||||
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||||
|
|||||||
+10
-3
@@ -370,7 +370,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
|
final JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
|
||||||
if (callNameExpression == null) {
|
if (callNameExpression == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -399,10 +399,17 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Collection<DeclarationDescriptor> variants = TipsManager.INSTANCE$.getReferenceVariants(callNameExpression, bindingContext, visibilityFilter);
|
|
||||||
|
|
||||||
Name refName = callNameExpression.getReferencedNameAsName();
|
Name refName = callNameExpression.getReferencedNameAsName();
|
||||||
|
|
||||||
|
final String refNameString = refName.isSpecial() ? null : refName.asString();
|
||||||
|
Function1<String, Boolean> nameFilter = new Function1<String, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean invoke(String s) {
|
||||||
|
return refNameString == null || s.equals(refNameString);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Collection<DeclarationDescriptor> variants = TipsManager.INSTANCE$.getReferenceVariants(callNameExpression, bindingContext, nameFilter, visibilityFilter);
|
||||||
|
|
||||||
Collection<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>>();
|
Collection<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSessionForBodies>>();
|
||||||
for (DeclarationDescriptor variant : variants) {
|
for (DeclarationDescriptor variant : variants) {
|
||||||
if (variant instanceof FunctionDescriptor) {
|
if (variant instanceof FunctionDescriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user