mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle] IDEA-381944 Add text-matching dependency to Gradle completion logic
GitOrigin-RevId: 753b91f940680b63529f282823ff857702c65dcf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
20415d2468
commit
a12d0d5d54
@@ -80,6 +80,7 @@ jvm_library(
|
||||
"//platform/forms_rt:java-guiForms-rt",
|
||||
"//libraries/jspecify",
|
||||
"//plugins/repository-search",
|
||||
"//platform/util/text-matching",
|
||||
],
|
||||
exports = [
|
||||
"//platform/external-system-api:externalSystem",
|
||||
|
||||
@@ -67,5 +67,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.guiForms.rt" />
|
||||
<orderEntry type="module" module-name="intellij.libraries.jspecify" />
|
||||
<orderEntry type="module" module-name="intellij.repository.search" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.text.matching" />
|
||||
</component>
|
||||
</module>
|
||||
+7
-7
@@ -3,7 +3,7 @@ package org.jetbrains.plugins.gradle.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.util.text.matching.MatchedFragment
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
private val log = logger<GradleDependencyCompletionMatcher>()
|
||||
@@ -18,7 +18,7 @@ class GradleDependencyCompletionMatcher(prefix: String) : PrefixMatcher(prefix)
|
||||
return GradleDependencyCompletionMatcher(prefix)
|
||||
}
|
||||
|
||||
override fun getMatchingFragments(prefix: String, name: String): List<TextRange>? {
|
||||
override fun getMatchingFragments(prefix: String, name: String): List<MatchedFragment> {
|
||||
try {
|
||||
return tryGetMatchingFragments(prefix, name)
|
||||
}
|
||||
@@ -28,17 +28,17 @@ class GradleDependencyCompletionMatcher(prefix: String) : PrefixMatcher(prefix)
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryGetMatchingFragments(prefix: String, name: String): List<TextRange>? {
|
||||
private fun tryGetMatchingFragments(prefix: String, name: String): List<MatchedFragment> {
|
||||
// handle top level completion case:
|
||||
// implementation("org.example:lib-implementation:1.0") - "implementation" in the artifact name should be matched
|
||||
val start = name.indexOf("(").coerceAtLeast(0)
|
||||
val prefixParts = prefix.split(":")
|
||||
val nameParts = name.substring(start).split(":")
|
||||
val result = mutableListOf<TextRange>()
|
||||
val result = mutableListOf<MatchedFragment>()
|
||||
var offset = start
|
||||
var j = 0
|
||||
for (i in 0 until prefixParts.size) {
|
||||
var matchingFragment: TextRange? = null
|
||||
var matchingFragment: MatchedFragment? = null
|
||||
while (j < nameParts.size && matchingFragment == null) {
|
||||
matchingFragment = getMatchingFragment(offset, prefixParts[i], nameParts[j])
|
||||
offset += nameParts[j].length + 1
|
||||
@@ -53,11 +53,11 @@ class GradleDependencyCompletionMatcher(prefix: String) : PrefixMatcher(prefix)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getMatchingFragment(offset: Int, prefixPart: String, name: String): TextRange? {
|
||||
private fun getMatchingFragment(offset: Int, prefixPart: String, name: String): MatchedFragment? {
|
||||
val from = name.indexOf(prefixPart)
|
||||
if (from == -1) {
|
||||
return null
|
||||
}
|
||||
return TextRange(from + offset, from + offset + prefixPart.length)
|
||||
return MatchedFragment(from + offset, from + offset + prefixPart.length)
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,8 @@ jvm_library(
|
||||
"//plugins/repository-search",
|
||||
"//plugins/repository-search:repository-search_test_lib",
|
||||
"//plugins/kotlin/gradle/scripting/kotlin.gradle.scripting.shared:kotlin-gradle-scripting-shared",
|
||||
"//platform/util/text-matching",
|
||||
"//platform/util/text-matching:text-matching_test_lib",
|
||||
],
|
||||
exports = ["@lib//:kotlin-gradle-plugin-idea"],
|
||||
runtime_deps = [":tests.shared"]
|
||||
|
||||
+1
@@ -82,5 +82,6 @@
|
||||
<orderEntry type="module" module-name="intellij.junit" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.repository.search" scope="TEST" />
|
||||
<orderEntry type="module" module-name="kotlin.gradle.scripting.shared" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.text.matching" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
+2
-4
@@ -1,7 +1,7 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.codeInsight.gradle.completion
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.util.text.matching.MatchedFragment
|
||||
import org.jetbrains.plugins.gradle.completion.GradleDependencyCompletionMatcher
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
@@ -63,7 +63,7 @@ class GradleDependencyCompletionMatcherTest {
|
||||
}
|
||||
|
||||
// Apply ranges as braces to the clean name to build an annotated string
|
||||
fun annotate(name: String, ranges: List<TextRange>): String {
|
||||
fun annotate(name: String, ranges: List<MatchedFragment>): String {
|
||||
if (ranges.isEmpty()) return name
|
||||
val sorted = ranges.sortedBy { it.startOffset }
|
||||
val starts = sorted.groupBy { it.startOffset }
|
||||
@@ -85,8 +85,6 @@ class GradleDependencyCompletionMatcherTest {
|
||||
val matcher = GradleDependencyCompletionMatcher(prefix)
|
||||
val fragments = matcher.getMatchingFragments(prefix, name)
|
||||
|
||||
require(fragments != null) { "Expected non-null fragments" }
|
||||
|
||||
val actualAnnotated = annotate(name, fragments)
|
||||
val message = "getMatchingFragments: prefix='$prefix' expected $annotatedName but was $actualAnnotated"
|
||||
assertEquals(annotatedName, actualAnnotated, message)
|
||||
|
||||
Reference in New Issue
Block a user