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 fun getReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext, visibilityFilter: (DeclarationDescriptor) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return getReferenceVariants(expression, context).filter(visibilityFilter)
|
||||
public fun getReferenceVariants(expression: JetSimpleNameExpression,
|
||||
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 parent = expression.getParent()
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
@@ -58,7 +63,7 @@ public object TipsManager{
|
||||
if (qualifier != null) {
|
||||
//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)
|
||||
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]
|
||||
@@ -81,7 +86,7 @@ public object TipsManager{
|
||||
}
|
||||
|
||||
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 {
|
||||
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
||||
@@ -90,7 +95,7 @@ public object TipsManager{
|
||||
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))
|
||||
|
||||
@@ -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()
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }))
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||
}
|
||||
|
||||
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>,
|
||||
|
||||
@@ -86,6 +86,13 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
|
||||
protected abstract fun doComplete()
|
||||
|
||||
protected fun getReferenceVariants(): Collection<DeclarationDescriptor> {
|
||||
return TipsManager.getReferenceVariants(jetReference!!.expression,
|
||||
bindingContext!!,
|
||||
{ prefixMatcher.prefixMatches(it) },
|
||||
{ isVisibleDescriptor(it) })
|
||||
}
|
||||
|
||||
protected fun shouldRunTopLevelCompletion(): Boolean {
|
||||
if (!configuration.completeNonImportedDeclarations) return false
|
||||
|
||||
@@ -193,8 +200,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
private fun addReferenceVariants(filterCondition: (DeclarationDescriptor) -> Boolean = { true }) {
|
||||
val descriptors = TipsManager.getReferenceVariants(jetReference!!.expression, bindingContext!!) { isVisibleDescriptor(it) }
|
||||
collector.addDescriptorElements(descriptors.filter { filterCondition(it) }, suppressAutoInsertion = false)
|
||||
collector.addDescriptorElements(getReferenceVariants().filter { filterCondition(it) }, suppressAutoInsertion = false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +216,11 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
|
||||
val filter = result.declarationFilter
|
||||
if (filter != null) {
|
||||
TipsManager.getReferenceVariants(jetReference.expression, bindingContext!!) { isVisibleDescriptor(it) }
|
||||
.forEach { if (prefixMatcher.prefixMatches(it.getName().asString())) collector.addElements(filter(it)) }
|
||||
getReferenceVariants().forEach {
|
||||
if (prefixMatcher.prefixMatches(it.getName().asString())) {
|
||||
collector.addElements(filter(it))
|
||||
}
|
||||
}
|
||||
|
||||
flushToResultSet()
|
||||
|
||||
|
||||
@@ -47,12 +47,13 @@ object PackageDirectiveCompletion {
|
||||
|
||||
try {
|
||||
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 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) {
|
||||
val lookupElement = KotlinLookupElementFactory.createLookupElement(resolveSession, variant)
|
||||
if (!lookupElement.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||
|
||||
+10
-3
@@ -370,7 +370,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
return null;
|
||||
}
|
||||
|
||||
JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
|
||||
final JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
|
||||
if (callNameExpression == 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();
|
||||
|
||||
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>>();
|
||||
for (DeclarationDescriptor variant : variants) {
|
||||
if (variant instanceof FunctionDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user