Skip to content

Commit

Permalink
chore: refactor lemminx extension structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mangern committed Oct 25, 2024
1 parent f2c64f0 commit a6de126
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
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 @@ -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 a6de126

Please sign in to comment.