[devkit] IJ-CR-145746 IJPL-163148: fix resolving actions from libraries

IJ-CR-145746
(cherry picked from commit 9be9bb7b5c646684069cc5885881c068f65b27ee)

GitOrigin-RevId: 63f30a64360ff8716fca3e6a837e1e3574c0de29
This commit is contained in:
Nicolay Mitropolsky
2025-01-06 20:43:54 +01:00
committed by intellij-monorepo-bot
parent 3edeaf4606
commit 9a9f103ced
2 changed files with 33 additions and 12 deletions

View File

@@ -44,7 +44,8 @@ final class ActionOrGroupIdReference extends PsiPolyVariantReferenceBase<PsiElem
public ResolveResult @NotNull [] multiResolve(boolean incompleteCode) { public ResolveResult @NotNull [] multiResolve(boolean incompleteCode) {
Project project = getElement().getProject(); Project project = getElement().getProject();
final GlobalSearchScope scope = ProjectScope.getContentScope(project); final GlobalSearchScope scope = ProjectScope.getContentScope(project)
.union(ProjectScope.getLibrariesScope(project));
CommonProcessors.CollectUniquesProcessor<ActionOrGroup> processor = new CommonProcessors.CollectUniquesProcessor<>(); CommonProcessors.CollectUniquesProcessor<ActionOrGroup> processor = new CommonProcessors.CollectUniquesProcessor<>();
collectResults(myId, scope, processor); collectResults(myId, scope, processor);

View File

@@ -1,23 +1,23 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.devkit.kotlin.codeInsight package org.jetbrains.idea.devkit.kotlin.codeInsight
import com.intellij.codeInspection.LocalInspectionEP
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.application.PathManager
import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.ui.components.JBList
import com.intellij.util.PathUtil
import org.jetbrains.idea.devkit.inspections.UnresolvedPluginConfigReferenceInspection import org.jetbrains.idea.devkit.inspections.UnresolvedPluginConfigReferenceInspection
class KtActionReferenceTest : LightJavaCodeInsightFixtureTestCase() { class KtActionReferenceTest : LightJavaCodeInsightFixtureTestCase() {
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
myFixture.addClass("package com.intellij.ui.components; public class JBList {}"); PsiTestUtil.addLibrary(myFixture.module, PathUtil.getJarPathForClass(JBList::class.java))
myFixture.addClass("package com.intellij.openapi.actionSystem; public abstract class AnAction {}"); PsiTestUtil.addLibrary(myFixture.module, PathUtil.getJarPathForClass(ActionManager::class.java))
myFixture.addClass(""" PsiTestUtil.addLibrary(myFixture.module,
package com.intellij.openapi.actionSystem; PathManager.getResourceRoot(LocalInspectionEP::class.java, "/idea/PlatformActions.xml")!!)
public abstract class ActionManager {
public abstract AnAction getAction(@NonNls @NotNull String actionId);
}
""".trimIndent())
} }
private fun pluginXmlActions(actionsText: String): String { private fun pluginXmlActions(actionsText: String): String {
@@ -49,6 +49,25 @@ class KtActionReferenceTest : LightJavaCodeInsightFixtureTestCase() {
myFixture.testHighlighting() myFixture.testHighlighting()
} }
fun testResolveLibrariActionId() {
val pluginXmlActions = pluginXmlActions("""
<action id="myAction"/>
""".trimIndent())
myFixture.createFile("plugin.xml", pluginXmlActions)
myFixture.createFile("anotherPlugin.xml", pluginXmlActions)
myFixture.configureByText("Caller.kt", """
fun usage(actionManager: com.intellij.openapi.actionSystem.ActionManager){
actionManager.getAction("$DLR{"\$DLR"}Undo")
actionManager.getAction("Find")
actionManager.getAction("<error>Unknown1</error>")
}
""".trimIndent())
myFixture.enableInspections(UnresolvedPluginConfigReferenceInspection::class.java)
myFixture.testHighlighting()
}
fun testRenameAction() { fun testRenameAction() {
myFixture.createFile("plugin.xml", pluginXmlActions(""" myFixture.createFile("plugin.xml", pluginXmlActions("""
<group id="myGroup"></group> <group id="myGroup"></group>
@@ -87,7 +106,6 @@ class KtActionReferenceTest : LightJavaCodeInsightFixtureTestCase() {
} }
fun testInvalidActionOrGroupReference() { fun testInvalidActionOrGroupReference() {
val DLR = '$'.toString()
myFixture.enableInspections(UnresolvedPluginConfigReferenceInspection::class.java) myFixture.enableInspections(UnresolvedPluginConfigReferenceInspection::class.java)
myFixture.createFile("plugin.xml", pluginXmlActions(""" myFixture.createFile("plugin.xml", pluginXmlActions("""
<group id="myGroup"></group> <group id="myGroup"></group>
@@ -128,4 +146,6 @@ class KtActionReferenceTest : LightJavaCodeInsightFixtureTestCase() {
), true) ), true)
} }
val DLR = '$'.toString()
} }