Skip to content

Commit 6ec1388

Browse files
committed
feat: click on insert section codelens must show references
Signed-off-by: azerr <[email protected]>
1 parent ac64890 commit 6ec1388

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteServer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import com.intellij.openapi.vfs.VirtualFile;
1919
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
2020
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
21+
import com.redhat.devtools.intellij.qute.psi.QuteCommandConstants;
2122
import com.redhat.devtools.lsp4ij.server.JavaProcessCommandBuilder;
2223
import com.redhat.devtools.lsp4ij.server.OSProcessStreamConnectionProvider;
23-
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider;
2424
import com.redhat.devtools.intellij.qute.settings.UserDefinedQuteSettings;
25-
import org.slf4j.Logger;
26-
import org.slf4j.LoggerFactory;
2725

2826
import java.nio.file.Path;
2927
import java.util.Arrays;
@@ -63,7 +61,10 @@ public Object getInitializationOptions(VirtualFile rootUri) {
6361
Map<String, Object> extendedClientCapabilities = new HashMap<>();
6462
Map<String, Object> commands = new HashMap<>();
6563
Map<String, Object> commandsKind = new HashMap<>();
66-
commandsKind.put("valueSet", Arrays.asList("qute.command.java.definition", "qute.command.configuration.update" , "qute.command.open.uri"));
64+
commandsKind.put("valueSet", Arrays.asList(QuteCommandConstants.OPEN_URI,
65+
QuteCommandConstants.JAVA_DEFINITION,
66+
QuteCommandConstants.COMMAND_CONFIGURATION_UPDATE,
67+
QuteCommandConstants.COMMAND_SHOW_REFERENCES));
6768
commands.put("commandsKind", commandsKind);
6869
extendedClientCapabilities.put("commands", commands);
6970
extendedClientCapabilities.put("shouldLanguageServerExitOnShutdown", Boolean.TRUE);

src/main/java/com/redhat/devtools/intellij/qute/psi/QuteCommandConstants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
*/
2020
public class QuteCommandConstants {
2121

22-
public static final String QUTE_COMMAND_OPEN_URI = "qute.command.open.uri";
22+
public static final String OPEN_URI = "qute.command.open.uri";
23+
public static final String JAVA_DEFINITION = "qute.command.java.definition";
24+
public static final String COMMAND_CONFIGURATION_UPDATE = "qute.command.configuration.update";
25+
public static final String COMMAND_SHOW_REFERENCES = "qute.command.show.references";
2326

24-
public static final String QUTE_COMMAND_GENERATE_TEMPLATE_FILE = "qute.command.generate.template.file";
27+
public static final String GENERATE_TEMPLATE_FILE = "qute.command.generate.template.file";
2528

2629
private QuteCommandConstants() {
2730

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.qute.psi.core.command;
12+
13+
import com.intellij.openapi.actionSystem.AnActionEvent;
14+
import com.intellij.openapi.project.Project;
15+
import com.redhat.devtools.lsp4ij.LSPIJUtils;
16+
import com.redhat.devtools.lsp4ij.commands.LSPCommand;
17+
import com.redhat.devtools.lsp4ij.usages.LSPUsageType;
18+
import com.redhat.devtools.lsp4ij.usages.LSPUsagesManager;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
import java.awt.event.MouseEvent;
22+
23+
public class QuteShowReferencesAction extends QuteAction {
24+
25+
@Override
26+
protected void commandPerformed(@NotNull LSPCommand command, @NotNull AnActionEvent e) {
27+
Project project = e.getProject();
28+
if (project == null) {
29+
return;
30+
}
31+
32+
// Call "Find Usages" in popup mode.
33+
LSPUsagesManager.getInstance(project).findShowUsagesInPopup(locations,
34+
LSPUsageType.References,
35+
dataContext,
36+
(MouseEvent) e.getInputEvent());
37+
}
38+
39+
}

src/main/java/com/redhat/devtools/intellij/qute/psi/internal/java/QuteJavaCodeLensCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected void collectTemplateLink(String basePath, PsiElement fieldOrMethod, Ps
7474
? MessageFormat.format(QUTE_COMMAND_OPEN_URI_WITH_FRAGMENT_MESSAGE, fragmentId, templateUri)
7575
: MessageFormat.format(QUTE_COMMAND_OPEN_URI_MESSAGE, templateUri);
7676
command = new Command(title, //
77-
QuteCommandConstants.QUTE_COMMAND_OPEN_URI,
77+
QuteCommandConstants.OPEN_URI,
7878
Arrays.asList(LSPIJUtils.toUriAsString(templateFile)));
7979
} else {
8080
List<DataModelParameter> parameters = createParameters(fieldOrMethod);
@@ -84,7 +84,7 @@ protected void collectTemplateLink(String basePath, PsiElement fieldOrMethod, Ps
8484
info.setTemplateFileUri(getVirtualFileUrl(utils.getModule(), templateUri));
8585
info.setTemplateFilePath(templateUri);
8686
command = new Command(MessageFormat.format(QUTE_COMMAND_GENERATE_TEMPLATE_MESSAGE, templateUri), //
87-
QuteCommandConstants.QUTE_COMMAND_GENERATE_TEMPLATE_FILE, Arrays.asList(info));
87+
QuteCommandConstants.GENERATE_TEMPLATE_FILE, Arrays.asList(info));
8888
}
8989
TextRange tr = fieldOrMethod.getTextRange();
9090
Range range = utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength());

src/main/resources/META-INF/plugin.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,20 +779,25 @@
779779
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="/META-INF/lsp4ij-qute.xml"
780780
xpointer="xpointer(/idea-plugin/*)"/>
781781
<actions>
782+
<!-- Custom LSP client command for MicroProfile LS -->
782783
<action id="microprofile.command.open.uri"
783784
class="com.redhat.devtools.intellij.lsp4mp4ij.psi.core.command.MicroprofileOpenURIAction"
784785
text="MicroprofileOpenURIAction"/>
785786
<action id="microprofile.command.configuration.update"
786787
class="com.redhat.devtools.intellij.lsp4mp4ij.psi.core.command.MicroprofileUpdateConfigurationAction"
787788
text="MicroprofileUpdateConfigurationAction"/>
789+
790+
<!-- Custom LSP client command for Qute LS -->
788791
<action id="qute.command.open.uri"
789792
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteOpenURIAction"/>
790-
<action id="qute.command.generate.template.file"
791-
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteGenerateTemplateAction"/>
792793
<action id="qute.command.java.definition"
793794
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteJavaDefinitionAction"/>
794795
<action id="qute.command.configuration.update"
795796
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteUpdateConfigurationAction"/>
797+
<action id="qute.command.show.references"
798+
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteShowReferencesAction"/>
799+
<action id="qute.command.generate.template.file"
800+
class="com.redhat.devtools.intellij.qute.psi.core.command.QuteGenerateTemplateAction"/>
796801

797802
</actions>
798803
</idea-plugin>

0 commit comments

Comments
 (0)