Skip to content

Commit

Permalink
Update to LSP4J 0.5.0.M1
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Sep 13, 2018
1 parent da25ecf commit b23bf1c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,14 +51,16 @@ public JavaTextDocumentServiceWraper(TextDocumentService wrapped) {
this.wrapped = wrapped;
}

public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
CompletableFuture<List<? extends Command>> result = wrapped.codeAction(params);
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
CompletableFuture<List<Either<Command, CodeAction>>> result = wrapped.codeAction(params);
return result.thenApply(
(List<? extends Command> commands) -> {
(List<Either<Command, CodeAction>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
<excludes>
<exclude>org.eclipse.lsp4j.WatchKind</exclude>
<exclude>org.eclipse.lsp4j.MarkupKind</exclude>
<exclude>org.eclipse.lsp4j.CodeActionKind</exclude>
<exclude>org.eclipse.lsp4j.FoldingRangeKind</exclude>
</excludes>
<dtoPackages>
<package>org.eclipse.lsp4j</package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -88,13 +90,13 @@ public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(
}

@Override
public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
DocumentSymbolParams params) {
return null;
}

@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions wsagent/che-core-api-languageserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
<excludes>
<exclude>org.eclipse.lsp4j.WatchKind</exclude>
<exclude>org.eclipse.lsp4j.MarkupKind</exclude>
<exclude>org.eclipse.lsp4j.CodeActionKind</exclude>
<exclude>org.eclipse.lsp4j.FoldingRangeKind</exclude>
</excludes>
<dtoPackages>
<package>org.eclipse.lsp4j</package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -205,23 +208,30 @@ private List<CommandDto> codeAction(CodeActionParams params) {
textDocument.setUri(uri);
List<CommandDto> result = new ArrayList<>();
Set<ExtendedLanguageServer> servers = findServer.byPath(wsPath);
LSOperation<ExtendedLanguageServer, List<? extends Command>> op =
new LSOperation<ExtendedLanguageServer, List<? extends Command>>() {
LSOperation<ExtendedLanguageServer, List<Either<Command, CodeAction>>> op =
new LSOperation<ExtendedLanguageServer, List<Either<Command, CodeAction>>>() {

@Override
public boolean canDo(ExtendedLanguageServer server) {
return truish(server.getCapabilities().getCodeActionProvider());
}

@Override
public CompletableFuture<List<? extends Command>> start(ExtendedLanguageServer element) {
public CompletableFuture<List<Either<Command, CodeAction>>> start(
ExtendedLanguageServer element) {
return element.getTextDocumentService().codeAction(params);
}

@Override
public boolean handleResult(ExtendedLanguageServer element, List<? extends Command> res) {
for (Command cmd : res) {
result.add(new CommandDto(cmd));
public boolean handleResult(
ExtendedLanguageServer element, List<Either<Command, CodeAction>> res) {
for (Either<Command, CodeAction> 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;
}
Expand Down Expand Up @@ -295,29 +305,49 @@ private List<SymbolInformationDto> documentSymbol(DocumentSymbolParams documentS

OperationUtil.doInParallel(
servers,
new LSOperation<ExtendedLanguageServer, List<? extends SymbolInformation>>() {
new LSOperation<ExtendedLanguageServer, List<Either<SymbolInformation, DocumentSymbol>>>() {

@Override
public boolean canDo(ExtendedLanguageServer element) {
return truish(element.getCapabilities().getDocumentSymbolProvider());
}

@Override
public CompletableFuture<List<? extends SymbolInformation>> start(
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> start(
ExtendedLanguageServer element) {
return element.getTextDocumentService().documentSymbol(documentSymbolParams);
}

@Override
public boolean handleResult(
ExtendedLanguageServer element, List<? extends SymbolInformation> locations) {
ExtendedLanguageServer element,
List<Either<SymbolInformation, DocumentSymbol>> 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<? extends SymbolInformationDto> convertDocumentSymbol(
DocumentSymbol symbol) {
ArrayList<SymbolInformationDto> 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;
Expand Down

0 comments on commit b23bf1c

Please sign in to comment.