mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-207762 make LimitedToleranceMatcher independent from lookupElement
GitOrigin-RevId: 0ab2b723bfd4da2e4d0d51d5c66c36797b25ae2a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8dc891ef00
commit
6070d3d255
+17
-19
@@ -175,11 +175,9 @@ internal class CommandCompletionProvider(val contributor: CommandCompletionContr
|
||||
|
||||
val prefix = commandCompletionType.pattern
|
||||
val sorter = createSorter(parameters)
|
||||
val matcher = LimitedToleranceMatcher(prefix)
|
||||
val withPrefixMatcher = resultSet.withPrefixMatcher(matcher)
|
||||
.withRelevanceSorter(sorter)
|
||||
val withRelevanceSorter = resultSet.withRelevanceSorter(sorter)
|
||||
|
||||
withPrefixMatcher.restartCompletionOnPrefixChange(
|
||||
resultSet.restartCompletionOnPrefixChange(
|
||||
StandardPatterns.string().with(object : PatternCondition<String>("add filter for command completion") {
|
||||
override fun accepts(t: String, context: ProcessingContext?): Boolean {
|
||||
return (!isReadOnly && commandCompletionType.suffix + t ==
|
||||
@@ -199,6 +197,7 @@ internal class CommandCompletionProvider(val contributor: CommandCompletionContr
|
||||
isReadOnly = isReadOnly,
|
||||
isInjected = isInjected,
|
||||
commandCompletionType = commandCompletionType) { commands ->
|
||||
val baseMatcher = CamelHumpMatcher(prefix, false, true)
|
||||
commands.forEach { command ->
|
||||
ProgressManager.checkCanceled()
|
||||
CommandCompletionCollector.shown(command::class.java, originalFile.language, commandCompletionType::class.java)
|
||||
@@ -213,9 +212,11 @@ internal class CommandCompletionProvider(val contributor: CommandCompletionContr
|
||||
}
|
||||
else {
|
||||
for (element in lookupElements) {
|
||||
if (!matcher.basePrefixMatches(element)) continue
|
||||
if (!baseMatcher.prefixMatches(element)) continue
|
||||
val commandCompletionElement = element.`as`(CommandCompletionLookupElement::class.java)!!
|
||||
val matcher = LimitedToleranceMatcher(prefix, commandCompletionElement.currentTags, commandCompletionElement.otherTags)
|
||||
element.putUserData(SHOULD_NOT_CHECK_WHEN_WRAP, true)
|
||||
withPrefixMatcher.addElement(element)
|
||||
withRelevanceSorter.withPrefixMatcher(matcher).addElement(element)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,23 +646,20 @@ internal fun findCommandCompletionType(
|
||||
return null
|
||||
}
|
||||
|
||||
private class LimitedToleranceMatcher(prefix: String) : CamelHumpMatcher(prefix, false, true) {
|
||||
|
||||
fun basePrefixMatches(element: LookupElement): Boolean {
|
||||
return super.prefixMatches(element)
|
||||
}
|
||||
private class LimitedToleranceMatcher(
|
||||
prefix: String,
|
||||
private val currentTags: List<String>,
|
||||
private val otherTags: List<String>
|
||||
) : CamelHumpMatcher(prefix, false, true) {
|
||||
|
||||
override fun prefixMatches(element: LookupElement): Boolean {
|
||||
if (!super.prefixMatches(element)) return false
|
||||
val commandCompletionElement = element.`as`(CommandCompletionLookupElement::class.java) ?: return false
|
||||
val currentTags = commandCompletionElement.currentTags
|
||||
val allLookupStrings = currentTags.ifEmpty { element.allLookupStrings }
|
||||
val allLookupStrings = this.currentTags.ifEmpty { element.allLookupStrings }
|
||||
if (!matched(allLookupStrings)) return false
|
||||
val otherTags = commandCompletionElement.otherTags
|
||||
if (otherTags.isEmpty()) return true
|
||||
val indexOfFirst = otherTags.indexOfFirst { allLookupStrings.contains(it) }
|
||||
if (this.otherTags.isEmpty()) return true
|
||||
val indexOfFirst = this.otherTags.indexOfFirst { allLookupStrings.contains(it) }
|
||||
if (indexOfFirst <= 0) return true
|
||||
if (matched(otherTags.subList(0, indexOfFirst))) return false
|
||||
if (matched(this.otherTags.subList(0, indexOfFirst))) return false
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -693,7 +691,7 @@ private class LimitedToleranceMatcher(prefix: String) : CamelHumpMatcher(prefix,
|
||||
if (prefix == this.prefix) {
|
||||
return this
|
||||
}
|
||||
return LimitedToleranceMatcher(prefix)
|
||||
return LimitedToleranceMatcher(prefix, currentTags, otherTags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user