From f2c64f0082af9b4dad4bcb7488ca1ca7a2264393 Mon Sep 17 00:00:00 2001 From: Magnus Eide-Fredriksen Date: Fri, 25 Oct 2024 16:38:17 +0200 Subject: [PATCH 1/2] fix: double check correct .rng files are extracted from lemminx vespa jar --- .../schema-language-server/clients/vscode/package.json | 3 +-- .../schema-language-server/clients/vscode/src/extension.ts | 6 +++--- .../src/main/java/ai/vespa/lemminx/UnpackRNGFiles.java | 4 +++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/integration/schema-language-server/clients/vscode/package.json b/integration/schema-language-server/clients/vscode/package.json index ab32feee1c4a..14f4265435e0 100644 --- a/integration/schema-language-server/clients/vscode/package.json +++ b/integration/schema-language-server/clients/vscode/package.json @@ -36,8 +36,7 @@ ], "extensions": [ ".sd", - ".profile", - ".yql" + ".profile" ], "configuration": "./language-configuration.json" } diff --git a/integration/schema-language-server/clients/vscode/src/extension.ts b/integration/schema-language-server/clients/vscode/src/extension.ts index 80c97636da12..c720a4791835 100644 --- a/integration/schema-language-server/clients/vscode/src/extension.ts +++ b/integration/schema-language-server/clients/vscode/src/extension.ts @@ -144,7 +144,7 @@ export function activate(context: vscode.ExtensionContext) { }))); - context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.findSchemaDefinition", async (fileName) => { + context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.schema.findSchemaDefinition", async (fileName) => { if (schemaClient === null) { return null; } @@ -161,7 +161,7 @@ export function activate(context: vscode.ExtensionContext) { })); // This command exists to setup schema language server workspace in case the first opened document is an xml file (which not handled by schema language server) - context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.setupWorkspace", async (fileURI) => { + context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.schema.setupWorkspace", async (fileURI) => { if (schemaClient === null) { return; } @@ -175,7 +175,7 @@ export function activate(context: vscode.ExtensionContext) { } })); - context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.hasSetupWorkspace", async () => { + context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.commands.schema.hasSetupWorkspace", async () => { if (schemaClient === null) { return false; } diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/UnpackRNGFiles.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/UnpackRNGFiles.java index 3efe9968921e..6449287effaf 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/UnpackRNGFiles.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/UnpackRNGFiles.java @@ -41,12 +41,14 @@ public static void unpackRNGFiles(Path serverPath) throws IOException { Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); - if (!entry.isDirectory() && entry.getName().endsWith(".rng")) { + if (!entry.isDirectory() && entry.getName().endsWith(".rng") && entry.getName().startsWith("resources/schema")) { Path writePath = serverPath.resolve(entry.getName()); try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(entry.getName())) { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String content = reader.lines().collect(Collectors.joining(System.lineSeparator())); Files.write(writePath, content.getBytes(), StandardOpenOption.CREATE); + } catch (Exception ex) { + // Ignore: unwanted .rng file } } } From a6de126e5b68dae495f792fd7dbf8b711c0fa65b Mon Sep 17 00:00:00 2001 From: Magnus Eide-Fredriksen Date: Fri, 25 Oct 2024 16:43:37 +0200 Subject: [PATCH 2/2] chore: refactor lemminx extension structure --- .../lemminx/ServicesURIResolverExtension.java | 1 - .../java/ai/vespa/lemminx/VespaExtension.java | 6 ++++++ .../{ => command}/SchemaLSCommands.java | 8 ++++---- .../participants/CodeActionParticipant.java | 20 +++++++++++++++++++ .../DefinitionParticipant.java | 4 +++- .../DiagnosticsParticipant.java | 4 +++- .../DocumentLifecycleParticipant.java | 4 +++- .../{ => participants}/HoverParticipant.java | 19 ++++++------------ 8 files changed, 45 insertions(+), 21 deletions(-) rename integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/{ => command}/SchemaLSCommands.java (89%) create mode 100644 integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/CodeActionParticipant.java rename integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/{ => participants}/DefinitionParticipant.java (93%) rename integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/{ => participants}/DiagnosticsParticipant.java (96%) rename integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/{ => participants}/DocumentLifecycleParticipant.java (93%) rename integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/{ => participants}/HoverParticipant.java (90%) diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/ServicesURIResolverExtension.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/ServicesURIResolverExtension.java index 90cf6f5de76d..ef7436fc0ade 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/ServicesURIResolverExtension.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/ServicesURIResolverExtension.java @@ -1,7 +1,6 @@ package ai.vespa.lemminx; import java.nio.file.Path; -import java.util.logging.Logger; import org.eclipse.lemminx.uriresolver.URIResolverExtension; diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/VespaExtension.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/VespaExtension.java index adabeec89c05..d02b9b13caec 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/VespaExtension.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/VespaExtension.java @@ -14,6 +14,12 @@ import org.eclipse.lemminx.uriresolver.URIResolverExtension; import org.eclipse.lsp4j.InitializeParams; +import ai.vespa.lemminx.command.SchemaLSCommands; +import ai.vespa.lemminx.participants.DefinitionParticipant; +import ai.vespa.lemminx.participants.DiagnosticsParticipant; +import ai.vespa.lemminx.participants.DocumentLifecycleParticipant; +import ai.vespa.lemminx.participants.HoverParticipant; + public class VespaExtension implements IXMLExtension { private static final Logger logger = Logger.getLogger(VespaExtension.class.getName()); diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/SchemaLSCommands.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/command/SchemaLSCommands.java similarity index 89% rename from integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/SchemaLSCommands.java rename to integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/command/SchemaLSCommands.java index 1743cb81e990..56371911d9f2 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/SchemaLSCommands.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/command/SchemaLSCommands.java @@ -1,4 +1,4 @@ -package ai.vespa.lemminx; +package ai.vespa.lemminx.command; import java.lang.reflect.Type; import java.util.List; @@ -35,12 +35,12 @@ public static SchemaLSCommands instance() { } public void sendSetupWorkspaceRequest(String fileURI) { - commandService.executeClientCommand(new ExecuteCommandParams("vespaSchemaLS.commands.setupWorkspace", List.of(fileURI))); + commandService.executeClientCommand(new ExecuteCommandParams("vespaSchemaLS.commands.schema.setupWorkspace", List.of(fileURI))); } public boolean hasSetupWorkspace() { Object result = commandService.executeClientCommand( - new ExecuteCommandParams("vespaSchemaLS.commands.hasSetupWorkspace", List.of())).join(); + new ExecuteCommandParams("vespaSchemaLS.commands.schema.hasSetupWorkspace", List.of())).join(); if (result == null) return false; try { String json = gson.toJson(result); @@ -59,7 +59,7 @@ public boolean hasSetupWorkspace() { public List findSchemaDefinition(String schemaName) { // run sync Object findDocumentResult = commandService.executeClientCommand( - new ExecuteCommandParams("vespaSchemaLS.commands.findSchemaDefinition", List.of(schemaName))).join(); + new ExecuteCommandParams("vespaSchemaLS.commands.schema.findSchemaDefinition", List.of(schemaName))).join(); if (findDocumentResult == null) return List.of(); try { diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/CodeActionParticipant.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/CodeActionParticipant.java new file mode 100644 index 000000000000..6d151d33d533 --- /dev/null +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/CodeActionParticipant.java @@ -0,0 +1,20 @@ +package ai.vespa.lemminx.participants; + +import java.util.List; +import java.util.concurrent.CancellationException; +import java.util.logging.Logger; + +import org.eclipse.lemminx.services.extensions.codeaction.ICodeActionParticipant; +import org.eclipse.lemminx.services.extensions.codeaction.ICodeActionRequest; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.jsonrpc.CancelChecker; + +public class CodeActionParticipant implements ICodeActionParticipant { + private static final Logger logger = Logger.getLogger(CodeActionParticipant.class.getName()); + + @Override + public void doCodeAction(ICodeActionRequest request, List codeActions, CancelChecker cancelChecker) throws CancellationException { + logger.info(request.getDiagnostic().toString()); + } +} + diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DefinitionParticipant.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DefinitionParticipant.java similarity index 93% rename from integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DefinitionParticipant.java rename to integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DefinitionParticipant.java index 5424b80118cb..6347540f3f20 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DefinitionParticipant.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DefinitionParticipant.java @@ -1,4 +1,4 @@ -package ai.vespa.lemminx; +package ai.vespa.lemminx.participants; import java.util.List; import java.util.logging.Logger; @@ -10,6 +10,8 @@ import org.eclipse.lsp4j.LocationLink; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +import ai.vespa.lemminx.command.SchemaLSCommands; + public class DefinitionParticipant implements IDefinitionParticipant { private static final Logger logger = Logger.getLogger(DefinitionParticipant.class.getName()); diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DiagnosticsParticipant.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DiagnosticsParticipant.java similarity index 96% rename from integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DiagnosticsParticipant.java rename to integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DiagnosticsParticipant.java index 0f29575d4562..3cd5ac8e64f8 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DiagnosticsParticipant.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DiagnosticsParticipant.java @@ -1,4 +1,4 @@ -package ai.vespa.lemminx; +package ai.vespa.lemminx.participants; import java.util.List; import java.util.logging.Logger; @@ -17,6 +17,8 @@ import org.eclipse.lsp4j.jsonrpc.CancelChecker; import org.w3c.dom.Node; +import ai.vespa.lemminx.command.SchemaLSCommands; + public class DiagnosticsParticipant implements IDiagnosticsParticipant { private static final Logger logger = Logger.getLogger(DiagnosticsParticipant.class.getName()); diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DocumentLifecycleParticipant.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DocumentLifecycleParticipant.java similarity index 93% rename from integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DocumentLifecycleParticipant.java rename to integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DocumentLifecycleParticipant.java index 5de56b012fdb..e0d56836d591 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/DocumentLifecycleParticipant.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/DocumentLifecycleParticipant.java @@ -1,4 +1,4 @@ -package ai.vespa.lemminx; +package ai.vespa.lemminx.participants; import java.util.List; import java.util.logging.Logger; @@ -8,6 +8,8 @@ import org.eclipse.lemminx.services.extensions.commands.IXMLCommandService; import org.eclipse.lsp4j.ExecuteCommandParams; +import ai.vespa.lemminx.command.SchemaLSCommands; + public class DocumentLifecycleParticipant implements IDocumentLifecycleParticipant { private static final Logger logger = Logger.getLogger(DocumentLifecycleParticipant.class.getName()); private IXMLCommandService commandService; diff --git a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/HoverParticipant.java b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/HoverParticipant.java similarity index 90% rename from integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/HoverParticipant.java rename to integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/HoverParticipant.java index 09ef2ab17fad..0bc1c4dddd4c 100644 --- a/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/HoverParticipant.java +++ b/integration/schema-language-server/lemminx-vespa/src/main/java/ai/vespa/lemminx/participants/HoverParticipant.java @@ -1,4 +1,4 @@ -package ai.vespa.lemminx; +package ai.vespa.lemminx.participants; import java.io.IOException; import java.nio.file.Files; @@ -9,7 +9,6 @@ import java.util.logging.Logger; import java.util.stream.Stream; -import org.eclipse.lemminx.dom.DOMNode; import org.eclipse.lemminx.services.extensions.hover.IHoverParticipant; import org.eclipse.lemminx.services.extensions.hover.IHoverRequest; import org.eclipse.lsp4j.Hover; @@ -17,6 +16,9 @@ import org.eclipse.lsp4j.MarkupKind; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +/** + * TODO: refactor and handle tags with the same name based on context. + */ public class HoverParticipant implements IHoverParticipant { private static final Logger logger = Logger.getLogger(HoverParticipant.class.getName()); private Path serverPath; @@ -29,15 +31,6 @@ public HoverParticipant(Path serverPath) { public Hover onTag(IHoverRequest request, CancelChecker cancelChecker) throws Exception { if (request.getCurrentTag() == null) return null; - DOMNode node = request.getNode(); - - String logMsg = ""; - while (node != null) { - logMsg += node.getNodeName() + " -> "; - node = node.getParentNode(); - } - logger.info(logMsg); - Optional content = getFileHover(request.getCurrentTag()); if (content.isEmpty()) return null; @@ -85,8 +78,8 @@ private Optional getFileHover(String tagName) { markdownFiles.put(tag, innerPath); } }); - } catch (IOException ex) { - logger.severe("Inner ioexception"); + } catch (IOException ex) { + // Ignore } } else { String tag = path.getFileName().toString();