From 84386237a69a0815a138f5b76024eadedd870e19 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Mon, 15 Mar 2021 10:37:50 +0300 Subject: [PATCH] FIR IDE: Refactor classifiers insertion handlers --- .../KotlinFirLookupElementFactory.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/completion/KotlinFirLookupElementFactory.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/completion/KotlinFirLookupElementFactory.kt index af18e9f41a8..65154dc73be 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/completion/KotlinFirLookupElementFactory.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/completion/KotlinFirLookupElementFactory.kt @@ -92,14 +92,7 @@ private data class VariableLookupObject(override val shortName: Name, val callab private class ClassLookupElementFactory { fun createLookup(symbol: KtClassLikeSymbol): LookupElementBuilder { return LookupElementBuilder.create(ClassifierLookupObject(symbol.name, symbol.classIdIfNonLocal), symbol.name.asString()) - .withInsertHandler(createInsertHandler(symbol)) - } - - private fun createInsertHandler(symbol: KtClassLikeSymbol): InsertHandler { - val classFqName = symbol.classIdIfNonLocal?.asSingleFqName() - ?: return QuotedNamesAwareInsertionHandler() - - return ClassifierInsertionHandler(classFqName) + .withInsertHandler(ClassifierInsertionHandler) } } @@ -206,14 +199,19 @@ private class FunctionLookupElementFactory { /** * The simplest implementation of the insertion handler for a classifiers. */ -private class ClassifierInsertionHandler(private val fqName: FqName) : InsertHandler { +private object ClassifierInsertionHandler : InsertHandler { override fun handleInsert(context: InsertionContext, item: LookupElement) { val targetFile = context.file as? KtFile ?: return + val lookupObject = item.`object` as ClassifierLookupObject - context.document.replaceString(context.startOffset, context.tailOffset, fqName.render()) - context.commitDocument() + if (lookupObject.classId != null) { + val fqName = lookupObject.classId.asSingleFqName() - shortenReferences(targetFile, TextRange(context.startOffset, context.tailOffset)) + context.document.replaceString(context.startOffset, context.tailOffset, fqName.render()) + context.commitDocument() + + shortenReferences(targetFile, TextRange(context.startOffset, context.tailOffset)) + } } }