Better formatting of BasicCompletionSession
This commit is contained in:
+183
-131
@@ -72,10 +72,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
|
|
||||||
class BasicCompletionSession(
|
class BasicCompletionSession(
|
||||||
configuration: CompletionSessionConfiguration,
|
configuration: CompletionSessionConfiguration,
|
||||||
parameters: CompletionParameters,
|
parameters: CompletionParameters,
|
||||||
toFromOriginalFileMapper: ToFromOriginalFileMapper,
|
toFromOriginalFileMapper: ToFromOriginalFileMapper,
|
||||||
resultSet: CompletionResultSet
|
resultSet: CompletionResultSet
|
||||||
) : CompletionSession(configuration, parameters, toFromOriginalFileMapper, resultSet) {
|
) : CompletionSession(configuration, parameters, toFromOriginalFileMapper, resultSet) {
|
||||||
|
|
||||||
private interface CompletionKind {
|
private interface CompletionKind {
|
||||||
@@ -95,9 +95,9 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
private val smartCompletion = expression?.let {
|
private val smartCompletion = expression?.let {
|
||||||
SmartCompletion(
|
SmartCompletion(
|
||||||
it, resolutionFacade, bindingContext, moduleDescriptor, isVisibleFilter, indicesHelper(false), prefixMatcher,
|
it, resolutionFacade, bindingContext, moduleDescriptor, isVisibleFilter, indicesHelper(false), prefixMatcher,
|
||||||
GlobalSearchScope.EMPTY_SCOPE, toFromOriginalFileMapper, callTypeAndReceiver,
|
GlobalSearchScope.EMPTY_SCOPE, toFromOriginalFileMapper, callTypeAndReceiver,
|
||||||
isJvmModule, forBasicCompletion = true
|
isJvmModule, forBasicCompletion = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
private fun detectCompletionKind(): CompletionKind {
|
private fun detectCompletionKind(): CompletionKind {
|
||||||
if (nameExpression == null) {
|
if (nameExpression == null) {
|
||||||
return when {
|
return when {
|
||||||
(position.parent as? KtNamedDeclaration)?.nameIdentifier == position -> DECLARATION_NAME
|
(position.parent as? KtNamedDeclaration)?.nameIdentifier == position -> DECLARATION_NAME
|
||||||
|
|
||||||
else -> KEYWORDS_ONLY
|
else -> KEYWORDS_ONLY
|
||||||
@@ -127,11 +127,9 @@ class BasicCompletionSession(
|
|||||||
return ALL
|
return ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldDisableAutoPopup(): Boolean
|
fun shouldDisableAutoPopup(): Boolean = completionKind.shouldDisableAutoPopup()
|
||||||
= completionKind.shouldDisableAutoPopup()
|
|
||||||
|
|
||||||
override fun shouldCompleteTopLevelCallablesFromIndex()
|
override fun shouldCompleteTopLevelCallablesFromIndex() = super.shouldCompleteTopLevelCallablesFromIndex() && prefix.isNotEmpty()
|
||||||
= super.shouldCompleteTopLevelCallablesFromIndex() && prefix.isNotEmpty()
|
|
||||||
|
|
||||||
override fun doComplete() {
|
override fun doComplete() {
|
||||||
assert(parameters.completionType == CompletionType.BASIC)
|
assert(parameters.completionType == CompletionType.BASIC)
|
||||||
@@ -167,10 +165,13 @@ class BasicCompletionSession(
|
|||||||
var sorter = super.createSorter()
|
var sorter = super.createSorter()
|
||||||
|
|
||||||
if (smartCompletion != null) {
|
if (smartCompletion != null) {
|
||||||
val smartCompletionInBasicWeigher = SmartCompletionInBasicWeigher(smartCompletion, callTypeAndReceiver, resolutionFacade, bindingContext)
|
val smartCompletionInBasicWeigher =
|
||||||
sorter = sorter.weighBefore(KindWeigher.toString(),
|
SmartCompletionInBasicWeigher(smartCompletion, callTypeAndReceiver, resolutionFacade, bindingContext)
|
||||||
smartCompletionInBasicWeigher,
|
sorter = sorter.weighBefore(
|
||||||
CallableReferenceWeigher(callTypeAndReceiver.callType))
|
KindWeigher.toString(),
|
||||||
|
smartCompletionInBasicWeigher,
|
||||||
|
CallableReferenceWeigher(callTypeAndReceiver.callType)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
sorter = completionKind.addWeighers(sorter)
|
sorter = completionKind.addWeighers(sorter)
|
||||||
@@ -214,7 +215,9 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
fun completeWithSmartCompletion(lookupElementFactory: LookupElementFactory) {
|
fun completeWithSmartCompletion(lookupElementFactory: LookupElementFactory) {
|
||||||
if (smartCompletion != null) {
|
if (smartCompletion != null) {
|
||||||
val (additionalItems, @Suppress("UNUSED_VARIABLE") inheritanceSearcher) = smartCompletion.additionalItems(lookupElementFactory)
|
val (additionalItems, @Suppress("UNUSED_VARIABLE") inheritanceSearcher) = smartCompletion.additionalItems(
|
||||||
|
lookupElementFactory
|
||||||
|
)
|
||||||
|
|
||||||
// all additional items should have SMART_COMPLETION_ITEM_PRIORITY_KEY to be recognized by SmartCompletionInBasicWeigher
|
// all additional items should have SMART_COMPLETION_ITEM_PRIORITY_KEY to be recognized by SmartCompletionInBasicWeigher
|
||||||
for (item in additionalItems) {
|
for (item in additionalItems) {
|
||||||
@@ -239,8 +242,8 @@ class BasicCompletionSession(
|
|||||||
val contextVariableTypesForReferenceVariants = withCollectRequiredContextVariableTypes { lookupElementFactory ->
|
val contextVariableTypesForReferenceVariants = withCollectRequiredContextVariableTypes { lookupElementFactory ->
|
||||||
when {
|
when {
|
||||||
prefix.isEmpty()
|
prefix.isEmpty()
|
||||||
|| callTypeAndReceiver.receiver != null
|
|| callTypeAndReceiver.receiver != null
|
||||||
|| CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE == CodeInsightSettings.NONE -> {
|
|| CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE == CodeInsightSettings.NONE -> {
|
||||||
addReferenceVariantElements(lookupElementFactory, descriptorKindFilter)
|
addReferenceVariantElements(lookupElementFactory, descriptorKindFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +268,7 @@ class BasicCompletionSession(
|
|||||||
if (callTypeAndReceiver.receiver == null && callTypeAndReceiver.callType.descriptorKindFilter.kindMask.and(DescriptorKindFilter.PACKAGES_MASK) != 0) {
|
if (callTypeAndReceiver.receiver == null && callTypeAndReceiver.callType.descriptorKindFilter.kindMask.and(DescriptorKindFilter.PACKAGES_MASK) != 0) {
|
||||||
//TODO: move this code somewhere else?
|
//TODO: move this code somewhere else?
|
||||||
val packageNames = PackageIndexUtil.getSubPackageFqNames(FqName.ROOT, searchScope, project, prefixMatcher.asNameFilter())
|
val packageNames = PackageIndexUtil.getSubPackageFqNames(FqName.ROOT, searchScope, project, prefixMatcher.asNameFilter())
|
||||||
.toMutableSet()
|
.toMutableSet()
|
||||||
|
|
||||||
if (TargetPlatformDetector.getPlatform(parameters.originalFile as KtFile) == JvmPlatform) {
|
if (TargetPlatformDetector.getPlatform(parameters.originalFile as KtFile) == JvmPlatform) {
|
||||||
JavaPsiFacade.getInstance(project).findPackage("")?.getSubPackages(searchScope)?.forEach { psiPackage ->
|
JavaPsiFacade.getInstance(project).findPackage("")?.getSubPackages(searchScope)?.forEach { psiPackage ->
|
||||||
@@ -288,11 +291,12 @@ class BasicCompletionSession(
|
|||||||
withContextVariablesProvider(contextVariablesProvider) { lookupElementFactory ->
|
withContextVariablesProvider(contextVariablesProvider) { lookupElementFactory ->
|
||||||
if (receiverTypes != null) {
|
if (receiverTypes != null) {
|
||||||
ExtensionFunctionTypeValueCompletion(receiverTypes, callTypeAndReceiver.callType, lookupElementFactory)
|
ExtensionFunctionTypeValueCompletion(receiverTypes, callTypeAndReceiver.callType, lookupElementFactory)
|
||||||
.processVariables(contextVariablesProvider)
|
.processVariables(contextVariablesProvider)
|
||||||
.forEach {
|
.forEach {
|
||||||
val lookupElements = it.factory.createStandardLookupElementsForDescriptor(it.invokeDescriptor, useReceiverTypes = true)
|
val lookupElements =
|
||||||
collector.addElements(lookupElements)
|
it.factory.createStandardLookupElementsForDescriptor(it.invokeDescriptor, useReceiverTypes = true)
|
||||||
}
|
collector.addElements(lookupElements)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextVariableTypesForSmartCompletion.any { contextVariablesProvider.functionTypeVariables(it).isNotEmpty() }) {
|
if (contextVariableTypesForSmartCompletion.any { contextVariablesProvider.functionTypeVariables(it).isNotEmpty() }) {
|
||||||
@@ -306,11 +310,12 @@ class BasicCompletionSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val staticMembersCompletion = StaticMembersCompletion(
|
val staticMembersCompletion = StaticMembersCompletion(
|
||||||
prefixMatcher,
|
prefixMatcher,
|
||||||
resolutionFacade,
|
resolutionFacade,
|
||||||
lookupElementFactory,
|
lookupElementFactory,
|
||||||
referenceVariantsCollector!!.allCollected.imported,
|
referenceVariantsCollector!!.allCollected.imported,
|
||||||
isJvmModule)
|
isJvmModule
|
||||||
|
)
|
||||||
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
if (callTypeAndReceiver is CallTypeAndReceiver.DEFAULT) {
|
||||||
staticMembersCompletion.completeFromImports(file, collector)
|
staticMembersCompletion.completeFromImports(file, collector)
|
||||||
}
|
}
|
||||||
@@ -324,7 +329,12 @@ class BasicCompletionSession(
|
|||||||
val variants = variantsAndFactory.first
|
val variants = variantsAndFactory.first
|
||||||
@Suppress("NAME_SHADOWING") val lookupElementFactory = variantsAndFactory.second
|
@Suppress("NAME_SHADOWING") val lookupElementFactory = variantsAndFactory.second
|
||||||
collector.addDescriptorElements(variants.imported, lookupElementFactory, withReceiverCast = true)
|
collector.addDescriptorElements(variants.imported, lookupElementFactory, withReceiverCast = true)
|
||||||
collector.addDescriptorElements(variants.notImportedExtensions, lookupElementFactory, withReceiverCast = true, notImported = true)
|
collector.addDescriptorElements(
|
||||||
|
variants.notImportedExtensions,
|
||||||
|
lookupElementFactory,
|
||||||
|
withReceiverCast = true,
|
||||||
|
notImported = true
|
||||||
|
)
|
||||||
flushToResultSet()
|
flushToResultSet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,8 +380,7 @@ class BasicCompletionSession(
|
|||||||
prefixMatcher
|
prefixMatcher
|
||||||
addClassesFromIndex(classKindFilter, includeTypeAliases, prefixMatcher)
|
addClassesFromIndex(classKindFilter, includeTypeAliases, prefixMatcher)
|
||||||
}
|
}
|
||||||
}
|
} else if (callTypeAndReceiver is CallTypeAndReceiver.DOT) {
|
||||||
else if (callTypeAndReceiver is CallTypeAndReceiver.DOT) {
|
|
||||||
val qualifier = bindingContext[BindingContext.QUALIFIER, callTypeAndReceiver.receiver]
|
val qualifier = bindingContext[BindingContext.QUALIFIER, callTypeAndReceiver.receiver]
|
||||||
if (qualifier != null) return
|
if (qualifier != null) return
|
||||||
val receiver = callTypeAndReceiver.receiver as? KtSimpleNameExpression ?: return
|
val receiver = callTypeAndReceiver.receiver as? KtSimpleNameExpression ?: return
|
||||||
@@ -388,98 +397,106 @@ class BasicCompletionSession(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AllClassesCompletion(parameters.withPosition(receiver, receiver.startOffset), helper, fullTextPrefixMatcher, resolutionFacade,
|
AllClassesCompletion(
|
||||||
{ true }, true, configuration.javaClassesNotToBeUsed
|
parameters.withPosition(receiver, receiver.startOffset), helper, fullTextPrefixMatcher, resolutionFacade,
|
||||||
|
{ true }, true, configuration.javaClassesNotToBeUsed
|
||||||
).collect({ descriptors += it }, { descriptors.addIfNotNull(it.resolveToDescriptor(resolutionFacade)) })
|
).collect({ descriptors += it }, { descriptors.addIfNotNull(it.resolveToDescriptor(resolutionFacade)) })
|
||||||
|
|
||||||
val foundDescriptors = mutableSetOf<DeclarationDescriptor>()
|
val foundDescriptors = mutableSetOf<DeclarationDescriptor>()
|
||||||
descriptors.asSequence()
|
descriptors.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
it.kind == ClassKind.OBJECT ||
|
it.kind == ClassKind.OBJECT ||
|
||||||
it.kind == ClassKind.ENUM_CLASS ||
|
it.kind == ClassKind.ENUM_CLASS ||
|
||||||
it.kind == ClassKind.ENUM_ENTRY ||
|
it.kind == ClassKind.ENUM_ENTRY ||
|
||||||
it.hasCompanionObject ||
|
it.hasCompanionObject ||
|
||||||
it is JavaClassDescriptor
|
it is JavaClassDescriptor
|
||||||
}
|
}
|
||||||
.forEach { classifier ->
|
.forEach { classifier ->
|
||||||
val scope = nameExpression?.getResolutionScope(bindingContext) ?: return
|
val scope = nameExpression?.getResolutionScope(bindingContext) ?: return
|
||||||
|
|
||||||
val desc = classifier.getImportableDescriptor()
|
val desc = classifier.getImportableDescriptor()
|
||||||
val newScope = scope.addImportingScope(ExplicitImportsScope(listOf(desc)))
|
val newScope = scope.addImportingScope(ExplicitImportsScope(listOf(desc)))
|
||||||
|
|
||||||
val newContext = (nameExpression.parent as KtExpression).analyzeInContext(newScope)
|
val newContext = (nameExpression.parent as KtExpression).analyzeInContext(newScope)
|
||||||
|
|
||||||
val rvHelper = ReferenceVariantsHelper(newContext,
|
val rvHelper = ReferenceVariantsHelper(
|
||||||
resolutionFacade,
|
newContext,
|
||||||
moduleDescriptor,
|
resolutionFacade,
|
||||||
isVisibleFilter,
|
moduleDescriptor,
|
||||||
NotPropertiesService.getNotProperties(position))
|
isVisibleFilter,
|
||||||
val rvCollector = ReferenceVariantsCollector(rvHelper, indicesHelper(true), prefixMatcher,
|
NotPropertiesService.getNotProperties(position)
|
||||||
nameExpression, callTypeAndReceiver, resolutionFacade, newContext,
|
)
|
||||||
importableFqNameClassifier, configuration)
|
val rvCollector = ReferenceVariantsCollector(
|
||||||
|
rvHelper, indicesHelper(true), prefixMatcher,
|
||||||
|
nameExpression, callTypeAndReceiver, resolutionFacade, newContext,
|
||||||
|
importableFqNameClassifier, configuration
|
||||||
|
)
|
||||||
|
|
||||||
val receiverTypes = detectReceiverTypes(newContext, nameExpression, callTypeAndReceiver)
|
val receiverTypes = detectReceiverTypes(newContext, nameExpression, callTypeAndReceiver)
|
||||||
|
|
||||||
val factory = lookupElementFactory.copy(receiverTypes = receiverTypes, standardLookupElementsPostProcessor = {
|
val factory = lookupElementFactory.copy(receiverTypes = receiverTypes, standardLookupElementsPostProcessor = {
|
||||||
|
|
||||||
lookupElement ->
|
lookupElement ->
|
||||||
val lookupDescriptor = (lookupElement.`object` as? DeclarationLookupObject)
|
val lookupDescriptor = (lookupElement.`object` as? DeclarationLookupObject)
|
||||||
?.descriptor as? MemberDescriptor ?: return@copy lookupElement
|
?.descriptor as? MemberDescriptor ?: return@copy lookupElement
|
||||||
|
|
||||||
if (!desc.isAncestorOf(lookupDescriptor, false)) return@copy lookupElement
|
if (!desc.isAncestorOf(lookupDescriptor, false)) return@copy lookupElement
|
||||||
|
|
||||||
if (lookupDescriptor is CallableMemberDescriptor &&
|
if (lookupDescriptor is CallableMemberDescriptor &&
|
||||||
lookupDescriptor.isExtension &&
|
lookupDescriptor.isExtension &&
|
||||||
lookupDescriptor.extensionReceiverParameter?.importableFqName != desc.fqNameSafe) {
|
lookupDescriptor.extensionReceiverParameter?.importableFqName != desc.fqNameSafe
|
||||||
return@copy lookupElement
|
) {
|
||||||
}
|
return@copy lookupElement
|
||||||
|
|
||||||
val fqNameToImport = lookupDescriptor.containingDeclaration.importableFqName ?: return@copy lookupElement
|
|
||||||
|
|
||||||
object : LookupElementDecorator<LookupElement>(lookupElement) {
|
|
||||||
val name = fqNameToImport.shortName()
|
|
||||||
val packageName = fqNameToImport.parent()
|
|
||||||
|
|
||||||
override fun handleInsert(context: InsertionContext) {
|
|
||||||
super.handleInsert(context)
|
|
||||||
context.commitDocument()
|
|
||||||
val file = context.file as? KtFile
|
|
||||||
if (file != null) {
|
|
||||||
val receiverInFile = file.findElementAt(receiver.startOffset)?.getParentOfType<KtSimpleNameExpression>(false) ?: return
|
|
||||||
receiverInFile.mainReference.bindToFqName(fqNameToImport, FORCED_SHORTENING)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun renderElement(presentation: LookupElementPresentation?) {
|
|
||||||
super.renderElement(presentation)
|
|
||||||
presentation?.appendTailText(" for $name in $packageName", true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
rvCollector.collectReferenceVariants(descriptorKindFilter) { (imported, notImportedExtensions) ->
|
|
||||||
|
|
||||||
val unique = imported.asSequence()
|
|
||||||
.filterNot { it.original in foundDescriptors }
|
|
||||||
.onEach { foundDescriptors += it.original }
|
|
||||||
|
|
||||||
val uniqueNotImportedExtensions = notImportedExtensions.asSequence()
|
|
||||||
.filterNot { it.original in foundDescriptors }
|
|
||||||
.onEach { foundDescriptors += it.original }
|
|
||||||
|
|
||||||
collector.addDescriptorElements(
|
|
||||||
unique.toList(), factory,
|
|
||||||
prohibitDuplicates = true
|
|
||||||
)
|
|
||||||
collector.addDescriptorElements(
|
|
||||||
uniqueNotImportedExtensions.toList(), factory,
|
|
||||||
notImported = true, prohibitDuplicates = true
|
|
||||||
)
|
|
||||||
|
|
||||||
flushToResultSet()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fqNameToImport = lookupDescriptor.containingDeclaration.importableFqName ?: return@copy lookupElement
|
||||||
|
|
||||||
|
object : LookupElementDecorator<LookupElement>(lookupElement) {
|
||||||
|
val name = fqNameToImport.shortName()
|
||||||
|
val packageName = fqNameToImport.parent()
|
||||||
|
|
||||||
|
override fun handleInsert(context: InsertionContext) {
|
||||||
|
super.handleInsert(context)
|
||||||
|
context.commitDocument()
|
||||||
|
val file = context.file as? KtFile
|
||||||
|
if (file != null) {
|
||||||
|
val receiverInFile =
|
||||||
|
file.findElementAt(receiver.startOffset)?.getParentOfType<KtSimpleNameExpression>(false)
|
||||||
|
?: return
|
||||||
|
receiverInFile.mainReference.bindToFqName(fqNameToImport, FORCED_SHORTENING)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun renderElement(presentation: LookupElementPresentation?) {
|
||||||
|
super.renderElement(presentation)
|
||||||
|
presentation?.appendTailText(" for $name in $packageName", true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
rvCollector.collectReferenceVariants(descriptorKindFilter) { (imported, notImportedExtensions) ->
|
||||||
|
|
||||||
|
val unique = imported.asSequence()
|
||||||
|
.filterNot { it.original in foundDescriptors }
|
||||||
|
.onEach { foundDescriptors += it.original }
|
||||||
|
|
||||||
|
val uniqueNotImportedExtensions = notImportedExtensions.asSequence()
|
||||||
|
.filterNot { it.original in foundDescriptors }
|
||||||
|
.onEach { foundDescriptors += it.original }
|
||||||
|
|
||||||
|
collector.addDescriptorElements(
|
||||||
|
unique.toList(), factory,
|
||||||
|
prohibitDuplicates = true
|
||||||
|
)
|
||||||
|
collector.addDescriptorElements(
|
||||||
|
uniqueNotImportedExtensions.toList(), factory,
|
||||||
|
notImported = true, prohibitDuplicates = true
|
||||||
|
)
|
||||||
|
|
||||||
|
flushToResultSet()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +525,12 @@ class BasicCompletionSession(
|
|||||||
val keywordsToSkip = HashSet<String>()
|
val keywordsToSkip = HashSet<String>()
|
||||||
|
|
||||||
val keywordValueConsumer = object : KeywordValues.Consumer {
|
val keywordValueConsumer = object : KeywordValues.Consumer {
|
||||||
override fun consume(lookupString: String, expectedInfoMatcher: (ExpectedInfo) -> ExpectedInfoMatch, priority: SmartCompletionItemPriority, factory: () -> LookupElement) {
|
override fun consume(
|
||||||
|
lookupString: String,
|
||||||
|
expectedInfoMatcher: (ExpectedInfo) -> ExpectedInfoMatch,
|
||||||
|
priority: SmartCompletionItemPriority,
|
||||||
|
factory: () -> LookupElement
|
||||||
|
) {
|
||||||
keywordsToSkip.add(lookupString)
|
keywordsToSkip.add(lookupString)
|
||||||
val lookupElement = factory()
|
val lookupElement = factory()
|
||||||
val matched = expectedInfos.any {
|
val matched = expectedInfos.any {
|
||||||
@@ -523,7 +545,14 @@ class BasicCompletionSession(
|
|||||||
collector.addElement(lookupElement)
|
collector.addElement(lookupElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeywordValues.process(keywordValueConsumer, callTypeAndReceiver, bindingContext, resolutionFacade, moduleDescriptor, isJvmModule)
|
KeywordValues.process(
|
||||||
|
keywordValueConsumer,
|
||||||
|
callTypeAndReceiver,
|
||||||
|
bindingContext,
|
||||||
|
resolutionFacade,
|
||||||
|
moduleDescriptor,
|
||||||
|
isJvmModule
|
||||||
|
)
|
||||||
|
|
||||||
val keywordsPrefix = prefix.substringBefore('@') // if there is '@' in the prefix - use shorter prefix to not loose 'this' etc
|
val keywordsPrefix = prefix.substringBefore('@') // if there is '@' in the prefix - use shorter prefix to not loose 'this' etc
|
||||||
val isUseSiteAnnotationTarget = position.prevLeaf()?.node?.elementType == KtTokens.AT
|
val isUseSiteAnnotationTarget = position.prevLeaf()?.node?.elementType == KtTokens.AT
|
||||||
@@ -535,9 +564,14 @@ class BasicCompletionSession(
|
|||||||
// if "this" is parsed correctly in the current context - insert it and all this@xxx items
|
// if "this" is parsed correctly in the current context - insert it and all this@xxx items
|
||||||
"this" -> {
|
"this" -> {
|
||||||
if (expression != null) {
|
if (expression != null) {
|
||||||
collector.addElements(thisExpressionItems(bindingContext, expression, prefix, resolutionFacade).map { it.createLookupElement() })
|
collector.addElements(
|
||||||
}
|
thisExpressionItems(
|
||||||
else {
|
bindingContext,
|
||||||
|
expression,
|
||||||
|
prefix,
|
||||||
|
resolutionFacade
|
||||||
|
).map { it.createLookupElement() })
|
||||||
|
} else {
|
||||||
// for completion in secondary constructor delegation call
|
// for completion in secondary constructor delegation call
|
||||||
collector.addElement(lookupElement)
|
collector.addElement(lookupElement)
|
||||||
}
|
}
|
||||||
@@ -573,7 +607,14 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
if (!isUseSiteAnnotationTarget) {
|
if (!isUseSiteAnnotationTarget) {
|
||||||
collector.addElement(createKeywordConstructLookupElement(project, keyword, "val v:Int get()=caret"))
|
collector.addElement(createKeywordConstructLookupElement(project, keyword, "val v:Int get()=caret"))
|
||||||
collector.addElement(createKeywordConstructLookupElement(project, keyword, "val v:Int get(){caret}", trimSpacesAroundCaret = true))
|
collector.addElement(
|
||||||
|
createKeywordConstructLookupElement(
|
||||||
|
project,
|
||||||
|
keyword,
|
||||||
|
"val v:Int get(){caret}",
|
||||||
|
trimSpacesAroundCaret = true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +623,14 @@ class BasicCompletionSession(
|
|||||||
|
|
||||||
if (!isUseSiteAnnotationTarget) {
|
if (!isUseSiteAnnotationTarget) {
|
||||||
collector.addElement(createKeywordConstructLookupElement(project, keyword, "var v:Int set(value)=caret"))
|
collector.addElement(createKeywordConstructLookupElement(project, keyword, "var v:Int set(value)=caret"))
|
||||||
collector.addElement(createKeywordConstructLookupElement(project, keyword, "var v:Int set(value){caret}", trimSpacesAroundCaret = true))
|
collector.addElement(
|
||||||
|
createKeywordConstructLookupElement(
|
||||||
|
project,
|
||||||
|
keyword,
|
||||||
|
"var v:Int set(value){caret}",
|
||||||
|
trimSpacesAroundCaret = true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +657,8 @@ class BasicCompletionSession(
|
|||||||
if (nameExpression == null || nameExpression != expression) return false
|
if (nameExpression == null || nameExpression != expression) return false
|
||||||
val func = position.getParentOfType<KtNamedFunction>(strict = false) ?: return false
|
val func = position.getParentOfType<KtNamedFunction>(strict = false) ?: return false
|
||||||
val funcNameIdentifier = func.nameIdentifier ?: return false
|
val funcNameIdentifier = func.nameIdentifier ?: return false
|
||||||
val identifierInNameExpression = nameExpression.nextLeaf { it is LeafPsiElement && it.elementType == KtTokens.IDENTIFIER } ?: return false
|
val identifierInNameExpression =
|
||||||
|
nameExpression.nextLeaf { it is LeafPsiElement && it.elementType == KtTokens.IDENTIFIER } ?: return false
|
||||||
if (!func.hasModifier(KtTokens.OPERATOR_KEYWORD) || identifierInNameExpression != funcNameIdentifier) return false
|
if (!func.hasModifier(KtTokens.OPERATOR_KEYWORD) || identifierInNameExpression != funcNameIdentifier) return false
|
||||||
val originalFunc = toFromOriginalFileMapper.toOriginalFile(func) ?: return false
|
val originalFunc = toFromOriginalFileMapper.toOriginalFile(func) ?: return false
|
||||||
return !originalFunc.isTopLevel || (originalFunc.isExtensionDeclaration())
|
return !originalFunc.isTopLevel || (originalFunc.isExtensionDeclaration())
|
||||||
@@ -692,7 +741,7 @@ class BasicCompletionSession(
|
|||||||
val classOrObject = position.parents.firstIsInstanceOrNull<KtClassOrObject>() ?: return
|
val classOrObject = position.parents.firstIsInstanceOrNull<KtClassOrObject>() ?: return
|
||||||
val classDescriptor = resolutionFacade.resolveToDescriptor(classOrObject, BodyResolveMode.PARTIAL) as ClassDescriptor
|
val classDescriptor = resolutionFacade.resolveToDescriptor(classOrObject, BodyResolveMode.PARTIAL) as ClassDescriptor
|
||||||
var superClasses = classDescriptor.defaultType.constructor.supertypesWithAny()
|
var superClasses = classDescriptor.defaultType.constructor.supertypesWithAny()
|
||||||
.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor }
|
.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor }
|
||||||
|
|
||||||
if (callTypeAndReceiver.receiver != null) {
|
if (callTypeAndReceiver.receiver != null) {
|
||||||
val referenceVariantsSet = referenceVariantsCollector!!.collectReferenceVariants(descriptorKindFilter).imported.toSet()
|
val referenceVariantsSet = referenceVariantsCollector!!.collectReferenceVariants(descriptorKindFilter).imported.toSet()
|
||||||
@@ -700,16 +749,15 @@ class BasicCompletionSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
superClasses
|
superClasses
|
||||||
.map { basicLookupElementFactory.createLookupElement(it, qualifyNestedClasses = true, includeClassTypeArguments = false) }
|
.map { basicLookupElementFactory.createLookupElement(it, qualifyNestedClasses = true, includeClassTypeArguments = false) }
|
||||||
.forEach { collector.addElement(it) }
|
.forEach { collector.addElement(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun completeDeclarationNameFromUnresolvedOrOverride(declaration: KtNamedDeclaration) {
|
private fun completeDeclarationNameFromUnresolvedOrOverride(declaration: KtNamedDeclaration) {
|
||||||
if (declaration is KtCallableDeclaration && declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD)) {
|
if (declaration is KtCallableDeclaration && declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD)) {
|
||||||
OverridesCompletion(collector, basicLookupElementFactory).complete(position, declaration)
|
OverridesCompletion(collector, basicLookupElementFactory).complete(position, declaration)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val referenceScope = referenceScope(declaration) ?: return
|
val referenceScope = referenceScope(declaration) ?: return
|
||||||
val originalScope = toFromOriginalFileMapper.toOriginalFile(referenceScope) ?: return
|
val originalScope = toFromOriginalFileMapper.toOriginalFile(referenceScope) ?: return
|
||||||
val afterOffset = if (referenceScope is KtBlockExpression) parameters.offset else null
|
val afterOffset = if (referenceScope is KtBlockExpression) parameters.offset else null
|
||||||
@@ -727,8 +775,7 @@ class BasicCompletionSession(
|
|||||||
val classOrObject = parent.parent as KtClassOrObject
|
val classOrObject = parent.parent as KtClassOrObject
|
||||||
if (classOrObject is KtObjectDeclaration && classOrObject.isCompanion()) {
|
if (classOrObject is KtObjectDeclaration && classOrObject.isCompanion()) {
|
||||||
classOrObject.containingClassOrObject
|
classOrObject.containingClassOrObject
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
classOrObject
|
classOrObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -748,8 +795,9 @@ class BasicCompletionSession(
|
|||||||
val javaClassCollector = { javaClass: PsiClass ->
|
val javaClassCollector = { javaClass: PsiClass ->
|
||||||
collector.addElement(basicLookupElementFactory.createLookupElementForJavaClass(javaClass), notImported = true)
|
collector.addElement(basicLookupElementFactory.createLookupElementForJavaClass(javaClass), notImported = true)
|
||||||
}
|
}
|
||||||
AllClassesCompletion(parameters, indicesHelper(true), prefixMatcher, resolutionFacade,
|
AllClassesCompletion(
|
||||||
kindFilter, includeTypeAliases, configuration.javaClassesNotToBeUsed
|
parameters, indicesHelper(true), prefixMatcher, resolutionFacade,
|
||||||
|
kindFilter, includeTypeAliases, configuration.javaClassesNotToBeUsed
|
||||||
).collect(classifierDescriptorCollector, javaClassCollector)
|
).collect(classifierDescriptorCollector, javaClassCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,10 +841,14 @@ class BasicCompletionSession(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val USUALLY_START_UPPER_CASE = DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.FUNCTIONS_MASK,
|
private val USUALLY_START_UPPER_CASE = DescriptorKindFilter(
|
||||||
listOf(NonSamConstructorFunctionExclude, DescriptorKindExclude.Extensions /* needed for faster getReferenceVariants */))
|
DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.FUNCTIONS_MASK,
|
||||||
private val USUALLY_START_LOWER_CASE = DescriptorKindFilter(DescriptorKindFilter.CALLABLES_MASK or DescriptorKindFilter.PACKAGES_MASK,
|
listOf(NonSamConstructorFunctionExclude, DescriptorKindExclude.Extensions /* needed for faster getReferenceVariants */)
|
||||||
listOf(SamConstructorDescriptorKindExclude))
|
)
|
||||||
|
private val USUALLY_START_LOWER_CASE = DescriptorKindFilter(
|
||||||
|
DescriptorKindFilter.CALLABLES_MASK or DescriptorKindFilter.PACKAGES_MASK,
|
||||||
|
listOf(SamConstructorDescriptorKindExclude)
|
||||||
|
)
|
||||||
|
|
||||||
private object NonSamConstructorFunctionExclude : DescriptorKindExclude() {
|
private object NonSamConstructorFunctionExclude : DescriptorKindExclude() {
|
||||||
override fun excludes(descriptor: DeclarationDescriptor) = descriptor is FunctionDescriptor && descriptor !is SamConstructorDescriptor
|
override fun excludes(descriptor: DeclarationDescriptor) = descriptor is FunctionDescriptor && descriptor !is SamConstructorDescriptor
|
||||||
|
|||||||
Reference in New Issue
Block a user