Skip to content

Commit

Permalink
Merge pull request #32671 from vespa-engine/interns/magnus/lemminx-vespa
Browse files Browse the repository at this point in the history
Interns/magnus/lemminx vespa
  • Loading branch information
Mangern authored Oct 25, 2024
2 parents 8a993f6 + a6de126 commit 0bfea6f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
],
"extensions": [
".sd",
".profile",
".yql"
".profile"
],
"configuration": "./language-configuration.json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ai.vespa.lemminx;

import java.nio.file.Path;
import java.util.logging.Logger;

import org.eclipse.lemminx.uriresolver.URIResolverExtension;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public static void unpackRNGFiles(Path serverPath) throws IOException {
Enumeration<JarEntry> 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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vespa.lemminx;
package ai.vespa.lemminx.command;

import java.lang.reflect.Type;
import java.util.List;
Expand Down Expand Up @@ -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);
Expand All @@ -59,7 +59,7 @@ public boolean hasSetupWorkspace() {
public List<Location> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CodeAction> codeActions, CancelChecker cancelChecker) throws CancellationException {
logger.info(request.getDiagnostic().toString());
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vespa.lemminx;
package ai.vespa.lemminx.participants;

import java.util.List;
import java.util.logging.Logger;
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vespa.lemminx;
package ai.vespa.lemminx.participants;

import java.util.List;
import java.util.logging.Logger;
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vespa.lemminx;
package ai.vespa.lemminx.participants;

import java.util.List;
import java.util.logging.Logger;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vespa.lemminx;
package ai.vespa.lemminx.participants;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -9,14 +9,16 @@
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;
import org.eclipse.lsp4j.MarkupContent;
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;
Expand All @@ -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<MarkupContent> content = getFileHover(request.getCurrentTag());

if (content.isEmpty()) return null;
Expand Down Expand Up @@ -85,8 +78,8 @@ private Optional<MarkupContent> getFileHover(String tagName) {
markdownFiles.put(tag, innerPath);
}
});
} catch (IOException ex) {
logger.severe("Inner ioexception");
} catch (IOException ex) {
// Ignore
}
} else {
String tag = path.getFileName().toString();
Expand Down

0 comments on commit 0bfea6f

Please sign in to comment.