More correct types filtering in code completion
This commit is contained in:
@@ -103,32 +103,25 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
|||||||
{ isVisibleDescriptor(it) })
|
{ isVisibleDescriptor(it) })
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun shouldRunTopLevelCompletion(): Boolean {
|
protected fun shouldRunTopLevelCompletion(): Boolean
|
||||||
if (!configuration.completeNonImportedDeclarations) return false
|
= configuration.completeNonImportedDeclarations && isNoQualifierContext()
|
||||||
|
|
||||||
if (position.getNode()!!.getElementType() == JetTokens.IDENTIFIER) {
|
protected fun isNoQualifierContext(): Boolean {
|
||||||
val parent = position.getParent()
|
val parent = position.getParent()
|
||||||
if (parent is JetSimpleNameExpression && !JetPsiUtil.isSelectorInQualified(parent)) return true
|
return parent is JetSimpleNameExpression && !JetPsiUtil.isSelectorInQualified(parent)
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun shouldRunExtensionsCompletion(): Boolean {
|
protected fun shouldRunExtensionsCompletion(): Boolean
|
||||||
return configuration.completeNonImportedDeclarations || prefixMatcher.getPrefix().length >= 3
|
= configuration.completeNonImportedDeclarations || prefixMatcher.getPrefix().length >= 3
|
||||||
}
|
|
||||||
|
|
||||||
protected fun getKotlinTopLevelCallables(): Collection<DeclarationDescriptor> {
|
protected fun getKotlinTopLevelCallables(): Collection<DeclarationDescriptor>
|
||||||
return indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression)
|
= indicesHelper.getTopLevelCallables({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression)
|
||||||
}
|
|
||||||
|
|
||||||
protected fun getKotlinTopLevelObjects(): Collection<DeclarationDescriptor> {
|
protected fun getKotlinTopLevelObjects(): Collection<DeclarationDescriptor>
|
||||||
return indicesHelper.getTopLevelObjects({ prefixMatcher.prefixMatches(it) })
|
= indicesHelper.getTopLevelObjects({ prefixMatcher.prefixMatches(it) })
|
||||||
}
|
|
||||||
|
|
||||||
protected fun getKotlinExtensions(): Collection<CallableDescriptor> {
|
protected fun getKotlinExtensions(): Collection<CallableDescriptor>
|
||||||
return indicesHelper.getCallableExtensions({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression)
|
= indicesHelper.getCallableExtensions({ prefixMatcher.prefixMatches(it) }, jetReference!!.expression)
|
||||||
}
|
|
||||||
|
|
||||||
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {
|
protected fun addAllClasses(kindFilter: (ClassKind) -> Boolean) {
|
||||||
AllClassesCompletion(parameters, resolveSession, searchScope, prefixMatcher, kindFilter, { isVisibleDescriptor(it) }).collect(collector)
|
AllClassesCompletion(parameters, resolveSession, searchScope, prefixMatcher, kindFilter, { isVisibleDescriptor(it) }).collect(collector)
|
||||||
@@ -145,41 +138,41 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
if (!NamedParametersCompletion.isOnlyNamedParameterExpected(position)) {
|
if (!NamedParametersCompletion.isOnlyNamedParameterExpected(position)) {
|
||||||
val completeReference = jetReference != null && !isOnlyKeywordCompletion()
|
val completeReference = jetReference != null && !isOnlyKeywordCompletion()
|
||||||
|
val onlyTypes = shouldRunOnlyTypeCompletion()
|
||||||
|
|
||||||
if (completeReference) {
|
if (completeReference) {
|
||||||
if (shouldRunOnlyTypeCompletion()) {
|
addReferenceVariants(if (onlyTypes) JetScope.TYPE or JetScope.PACKAGE else JetScope.ALL_KINDS_MASK)
|
||||||
if (configuration.completeNonImportedDeclarations) {
|
|
||||||
addAllClasses { !it.isSingleton() }
|
if (onlyTypes) {
|
||||||
}
|
collector.addDescriptorElements(listOf(KotlinBuiltIns.getInstance().getUnit()), false)
|
||||||
else {
|
|
||||||
addReferenceVariants(JetScope.TYPE or JetScope.PACKAGE)
|
|
||||||
collector.addDescriptorElements(listOf(KotlinBuiltIns.getInstance().getUnit()), false)
|
|
||||||
JavaCompletionContributor.advertiseSecondCompletion(project, resultSet)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
addReferenceVariants(JetScope.ALL_KINDS_MASK)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeywordCompletion.complete(parameters, prefixMatcher.getPrefix(), collector)
|
KeywordCompletion.complete(parameters, prefixMatcher.getPrefix(), collector)
|
||||||
|
|
||||||
if (completeReference && !shouldRunOnlyTypeCompletion()) {
|
if (completeReference) {
|
||||||
|
if (!configuration.completeNonImportedDeclarations && isNoQualifierContext()) {
|
||||||
|
JavaCompletionContributor.advertiseSecondCompletion(project, resultSet)
|
||||||
|
}
|
||||||
|
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
addNonImported()
|
addNonImported(onlyTypes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedParametersCompletion.complete(position, collector)
|
NamedParametersCompletion.complete(position, collector)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNonImported() {
|
private fun addNonImported(onlyTypes: Boolean) {
|
||||||
if (shouldRunTopLevelCompletion()) {
|
if (shouldRunTopLevelCompletion()) {
|
||||||
addAllClasses { it != ClassKind.ENUM_ENTRY }
|
addAllClasses { if (onlyTypes) !it.isSingleton() else it != ClassKind.ENUM_ENTRY }
|
||||||
collector.addDescriptorElements(getKotlinTopLevelCallables(), suppressAutoInsertion = true)
|
|
||||||
|
if (!onlyTypes) {
|
||||||
|
collector.addDescriptorElements(getKotlinTopLevelCallables(), suppressAutoInsertion = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRunExtensionsCompletion()) {
|
if (!onlyTypes && shouldRunExtensionsCompletion()) {
|
||||||
collector.addDescriptorElements(getKotlinExtensions(), suppressAutoInsertion = true)
|
collector.addDescriptorElements(getKotlinExtensions(), suppressAutoInsertion = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user