mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle][toml] IDEA-370681 fix finding TOML version catalog usages in build scripts of subprojects in included builds
Replace deprecated API that works only for subprojects of a root build. * org.jetbrains.plugins.gradle.dsl.versionCatalogs.GradleVersionCatalogsFindUsagesTest.testNestedProjectOfIncludedBuild GitOrigin-RevId: 57f7cb6cabd9aa8ac7524b79e58a1f160a24380f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e2ce16b40d
commit
f7f585c8ae
@@ -66,7 +66,7 @@ fun getAccessorsForAllCatalogs(context: PsiElement) : Map<String, PsiClass> {
|
||||
fun isInVersionCatalog(element: PsiElement): Boolean {
|
||||
val module = ModuleUtilCore.findModuleForPsiElement(element) ?: return false
|
||||
val versionCatalogFiles = getVersionCatalogFiles(module).values
|
||||
val thisFile = element.containingFile?.virtualFile
|
||||
val thisFile = element.containingFile?.virtualFile ?:return false
|
||||
return versionCatalogFiles.any { it == thisFile }
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,16 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.psi.search.UseScopeEnlarger
|
||||
import org.jetbrains.plugins.gradle.config.GradleBuildscriptSearchScope
|
||||
import org.jetbrains.plugins.gradle.service.resolve.getVersionCatalogFiles
|
||||
import org.jetbrains.plugins.gradle.service.resolve.isInVersionCatalog
|
||||
import org.toml.lang.psi.TomlElement
|
||||
|
||||
/**
|
||||
* Enables finding usages of TOML version catalog entries in subprojects.
|
||||
*/
|
||||
class GradleTomlUseScopeEnlarger : UseScopeEnlarger() {
|
||||
override fun getAdditionalUseScope(element: PsiElement): SearchScope? {
|
||||
if (element !is TomlElement) return null
|
||||
val containingFile = element.containingFile?.virtualFile ?: return null
|
||||
val versionCatalogFiles = getVersionCatalogFiles(element.project).values
|
||||
if (containingFile !in versionCatalogFiles) {
|
||||
return null
|
||||
}
|
||||
if (!isInVersionCatalog(element)) return null
|
||||
return GradleBuildscriptSearchScope(element.project)
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,11 @@ internal object GradleVersionCatalogFixtures {
|
||||
withSettingsFile(gradleVersion) {
|
||||
includeBuild("includedBuild1")
|
||||
}
|
||||
withSettingsFile(gradleVersion, "includedBuild1",) {
|
||||
include("subproject1")
|
||||
}
|
||||
withBuildFile(gradleVersion, "includedBuild1")
|
||||
withBuildFile(gradleVersion, "includedBuild1/subproject1")
|
||||
withFile("includedBuild1/gradle/libs.versions.toml", "")
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -8,6 +8,7 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.annotations.Unmodifiable
|
||||
import org.jetbrains.plugins.gradle.dsl.versionCatalogs.GradleVersionCatalogFixtures.BASE_VERSION_CATALOG_FIXTURE
|
||||
import org.jetbrains.plugins.gradle.dsl.versionCatalogs.GradleVersionCatalogFixtures.DYNAMICALLY_INCLUDED_SUBPROJECTS_FIXTURE
|
||||
import org.jetbrains.plugins.gradle.dsl.versionCatalogs.GradleVersionCatalogFixtures.VERSION_CATALOG_COMPOSITE_BUILD_FIXTURE
|
||||
import org.jetbrains.plugins.gradle.testFramework.GradleCodeInsightTestCase
|
||||
import org.jetbrains.plugins.gradle.testFramework.annotations.BaseGradleVersionSource
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
@@ -103,6 +104,24 @@ class GradleVersionCatalogsFindUsagesTest : GradleCodeInsightTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@BaseGradleVersionSource
|
||||
fun testNestedProjectOfIncludedBuild(gradleVersion: GradleVersion) {
|
||||
test(gradleVersion, VERSION_CATALOG_COMPOSITE_BUILD_FIXTURE) {
|
||||
writeTextAndCommit("includedBuild1/gradle/libs.versions.toml", /* language=TOML */ """
|
||||
[libraries]
|
||||
apache-gro<caret>ovy = { module = "org.apache.groovy:groovy", version = "4.0.0" }
|
||||
""".trimIndent()
|
||||
)
|
||||
writeTextAndCommit("includedBuild1/subproject1/build.gradle", "libs.apache.groovy")
|
||||
runInEdtAndWait {
|
||||
codeInsightFixture.configureFromExistingVirtualFile(getFile("includedBuild1/gradle/libs.versions.toml"))
|
||||
val usages = ReferencesSearch.search(codeInsightFixture.elementAtCaret).findAll()
|
||||
assertContainsUsagesInFiles(usages, "includedBuild1/subproject1/build.gradle")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@BaseGradleVersionSource
|
||||
fun testDynamicallyAddedSubprojectAndCustomToml(gradleVersion: GradleVersion) {
|
||||
|
||||
Reference in New Issue
Block a user