diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/SchemaTextDocumentService.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/SchemaTextDocumentService.java index 63928109952a..ddc724b526bb 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/SchemaTextDocumentService.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/SchemaTextDocumentService.java @@ -209,7 +209,6 @@ public void didOpen(DidOpenTextDocumentParams params) { @Override public void didChange(DidChangeTextDocumentParams params) { var document = params.getTextDocument(); - SchemaDocumentScheduler scheduler = eventContextCreator.scheduler; var contentChanges = params.getContentChanges(); diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/codeaction/provider/RefactorRewriteProvider.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/codeaction/provider/RefactorRewriteProvider.java index 51967466f5f6..8d07d9482912 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/codeaction/provider/RefactorRewriteProvider.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/codeaction/provider/RefactorRewriteProvider.java @@ -57,7 +57,12 @@ private Optional getMoveRankProfile(SchemaNode node, EventCodeAction action.setTitle("Move '" + rankProfileName + "' to separate file"); action.setKind(CodeActionKind.RefactorRewrite); action.setEdit(edit); - action.setCommand(CommandRegistry.createLSPCommand(CommandType.DOCUMENT_OPEN, List.of(rankProfileURI))); + //action.setCommand(CommandRegistry.createLSPCommand(CommandType.DOCUMENT_OPEN, List.of(rankProfileURI))); + //action.setCommand(CommandRegistry.createLSPCommand(CommandType.DOCUMENT_PARSE, List.of(context.document.getFileURI()))); + action.setCommand(CommandRegistry.createLSPCommand(CommandType.COMMAND_LIST, List.of( + CommandRegistry.createLSPCommand(CommandType.DOCUMENT_PARSE, List.of(context.document.getFileURI())), + CommandRegistry.createLSPCommand(CommandType.DOCUMENT_OPEN, List.of(rankProfileURI)) + ))); return Optional.of(action); } diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java index 558a68bfc400..c346febe8e43 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/CommandRegistry.java @@ -8,6 +8,8 @@ import org.eclipse.lsp4j.ExecuteCommandParams; import ai.vespa.schemals.lsp.command.commandtypes.DocumentOpen; +import ai.vespa.schemals.lsp.command.commandtypes.DocumentParse; +import ai.vespa.schemals.lsp.command.commandtypes.CommandList; import ai.vespa.schemals.lsp.command.commandtypes.SchemaCommand; /** @@ -22,6 +24,14 @@ public enum CommandType implements GenericCommandType { DOCUMENT_OPEN { public String title() { return "Open document"; } public SchemaCommand construct() { return new DocumentOpen(); } + }, + DOCUMENT_PARSE { + public String title() { return "Parse document"; } + public SchemaCommand construct() { return new DocumentParse(); } + }, + COMMAND_LIST { + public String title() { return "Command list"; } + public SchemaCommand construct() { return new CommandList(); } } } @@ -34,7 +44,7 @@ public static Optional getCommand(ExecuteCommandParams params) { CommandType commandType = CommandType.valueOf(params.getCommand()); SchemaCommand command = commandType.construct(); - if (command.getArity() != params.getArguments().size()) return Optional.empty(); + if (command.getArity() != -1 && command.getArity() != params.getArguments().size()) return Optional.empty(); if (!command.setArguments(params.getArguments())) return Optional.empty(); return Optional.of(command); } catch(Exception e) { diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/ExecuteCommand.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/ExecuteCommand.java index 35b3ac490700..7bcc28e0fca7 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/ExecuteCommand.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/ExecuteCommand.java @@ -12,6 +12,12 @@ public class ExecuteCommand { public static Object executeCommand(EventExecuteCommandContext context) { Optional command = CommandRegistry.getCommand(context.params); + if (command.isEmpty()) { + for (Object obj : context.params.getArguments()) { + context.logger.info(obj.getClass().toString() + " ||| " + obj.toString()); + } + } + command.ifPresent(cmd -> cmd.execute(context)); return null; } diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/CommandList.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/CommandList.java new file mode 100644 index 000000000000..8bab89c0fe8f --- /dev/null +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/CommandList.java @@ -0,0 +1,54 @@ +package ai.vespa.schemals.lsp.command.commandtypes; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.eclipse.lsp4j.ExecuteCommandParams; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import ai.vespa.schemals.lsp.command.CommandRegistry; +import ai.vespa.schemals.context.EventExecuteCommandContext; + +/** + * CommandList + * Represents a chain of commands to be executed one after another. + */ +public class CommandList implements SchemaCommand { + + List commandsToExecute = new ArrayList<>(); + + @Override + public int getArity() { + return -1; + } + + @Override + public boolean setArguments(List arguments) { + commandsToExecute.clear(); + + for (Object object : arguments) { + if (!(object instanceof JsonObject))return false; + + JsonObject jsonObject = (JsonObject)object; + + if (!jsonObject.has("command") || !jsonObject.get("command").isJsonPrimitive())return false; + if (!jsonObject.has("arguments") || !jsonObject.get("arguments").isJsonArray())return false; + + var params = new ExecuteCommandParams(jsonObject.get("command").getAsString(), new ArrayList(((JsonArray)jsonObject.get("arguments")).asList())); + Optional command = CommandRegistry.getCommand(params); + if (command.isEmpty()) return false; + commandsToExecute.add(command.get()); + } + return true; + } + + @Override + public void execute(EventExecuteCommandContext context) { + for (SchemaCommand cmd : commandsToExecute) { + cmd.execute(context); + } + } +} diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentOpen.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentOpen.java index b771e0a4add9..df9817d0e4c3 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentOpen.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentOpen.java @@ -10,6 +10,8 @@ /** * OpenDocument + * Kind of a reflection: client sends "Open document with fileURI", and server responds by telling the client to open it. + * Reason for this: Used in Code Actions to make file automatically open with new edit. */ public class DocumentOpen implements SchemaCommand { private String fileURI; @@ -18,9 +20,7 @@ public class DocumentOpen implements SchemaCommand { public void execute(EventExecuteCommandContext context) { if (fileURI == null) return; - context.logger.info("Show document: " + fileURI); ShowDocumentResult result = context.messageHandler.showDocument(fileURI).join(); - context.logger.info("Result: " + result.toString()); } @Override diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentParse.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentParse.java new file mode 100644 index 000000000000..a8fd312881f5 --- /dev/null +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/command/commandtypes/DocumentParse.java @@ -0,0 +1,39 @@ +package ai.vespa.schemals.lsp.command.commandtypes; + +import java.util.List; + +import com.google.gson.JsonPrimitive; + +import ai.vespa.schemals.context.EventExecuteCommandContext; +import ai.vespa.schemals.schemadocument.DocumentManager; + +/** + * DocumentParse + */ +public class DocumentParse implements SchemaCommand { + private String fileURI; + + @Override + public int getArity() { + return 1; + } + + @Override + public boolean setArguments(List arguments) { + assert arguments.size() == getArity(); + + if (!(arguments.get(0) instanceof JsonPrimitive)) + return false; + + JsonPrimitive arg = (JsonPrimitive) arguments.get(0); + this.fileURI = arg.getAsString(); + return true; + } + + @Override + public void execute(EventExecuteCommandContext context) { + DocumentManager document = context.scheduler.getDocument(fileURI); + if (document == null) return; + document.reparseContent(); + } +} diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/RankProfileDocument.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/RankProfileDocument.java index 0dae670fb2ea..478a92849f0e 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/RankProfileDocument.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/RankProfileDocument.java @@ -57,7 +57,6 @@ public void updateFileContent(String content) { var result = parseContent(context); diagnosticsHandler.publishDiagnostics(this.fileURI, result.diagnostics()); - logger.info("CST FOR RANK PROFILE " + this.fileURI); if (result.CST().isPresent()) { this.CST = result.CST().get(); lexer.setCST(CST);