Code refactoring + put named arguments completion into more reasonable order
This commit is contained in:
+45
-42
@@ -86,11 +86,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
filter
|
filter
|
||||||
}
|
}
|
||||||
|
|
||||||
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
|
|
||||||
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
|
||||||
else
|
|
||||||
null
|
|
||||||
|
|
||||||
private val smartCompletion = expression?.let {
|
private val smartCompletion = expression?.let {
|
||||||
SmartCompletion(
|
SmartCompletion(
|
||||||
it, resolutionFacade, bindingContext, moduleDescriptor, isVisibleFilter, prefixMatcher,
|
it, resolutionFacade, bindingContext, moduleDescriptor, isVisibleFilter, prefixMatcher,
|
||||||
@@ -165,37 +160,25 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completionKind == CompletionKind.SUPER_QUALIFIER) {
|
when (completionKind) {
|
||||||
completeSuperQualifier()
|
CompletionKind.SUPER_QUALIFIER -> completeSuperQualifier()
|
||||||
return
|
|
||||||
|
CompletionKind.TOP_LEVEL_CLASS_NAME -> completeTopLevelClassName()
|
||||||
|
|
||||||
|
CompletionKind.NAMED_ARGUMENTS_ONLY -> NamedArgumentCompletion.complete(collector, expectedInfos)
|
||||||
|
|
||||||
|
CompletionKind.KEYWORDS_ONLY -> completeKeywords()
|
||||||
|
|
||||||
|
CompletionKind.PARAMETER_NAME -> {
|
||||||
|
completeKeywords()
|
||||||
|
completeParameterNameAndType()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completionKind == CompletionKind.TOP_LEVEL_CLASS_NAME) {
|
CompletionKind.ALL -> completeAll()
|
||||||
completeTopLevelClassName()
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we are typing parameter name, restart completion each time we type an upper case letter because new suggestions will appear (previous words can be used as user prefix)
|
private fun completeAll() {
|
||||||
if (parameterNameAndTypeCompletion != null) {
|
|
||||||
val prefixPattern = StandardPatterns.string().with(object : PatternCondition<String>("Prefix ends with uppercase letter") {
|
|
||||||
override fun accepts(prefix: String, context: ProcessingContext?) = prefix.isNotEmpty() && prefix.last().isUpperCase()
|
|
||||||
})
|
|
||||||
collector.restartCompletionOnPrefixChange(prefixPattern)
|
|
||||||
|
|
||||||
collector.addLookupElementPostProcessor { lookupElement ->
|
|
||||||
lookupElement.putUserData(KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING, Unit)
|
|
||||||
lookupElement.putUserData(KotlinCompletionCharFilter.HIDE_LOOKUP_ON_COLON, Unit)
|
|
||||||
lookupElement
|
|
||||||
}
|
|
||||||
|
|
||||||
parameterNameAndTypeCompletion.addFromParametersInFile(position, resolutionFacade, isVisibleFilter)
|
|
||||||
flushToResultSet()
|
|
||||||
|
|
||||||
parameterNameAndTypeCompletion.addFromImportedClasses(position, bindingContext, isVisibleFilter)
|
|
||||||
flushToResultSet()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completionKind != CompletionKind.NAMED_ARGUMENTS_ONLY) {
|
|
||||||
if (smartCompletion != null) {
|
if (smartCompletion != null) {
|
||||||
val (additionalItems, @Suppress("UNUSED_VARIABLE") inheritanceSearcher) = smartCompletion.additionalItems(lookupElementFactory)
|
val (additionalItems, @Suppress("UNUSED_VARIABLE") inheritanceSearcher) = smartCompletion.additionalItems(lookupElementFactory)
|
||||||
|
|
||||||
@@ -209,11 +192,9 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
collector.addElements(additionalItems)
|
collector.addElements(additionalItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
referenceVariants?.let {
|
val (imported, notImported) = referenceVariants!!
|
||||||
val (imported, notImported) = it
|
|
||||||
collector.addDescriptorElements(imported, lookupElementFactory)
|
collector.addDescriptorElements(imported, lookupElementFactory)
|
||||||
collector.addDescriptorElements(notImported, lookupElementFactory, notImported = true)
|
collector.addDescriptorElements(notImported, lookupElementFactory, notImported = true)
|
||||||
}
|
|
||||||
|
|
||||||
completeKeywords()
|
completeKeywords()
|
||||||
|
|
||||||
@@ -237,12 +218,15 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
|
|
||||||
if (completionKind != CompletionKind.KEYWORDS_ONLY) {
|
NamedArgumentCompletion.complete(collector, expectedInfos)
|
||||||
completeNonImported()
|
|
||||||
|
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
|
|
||||||
if (position.getContainingFile() is KtCodeFragment) {
|
if (completionKind != CompletionKind.KEYWORDS_ONLY) {
|
||||||
|
completeNonImported()
|
||||||
|
flushToResultSet()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completionKind == CompletionKind.ALL && position.getContainingFile() is KtCodeFragment) {
|
||||||
val variantsAndFactory = getRuntimeReceiverTypeReferenceVariants()
|
val variantsAndFactory = getRuntimeReceiverTypeReferenceVariants()
|
||||||
if (variantsAndFactory != null) {
|
if (variantsAndFactory != null) {
|
||||||
val variants = variantsAndFactory.first
|
val variants = variantsAndFactory.first
|
||||||
@@ -253,9 +237,30 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun completeParameterNameAndType() {
|
||||||
|
if (!shouldCompleteParameterNameAndType()) return
|
||||||
|
val parameterNameAndTypeCompletion = ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
||||||
|
|
||||||
|
// if we are typing parameter name, restart completion each time we type an upper case letter because new suggestions will appear (previous words can be used as user prefix)
|
||||||
|
val prefixPattern = StandardPatterns.string().with(object : PatternCondition<String>("Prefix ends with uppercase letter") {
|
||||||
|
override fun accepts(prefix: String, context: ProcessingContext?) = prefix.isNotEmpty() && prefix.last().isUpperCase()
|
||||||
|
})
|
||||||
|
collector.restartCompletionOnPrefixChange(prefixPattern)
|
||||||
|
|
||||||
|
collector.addLookupElementPostProcessor { lookupElement ->
|
||||||
|
lookupElement.putUserData(KotlinCompletionCharFilter.SUPPRESS_ITEM_SELECTION_BY_CHARS_ON_TYPING, Unit)
|
||||||
|
lookupElement.putUserData(KotlinCompletionCharFilter.HIDE_LOOKUP_ON_COLON, Unit)
|
||||||
|
lookupElement
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedArgumentCompletion.complete(collector, expectedInfos)
|
parameterNameAndTypeCompletion.addFromParametersInFile(position, resolutionFacade, isVisibleFilter)
|
||||||
|
flushToResultSet()
|
||||||
|
|
||||||
|
parameterNameAndTypeCompletion.addFromImportedClasses(position, bindingContext, isVisibleFilter)
|
||||||
|
flushToResultSet()
|
||||||
|
|
||||||
|
parameterNameAndTypeCompletion.addFromAllClasses(parameters, indicesHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun completeKeywords() {
|
private fun completeKeywords() {
|
||||||
@@ -399,8 +404,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
collector.advertiseSecondCompletion()
|
collector.advertiseSecondCompletion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parameterNameAndTypeCompletion?.addFromAllClasses(parameters, indicesHelper)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun completeSuperQualifier() {
|
private fun completeSuperQualifier() {
|
||||||
|
|||||||
Reference in New Issue
Block a user