16
16
import com .intellij .openapi .fileEditor .FileEditorManager ;
17
17
import com .intellij .openapi .vfs .VfsUtil ;
18
18
import com .intellij .openapi .vfs .VirtualFile ;
19
- import com .redhat .devtools .lsp4ij .LanguageServiceAccessor ;
19
+ import com .redhat .devtools .lsp4ij .LanguageServerItem ;
20
+ import com .redhat .devtools .lsp4ij .commands .CommandExecutor ;
20
21
import com .redhat .devtools .lsp4ij .commands .LSPCommand ;
21
- import org .eclipse .lsp4j .ExecuteCommandOptions ;
22
22
import org .eclipse .lsp4j .ExecuteCommandParams ;
23
- import org .eclipse .lsp4j .services .LanguageServer ;
24
23
import org .jetbrains .annotations .NotNull ;
25
24
26
25
import java .io .IOException ;
27
26
import java .net .URI ;
28
27
import java .net .URISyntaxException ;
29
28
import java .nio .file .Files ;
30
29
import java .nio .file .Path ;
31
- import java .util .List ;
32
30
33
31
public class QuteGenerateTemplateAction extends QuteAction {
32
+
34
33
private static final String TEMPLATE_FILE_URI = "templateFileUri" ;
35
34
private static final String QUTE_COMMAND_GENERATE_TEMPLATE_CONTENT = "qute.command.generate.template.content" ;
36
- private static System .Logger LOGGER = System .getLogger (QuteGenerateTemplateAction .class .getName ());
37
35
38
- private LanguageServer getFirstServer (AnActionEvent e ) {
39
- List <LanguageServer > servers = LanguageServiceAccessor .getInstance (e .getProject ()).getActiveLanguageServers (cap -> {
40
- ExecuteCommandOptions provider = cap .getExecuteCommandProvider ();
41
- return provider != null && provider .getCommands ().contains (QUTE_COMMAND_GENERATE_TEMPLATE_CONTENT );
42
- });
43
- return servers .isEmpty () ? null : servers .get (0 );
44
- }
36
+ private static System .Logger LOGGER = System .getLogger (QuteGenerateTemplateAction .class .getName ());
45
37
46
38
@ Override
47
39
protected void commandPerformed (@ NotNull LSPCommand command , @ NotNull AnActionEvent e ) {
48
- LanguageServer server = getFirstServer ( e );
40
+ LanguageServerItem server = e . getDataContext (). getData ( CommandExecutor . LSP_COMMAND_LANGUAGE_SERVER );
49
41
try {
50
42
if (server != null ) {
51
43
URI uri = getURI (command );
@@ -70,7 +62,7 @@ protected void commandPerformed(@NotNull LSPCommand command, @NotNull AnActionEv
70
62
return content ;
71
63
}).exceptionally (ex -> {
72
64
LOGGER .log (System .Logger .Level .WARNING , "Error while generating Qute template" , ex );
73
- return ex ;
65
+ return ex ;
74
66
});
75
67
}
76
68
} catch (URISyntaxException ex ) {
0 commit comments