Skip to content

Commit

Permalink
chore: get Qute LS from command context
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Sep 30, 2024
1 parent 54f33f5 commit eedb7bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,28 @@
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.lsp4ij.LanguageServiceAccessor;
import com.redhat.devtools.lsp4ij.LanguageServerItem;
import com.redhat.devtools.lsp4ij.commands.CommandExecutor;
import com.redhat.devtools.lsp4ij.commands.LSPCommand;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class QuteGenerateTemplateAction extends QuteAction {

private static final String TEMPLATE_FILE_URI = "templateFileUri";
private static final String QUTE_COMMAND_GENERATE_TEMPLATE_CONTENT = "qute.command.generate.template.content";
private static System.Logger LOGGER = System.getLogger(QuteGenerateTemplateAction.class.getName());

private LanguageServer getFirstServer(AnActionEvent e) {
List<LanguageServer> servers = LanguageServiceAccessor.getInstance(e.getProject()).getActiveLanguageServers(cap -> {
ExecuteCommandOptions provider = cap.getExecuteCommandProvider();
return provider != null && provider.getCommands().contains(QUTE_COMMAND_GENERATE_TEMPLATE_CONTENT);
});
return servers.isEmpty() ? null : servers.get(0);
}
private static System.Logger LOGGER = System.getLogger(QuteGenerateTemplateAction.class.getName());

@Override
protected void commandPerformed(@NotNull LSPCommand command, @NotNull AnActionEvent e) {
LanguageServer server = getFirstServer(e);
LanguageServerItem server = e.getDataContext().getData(CommandExecutor.LSP_COMMAND_LANGUAGE_SERVER);
try {
if (server != null) {
URI uri = getURI(command);
Expand All @@ -70,7 +62,7 @@ protected void commandPerformed(@NotNull LSPCommand command, @NotNull AnActionEv
return content;
}).exceptionally(ex -> {
LOGGER.log(System.Logger.Level.WARNING, "Error while generating Qute template", ex);
return ex;
return ex;
});
}
} catch (URISyntaxException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import com.redhat.devtools.lsp4ij.LSPIJUtils;
import com.redhat.devtools.lsp4ij.commands.LSPCommand;
import com.redhat.qute.commons.QuteJavaDefinitionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Location;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class QuteJavaDefinitionAction extends QuteAction {

private static final String PROJECT_URI_ATTR = "projectUri";
private static final String SOURCE_TYPE_ATTR = "sourceType";
private static final String SOURCE_FIELD_ATTR = "sourceField";
Expand Down

0 comments on commit eedb7bd

Please sign in to comment.