diff --git a/src/main/kotlin/icu/windea/pls/core/StdlibExtensions.kt b/src/main/kotlin/icu/windea/pls/core/StdlibExtensions.kt index b81ea064c..47966c4f9 100644 --- a/src/main/kotlin/icu/windea/pls/core/StdlibExtensions.kt +++ b/src/main/kotlin/icu/windea/pls/core/StdlibExtensions.kt @@ -355,33 +355,6 @@ fun String.toCapitalizedWords(): String { private val keywordDelimiters = charArrayOf('.', '_') -/** - * 判断指定的关键词是否匹配当前字符串。 - */ -@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -fun String.matchesKeyword(keyword: String): Boolean { - if(keyword.isEmpty()) return true - - //IDEA底层如何匹配关键词: - //com.intellij.codeInsight.completion.PrefixMatcher.prefixMatches(java.lang.String) - - //这里如何匹配关键词:按顺序包含所有字符,忽略大小写 - var index = -1 - for(i in 0 until keyword.length) { - val c = keyword[i] - val index1 = (this as java.lang.String).indexOf(c.lowercaseChar().code, index + 1) - val index2 = (this as java.lang.String).indexOf(c.uppercaseChar().code, index + 1) - when { - index1 == -1 && index2 == -1 -> return false - index1 == -1 -> index = index2 - index2 == -1 -> index = index1 - else -> index = min(index, index2) - } - } - - return true -} - fun CharSequence.indicesOf(char: Char, startIndex: Int = 0, ignoreCase: Boolean = false): List { var indices: MutableList? = null var lastIndex = indexOf(char, startIndex, ignoreCase) diff --git a/src/main/kotlin/icu/windea/pls/core/codeInsight/completion/LimitedCompletionProcessor.kt b/src/main/kotlin/icu/windea/pls/core/codeInsight/completion/LimitedCompletionProcessor.kt index 7dc89ce0b..5f85f8513 100644 --- a/src/main/kotlin/icu/windea/pls/core/codeInsight/completion/LimitedCompletionProcessor.kt +++ b/src/main/kotlin/icu/windea/pls/core/codeInsight/completion/LimitedCompletionProcessor.kt @@ -4,13 +4,15 @@ import com.intellij.openapi.util.registry.* import com.intellij.util.* /** + * 进行代码提示时,确保加入的提示项不超过`ide.completion.variant.limit`指定的上限。 + * * 用于优化代码提示的性能。 */ class LimitedCompletionProcessor( private val processor: Processor ): Processor { private val limit: Int = Registry.intValue("ide.completion.variant.limit") - private var count = 0 + @Volatile private var count = 0 override fun process(e: T): Boolean { if(!processor.process(e)) return false diff --git a/src/main/kotlin/icu/windea/pls/core/search/ParadoxLocalisationSearch.kt b/src/main/kotlin/icu/windea/pls/core/search/ParadoxLocalisationSearch.kt index 2fdd57309..39b7dca96 100644 --- a/src/main/kotlin/icu/windea/pls/core/search/ParadoxLocalisationSearch.kt +++ b/src/main/kotlin/icu/windea/pls/core/search/ParadoxLocalisationSearch.kt @@ -1,5 +1,6 @@ package icu.windea.pls.core.search +import com.intellij.codeInsight.completion.PrefixMatcher import com.intellij.openapi.extensions.* import com.intellij.psi.search.searches.* import com.intellij.util.* @@ -46,13 +47,11 @@ class ParadoxLocalisationSearch : ExtensibleQueryFactory, processor: Processor ): Boolean { @@ -61,7 +60,7 @@ class ParadoxLocalisationSearch : ExtensibleQueryFactory key.matchesKeyword(keyword) }, + keyPredicate = { key -> prefixMatcher.prefixMatches(key) }, predicate = { element -> selector.select(element) }, getDefaultValue = { selector.defaultValue() }, resetDefaultValue = { selector.resetDefaultValue() }, diff --git a/src/main/kotlin/icu/windea/pls/core/search/ParadoxSyncedLocalisationSearch.kt b/src/main/kotlin/icu/windea/pls/core/search/ParadoxSyncedLocalisationSearch.kt index bcc85d616..961d05a42 100644 --- a/src/main/kotlin/icu/windea/pls/core/search/ParadoxSyncedLocalisationSearch.kt +++ b/src/main/kotlin/icu/windea/pls/core/search/ParadoxSyncedLocalisationSearch.kt @@ -1,5 +1,6 @@ package icu.windea.pls.core.search +import com.intellij.codeInsight.completion.* import com.intellij.openapi.extensions.* import com.intellij.psi.search.searches.* import com.intellij.util.* @@ -46,13 +47,11 @@ class ParadoxSyncedLocalisationSearch : ExtensibleQueryFactory, processor: Processor ): Boolean { @@ -61,8 +60,8 @@ class ParadoxSyncedLocalisationSearch : ExtensibleQueryFactory prefixMatcher.prefixMatches(key) }, predicate = { element -> selector.select(element) }, - keyPredicate = { key -> key.matchesKeyword(keyword) }, getDefaultValue = { selector.defaultValue() }, resetDefaultValue = { selector.resetDefaultValue() }, processor = { processor.process(it) } diff --git a/src/main/kotlin/icu/windea/pls/lang/expression/impl/ParadoxScriptExpressionSupports.kt b/src/main/kotlin/icu/windea/pls/lang/expression/impl/ParadoxScriptExpressionSupports.kt index e0c9cfee6..3cb3f84fb 100644 --- a/src/main/kotlin/icu/windea/pls/lang/expression/impl/ParadoxScriptExpressionSupports.kt +++ b/src/main/kotlin/icu/windea/pls/lang/expression/impl/ParadoxScriptExpressionSupports.kt @@ -66,7 +66,7 @@ class ParadoxScriptLocalisationExpressionSupport : ParadoxScriptExpressionSuppor val selector = localisationSelector(project, contextElement).contextSensitive() .preferLocale(ParadoxLocaleHandler.getPreferredLocale()) //.distinctByName() //这里selector不需要指定去重 - ParadoxLocalisationSearch.processVariants(keyword, selector, LimitedCompletionProcessor { localisation -> + ParadoxLocalisationSearch.processVariants(result.prefixMatcher, selector, LimitedCompletionProcessor { localisation -> val name = localisation.name //=localisation.paradoxLocalisationInfo?.name val typeFile = localisation.containingFile val builder = ParadoxScriptExpressionLookupElementBuilder.create(localisation, name) @@ -121,7 +121,7 @@ class ParadoxScriptSyncedLocalisationExpressionSupport : ParadoxScriptExpression val tailText = ParadoxConfigHandler.getScriptExpressionTailText(config) //这里selector不需要指定去重 val selector = localisationSelector(project, contextElement).contextSensitive().preferLocale(ParadoxLocaleHandler.getPreferredLocale()) - ParadoxSyncedLocalisationSearch.processVariants(keyword, selector) { syncedLocalisation -> + ParadoxSyncedLocalisationSearch.processVariants(result.prefixMatcher, selector) { syncedLocalisation -> val name = syncedLocalisation.name //=localisation.paradoxLocalisationInfo?.name val typeFile = syncedLocalisation.containingFile val builder = ParadoxScriptExpressionLookupElementBuilder.create(syncedLocalisation, name) @@ -180,7 +180,7 @@ class ParadoxScriptInlineLocalisationExpressionSupport : ParadoxScriptExpression val selector = localisationSelector(project, contextElement).contextSensitive() .preferLocale(ParadoxLocaleHandler.getPreferredLocale()) //.distinctByName() //这里selector不需要指定去重 - ParadoxLocalisationSearch.processVariants(keyword, selector, LimitedCompletionProcessor { localisation -> + ParadoxLocalisationSearch.processVariants(result.prefixMatcher, selector, LimitedCompletionProcessor { localisation -> val name = localisation.name //=localisation.paradoxLocalisationInfo?.name val typeFile = localisation.containingFile val builder = ParadoxScriptExpressionLookupElementBuilder.create(localisation, name) diff --git a/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationNameCompletionProvider.kt b/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationNameCompletionProvider.kt index ef22fba03..03d98b899 100644 --- a/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationNameCompletionProvider.kt +++ b/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationNameCompletionProvider.kt @@ -52,8 +52,8 @@ class ParadoxLocalisationNameCompletionProvider : CompletionProvider ParadoxLocalisationSearch.processVariants(keyword, selector, processor) - ParadoxLocalisationCategory.SyncedLocalisation -> ParadoxSyncedLocalisationSearch.processVariants(keyword, selector, processor) + ParadoxLocalisationCategory.Localisation -> ParadoxLocalisationSearch.processVariants(result.prefixMatcher, selector, processor) + ParadoxLocalisationCategory.SyncedLocalisation -> ParadoxSyncedLocalisationSearch.processVariants(result.prefixMatcher, selector, processor) } } } diff --git a/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationPropertyReferenceCompletionProvider.kt b/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationPropertyReferenceCompletionProvider.kt index 0badfb02f..e124f706b 100644 --- a/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationPropertyReferenceCompletionProvider.kt +++ b/src/main/kotlin/icu/windea/pls/localisation/codeInsight/completion/ParadoxLocalisationPropertyReferenceCompletionProvider.kt @@ -52,8 +52,8 @@ class ParadoxLocalisationPropertyReferenceCompletionProvider : CompletionProvide true } when(category) { - ParadoxLocalisationCategory.Localisation -> ParadoxLocalisationSearch.processVariants(keyword, selector, processor) - ParadoxLocalisationCategory.SyncedLocalisation -> ParadoxSyncedLocalisationSearch.processVariants(keyword, selector, processor) + ParadoxLocalisationCategory.Localisation -> ParadoxLocalisationSearch.processVariants(result.prefixMatcher, selector, processor) + ParadoxLocalisationCategory.SyncedLocalisation -> ParadoxSyncedLocalisationSearch.processVariants(result.prefixMatcher, selector, processor) } } }