From 5799ecbd28a79c0e5d03d67f22cf4eea771a963b Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 27 Aug 2014 20:34:36 +0400 Subject: [PATCH] Completion: minor code corrections after review --- .../org/jetbrains/jet/plugin/caches/KotlinIndicesHelper.kt | 2 ++ .../org/jetbrains/jet/plugin/completion/CompletionSession.kt | 4 ++-- .../completion/handlers/BaseDeclarationInsertHandler.kt | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/caches/KotlinIndicesHelper.kt b/idea/src/org/jetbrains/jet/plugin/caches/KotlinIndicesHelper.kt index d9d4d689cc2..8653f68a7da 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/KotlinIndicesHelper.kt +++ b/idea/src/org/jetbrains/jet/plugin/caches/KotlinIndicesHelper.kt @@ -98,6 +98,7 @@ public class KotlinIndicesHelper(private val project: Project) { private fun MutableCollection.addSourceTopLevelFunctions(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope) { val identifier = Name.identifier(name) val affectedPackages = JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().get(name, project, scope) + .stream() .map { it.getContainingFile() } .filterIsInstance(javaClass()) .map { it.getPackageFqName() } @@ -113,6 +114,7 @@ public class KotlinIndicesHelper(private val project: Project) { private fun MutableCollection.addSourceTopLevelProperties(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope) { val identifier = Name.identifier(name) val affectedPackages = JetTopLevelNonExtensionPropertyShortNameIndex.getInstance().get(name, project, scope) + .stream() .map { it.getContainingFile() } .filterIsInstance(javaClass()) .map { it.getPackageFqName() } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt b/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt index 267bad0022d..7e242bf0c2f 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt @@ -165,8 +165,8 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, private fun addKotlinTopLevelDeclarations() { val filter = { (name: String) -> prefixMatcher.prefixMatches(name) } - collector.addDescriptorElements(indicesHelper.getTopLevelCallables(filter, jetReference!!.expression, resolveSession, searchScope) + - indicesHelper.getTopLevelObjects(filter, resolveSession, searchScope)) + collector.addDescriptorElements(indicesHelper.getTopLevelCallables(filter, jetReference!!.expression, resolveSession, searchScope)) + collector.addDescriptorElements(indicesHelper.getTopLevelObjects(filter, resolveSession, searchScope)) } private fun addKotlinExtensions() { diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/BaseDeclarationInsertHandler.kt b/idea/src/org/jetbrains/jet/plugin/completion/handlers/BaseDeclarationInsertHandler.kt index abfbea65c56..26c4ac4a091 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/BaseDeclarationInsertHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/BaseDeclarationInsertHandler.kt @@ -30,7 +30,9 @@ open class BaseDeclarationInsertHandler : InsertHandler { val name = descriptor.getName() val nameInCode = DescriptorRenderer.SOURCE_CODE.renderName(name) val document = context.getDocument() - if (nameInCode != name.asString() && document.getText(TextRange(context.getStartOffset(), context.getTailOffset())) == name.asString()) { + val needEscaping = nameInCode != name.asString() + // we check that text inserted matches the name because something else can be inserted by custom insert handler + if (needEscaping && document.getText(TextRange(context.getStartOffset(), context.getTailOffset())) == name.asString()) { document.replaceString(context.getStartOffset(), context.getTailOffset(), nameInCode) } }