diff --git a/plugins/plugin-java/che-plugin-java-server/src/main/java/org/eclipse/che/plugin/java/languageserver/JavaTextDocumentServiceWraper.java b/plugins/plugin-java/che-plugin-java-server/src/main/java/org/eclipse/che/plugin/java/languageserver/JavaTextDocumentServiceWraper.java index 033cb56353e..6a4db9543ea 100644 --- a/plugins/plugin-java/che-plugin-java-server/src/main/java/org/eclipse/che/plugin/java/languageserver/JavaTextDocumentServiceWraper.java +++ b/plugins/plugin-java/che-plugin-java-server/src/main/java/org/eclipse/che/plugin/java/languageserver/JavaTextDocumentServiceWraper.java @@ -30,11 +30,13 @@ import org.eclipse.che.api.fs.server.WsPathUtils; import org.eclipse.che.api.languageserver.LanguageServerException; import org.eclipse.che.api.languageserver.LanguageServiceUtils; +import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionParams; import org.eclipse.lsp4j.Command; import org.eclipse.lsp4j.DocumentFormattingParams; import org.eclipse.lsp4j.FormattingOptions; import org.eclipse.lsp4j.TextEdit; +import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.services.TextDocumentService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,14 +51,16 @@ public JavaTextDocumentServiceWraper(TextDocumentService wrapped) { this.wrapped = wrapped; } - public CompletableFuture> codeAction(CodeActionParams params) { - CompletableFuture> result = wrapped.codeAction(params); + public CompletableFuture>> codeAction(CodeActionParams params) { + CompletableFuture>> result = wrapped.codeAction(params); return result.thenApply( - (List commands) -> { + (List> commands) -> { commands.forEach( cmd -> { - if ("java.apply.workspaceEdit".equals(cmd.getCommand())) { - cmd.setCommand("lsp.applyWorkspaceEdit"); + if (cmd.isLeft()) { + if ("java.apply.workspaceEdit".equals(cmd.getLeft().getCommand())) { + cmd.getLeft().setCommand("lsp.applyWorkspaceEdit"); + } } }); return commands; diff --git a/plugins/plugin-languageserver/che-plugin-languageserver-ide/pom.xml b/plugins/plugin-languageserver/che-plugin-languageserver-ide/pom.xml index 1f6ec1225cc..82b1bf90dd2 100644 --- a/plugins/plugin-languageserver/che-plugin-languageserver-ide/pom.xml +++ b/plugins/plugin-languageserver/che-plugin-languageserver-ide/pom.xml @@ -236,6 +236,8 @@ org.eclipse.lsp4j.WatchKind org.eclipse.lsp4j.MarkupKind + org.eclipse.lsp4j.CodeActionKind + org.eclipse.lsp4j.FoldingRangeKind org.eclipse.lsp4j diff --git a/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/lsp/MavenTextDocumentService.java b/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/lsp/MavenTextDocumentService.java index 56b077af9f8..d9c97b20c2e 100644 --- a/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/lsp/MavenTextDocumentService.java +++ b/plugins/plugin-maven/che-plugin-maven-server/src/main/java/org/eclipse/che/plugin/maven/lsp/MavenTextDocumentService.java @@ -15,6 +15,7 @@ import java.util.concurrent.CompletableFuture; import javax.inject.Inject; import javax.inject.Singleton; +import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionParams; import org.eclipse.lsp4j.CodeLens; import org.eclipse.lsp4j.CodeLensParams; @@ -30,6 +31,7 @@ import org.eclipse.lsp4j.DocumentHighlight; import org.eclipse.lsp4j.DocumentOnTypeFormattingParams; import org.eclipse.lsp4j.DocumentRangeFormattingParams; +import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.DocumentSymbolParams; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Location; @@ -88,13 +90,13 @@ public CompletableFuture> documentHighlight( } @Override - public CompletableFuture> documentSymbol( + public CompletableFuture>> documentSymbol( DocumentSymbolParams params) { return null; } @Override - public CompletableFuture> codeAction(CodeActionParams params) { + public CompletableFuture>> codeAction(CodeActionParams params) { return null; } diff --git a/wsagent/che-core-api-languageserver/pom.xml b/wsagent/che-core-api-languageserver/pom.xml index ff46d2d37df..5f36072b243 100644 --- a/wsagent/che-core-api-languageserver/pom.xml +++ b/wsagent/che-core-api-languageserver/pom.xml @@ -160,6 +160,8 @@ org.eclipse.lsp4j.WatchKind org.eclipse.lsp4j.MarkupKind + org.eclipse.lsp4j.CodeActionKind + org.eclipse.lsp4j.FoldingRangeKind org.eclipse.lsp4j diff --git a/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/TextDocumentService.java b/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/TextDocumentService.java index 3a3e941da42..b264a30b86f 100644 --- a/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/TextDocumentService.java +++ b/wsagent/che-core-api-languageserver/src/main/java/org/eclipse/che/api/languageserver/TextDocumentService.java @@ -29,6 +29,7 @@ import java.io.StringReader; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -78,6 +79,7 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IRegion; +import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionParams; import org.eclipse.lsp4j.Command; import org.eclipse.lsp4j.CompletionItem; @@ -91,6 +93,7 @@ import org.eclipse.lsp4j.DocumentHighlight; import org.eclipse.lsp4j.DocumentOnTypeFormattingParams; import org.eclipse.lsp4j.DocumentRangeFormattingParams; +import org.eclipse.lsp4j.DocumentSymbol; import org.eclipse.lsp4j.DocumentSymbolParams; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Location; @@ -205,8 +208,8 @@ private List codeAction(CodeActionParams params) { textDocument.setUri(uri); List result = new ArrayList<>(); Set servers = findServer.byPath(wsPath); - LSOperation> op = - new LSOperation>() { + LSOperation>> op = + new LSOperation>>() { @Override public boolean canDo(ExtendedLanguageServer server) { @@ -214,14 +217,21 @@ public boolean canDo(ExtendedLanguageServer server) { } @Override - public CompletableFuture> start(ExtendedLanguageServer element) { + public CompletableFuture>> start( + ExtendedLanguageServer element) { return element.getTextDocumentService().codeAction(params); } @Override - public boolean handleResult(ExtendedLanguageServer element, List res) { - for (Command cmd : res) { - result.add(new CommandDto(cmd)); + public boolean handleResult( + ExtendedLanguageServer element, List> res) { + for (Either cmd : res) { + if (cmd.isLeft()) { + result.add(new CommandDto(cmd.getLeft())); + } else { + // see https://github.com/eclipse/che/issues/11140 + LOG.warn("Ignoring code action: {}", cmd.getRight()); + } } return false; } @@ -295,7 +305,7 @@ private List documentSymbol(DocumentSymbolParams documentS OperationUtil.doInParallel( servers, - new LSOperation>() { + new LSOperation>>() { @Override public boolean canDo(ExtendedLanguageServer element) { @@ -303,21 +313,41 @@ public boolean canDo(ExtendedLanguageServer element) { } @Override - public CompletableFuture> start( + public CompletableFuture>> start( ExtendedLanguageServer element) { return element.getTextDocumentService().documentSymbol(documentSymbolParams); } @Override public boolean handleResult( - ExtendedLanguageServer element, List locations) { + ExtendedLanguageServer element, + List> locations) { locations.forEach( o -> { - o.getLocation().setUri(removePrefixUri(o.getLocation().getUri())); - result.add(new SymbolInformationDto(o)); + // minimal fix for https://github.com/eclipse/che/issues/11139 when updating lsp4j + if (o.isLeft()) { + SymbolInformation si = o.getLeft(); + si.getLocation().setUri(removePrefixUri(si.getLocation().getUri())); + result.add(new SymbolInformationDto(si)); + } else { + result.addAll(convertDocumentSymbol(o.getRight())); + } }); return true; } + + private Collection convertDocumentSymbol( + DocumentSymbol symbol) { + ArrayList result = new ArrayList<>(); + result.add( + new SymbolInformationDto( + new SymbolInformation( + symbol.getName(), symbol.getKind(), new Location(uri, symbol.getRange())))); + for (DocumentSymbol child : symbol.getChildren()) { + result.addAll(convertDocumentSymbol(child)); + } + return result; + } }, 10000); return result;