You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2019/04/30 18:49:59 UTC
[netbeans] branch master updated: Upgrading the LSP4J library to
0.7.0.
This is an automated email from the ASF dual-hosted git repository.
jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new c31b1fd Upgrading the LSP4J library to 0.7.0.
c31b1fd is described below
commit c31b1fd36b21d2669d82a96bfd476c9e540b4d4b
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Tue Apr 30 20:49:52 2019 +0200
Upgrading the LSP4J library to 0.7.0.
---
ide/lsp.client/external/binaries-list | 6 +-
...j-0.4.1-license.txt => lsp4j-0.7.0-license.txt} | 4 +-
ide/lsp.client/nbproject/project.properties | 6 +-
ide/lsp.client/nbproject/project.xml | 12 ++--
.../netbeans/modules/lsp/client/LSPBindings.java | 7 ++-
.../src/org/netbeans/modules/lsp/client/Utils.java | 65 +++++++++++++++++++++
.../modules/lsp/client/bindings/CodeActions.java | 12 ++--
.../lsp/client/bindings/HyperlinkProviderImpl.java | 49 ++++++++++------
.../lsp/client/bindings/LanguageClientImpl.java | 51 ++++-------------
.../lsp/client/bindings/NavigatorPanelImpl.java | 66 +++++++++++++++++++---
10 files changed, 192 insertions(+), 86 deletions(-)
diff --git a/ide/lsp.client/external/binaries-list b/ide/lsp.client/external/binaries-list
index 248d43a..1779fd7 100644
--- a/ide/lsp.client/external/binaries-list
+++ b/ide/lsp.client/external/binaries-list
@@ -15,9 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-90E34B7C7E0257E3993CA5A939AE94F889D31340 org.eclipse.lsp4j:org.eclipse.lsp4j:0.4.1
-467F27E91FD694C05EB663532F2EDE0404025AFE org.eclipse.lsp4j:org.eclipse.lsp4j.generator:0.4.1
-F3F93F50BBEB7D58B50E6FFCA615CBFC76491846 org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.4.1
+22FA797D3E83E92ABBA55D1020DECFB6FC7454BA org.eclipse.lsp4j:org.eclipse.lsp4j:0.7.0
+D5DA405216BFF241A78DDA7F44F35362E09BBDC2 org.eclipse.lsp4j:org.eclipse.lsp4j.generator:0.7.0
+4017EAB62A0845A1D166A1B902AE4EEFCA6594EB org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.7.0
56459301B64C92BBBB6E13988B91CDBE1FC6264E org.eclipse.xtend:org.eclipse.xtend.lib:2.14.0
F2FCA7A70C8A29374E79487417CEFB5F51A84867 org.eclipse.xtend:org.eclipse.xtend.lib.macro:2.14.0
C40FFE7E5E6244DD094AE95009AA45072C629254 org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.14.0
diff --git a/ide/lsp.client/external/lsp4j-0.4.1-license.txt b/ide/lsp.client/external/lsp4j-0.7.0-license.txt
similarity index 98%
rename from ide/lsp.client/external/lsp4j-0.4.1-license.txt
rename to ide/lsp.client/external/lsp4j-0.7.0-license.txt
index 8129cb7..1cff7fa 100644
--- a/ide/lsp.client/external/lsp4j-0.4.1-license.txt
+++ b/ide/lsp.client/external/lsp4j-0.7.0-license.txt
@@ -1,10 +1,10 @@
Name: Eclipse Language Server Protocol Library
Origin: Eclipse
-Version: 0.4.1
+Version: 0.7.0
License: EPL-v10
URL: http://www.eclipse.org/
Description: Eclipse Language Server Protocol Library
-Files: org.eclipse.lsp4j-0.4.1.jar org.eclipse.lsp4j.generator-0.4.1.jar org.eclipse.lsp4j.jsonrpc-0.4.1.jar
+Files: org.eclipse.lsp4j-0.7.0.jar org.eclipse.lsp4j.generator-0.7.0.jar org.eclipse.lsp4j.jsonrpc-0.7.0.jar
Eclipse Public License - v 1.0
diff --git a/ide/lsp.client/nbproject/project.properties b/ide/lsp.client/nbproject/project.properties
index 1118a91..bc9ed2c 100644
--- a/ide/lsp.client/nbproject/project.properties
+++ b/ide/lsp.client/nbproject/project.properties
@@ -18,9 +18,9 @@
javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial
javadoc.arch=${basedir}/arch.xml
-release.external/org.eclipse.lsp4j-0.4.1.jar=modules/ext/org.eclipse.lsp4j-0.4.1.jar
-release.external/org.eclipse.lsp4j.generator-0.4.1.jar=modules/ext/org.eclipse.lsp4j.generator-0.4.1.jar
-release.external/org.eclipse.lsp4j.jsonrpc-0.4.1.jar=modules/ext/org.eclipse.lsp4j.jsonrpc-0.4.1.jar
+release.external/org.eclipse.lsp4j-0.7.0.jar=modules/ext/org.eclipse.lsp4j-0.7.0.jar
+release.external/org.eclipse.lsp4j.generator-0.7.0.jar=modules/ext/org.eclipse.lsp4j.generator-0.7.0.jar
+release.external/org.eclipse.lsp4j.jsonrpc-0.7.0.jar=modules/ext/org.eclipse.lsp4j.jsonrpc-0.7.0.jar
release.external/org.eclipse.xtend.lib-2.14.0.jar=modules/ext/org.eclipse.xtend.lib-2.14.0.jar
release.external/org.eclipse.xtend.lib.macro-2.14.0.jar=modules/ext/org.eclipse.xtend.lib.macro-2.14.0.jar
release.external/org.eclipse.xtext.xbase.lib-2.14.0.jar=modules/ext/org.eclipse.xtext.xbase.lib-2.14.0.jar
diff --git a/ide/lsp.client/nbproject/project.xml b/ide/lsp.client/nbproject/project.xml
index c032598..00ad85f 100644
--- a/ide/lsp.client/nbproject/project.xml
+++ b/ide/lsp.client/nbproject/project.xml
@@ -224,16 +224,16 @@
<package>org.netbeans.modules.lsp.client.spi</package>
</public-packages>
<class-path-extension>
- <runtime-relative-path>ext/org.eclipse.lsp4j-0.4.1.jar</runtime-relative-path>
- <binary-origin>external/org.eclipse.lsp4j-0.4.1.jar</binary-origin>
+ <runtime-relative-path>ext/org.eclipse.lsp4j-0.7.0.jar</runtime-relative-path>
+ <binary-origin>external/org.eclipse.lsp4j-0.7.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/org.eclipse.xtend.lib.macro-2.14.0.jar</runtime-relative-path>
<binary-origin>external/org.eclipse.xtend.lib.macro-2.14.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
- <runtime-relative-path>ext/org.eclipse.lsp4j.generator-0.4.1.jar</runtime-relative-path>
- <binary-origin>external/org.eclipse.lsp4j.generator-0.4.1.jar</binary-origin>
+ <runtime-relative-path>ext/org.eclipse.lsp4j.generator-0.7.0.jar</runtime-relative-path>
+ <binary-origin>external/org.eclipse.lsp4j.generator-0.7.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/org.eclipse.xtend.lib-2.14.0.jar</runtime-relative-path>
@@ -244,8 +244,8 @@
<binary-origin>external/org.eclipse.xtext.xbase.lib-2.14.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
- <runtime-relative-path>ext/org.eclipse.lsp4j.jsonrpc-0.4.1.jar</runtime-relative-path>
- <binary-origin>external/org.eclipse.lsp4j.jsonrpc-0.4.1.jar</binary-origin>
+ <runtime-relative-path>ext/org.eclipse.lsp4j.jsonrpc-0.7.0.jar</runtime-relative-path>
+ <binary-origin>external/org.eclipse.lsp4j.jsonrpc-0.7.0.jar</binary-origin>
</class-path-extension>
</data>
</configuration>
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java
index 5889b9b..a0eb7be 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LSPBindings.java
@@ -35,6 +35,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.ClientCapabilities;
+import org.eclipse.lsp4j.DocumentSymbolCapabilities;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
@@ -164,7 +165,11 @@ public class LSPBindings {
initParams.setRootUri(Utils.toURI(root));
initParams.setRootPath(FileUtil.toFile(root).getAbsolutePath()); //some servers still expect root path
initParams.setProcessId(0);
- initParams.setCapabilities(new ClientCapabilities(new WorkspaceClientCapabilities(), new TextDocumentClientCapabilities(), null));
+ TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities();
+ DocumentSymbolCapabilities dsc = new DocumentSymbolCapabilities();
+ dsc.setHierarchicalDocumentSymbolSupport(true);
+ tdcc.setDocumentSymbol(dsc);
+ initParams.setCapabilities(new ClientCapabilities(new WorkspaceClientCapabilities(), tdcc, null));
return server.initialize(initParams).get();
}
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
index f972bc5..b924944 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/Utils.java
@@ -18,12 +18,29 @@
*/
package org.netbeans.modules.lsp.client;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
+import javax.swing.text.StyledDocument;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.Command;
+import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4j.TextEdit;
+import org.eclipse.lsp4j.WorkspaceEdit;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.editor.document.LineDocument;
import org.netbeans.api.editor.document.LineDocumentUtils;
+import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
+import org.openide.filesystems.URLMapper;
+import org.openide.text.NbDocument;
+import org.openide.util.Exceptions;
/**
*
@@ -43,4 +60,52 @@ public class Utils {
public static int getOffset(Document doc, Position pos) {
return LineDocumentUtils.getLineStartFromIndex((LineDocument) doc, pos.getLine()) + pos.getCharacter();
}
+
+ public static void applyWorkspaceEditor(WorkspaceEdit edit) {
+ for (Map.Entry<String, List<TextEdit>> e : edit.getChanges().entrySet()) {
+ try {
+ FileObject file = URLMapper.findFileObject(new URI(e.getKey()).toURL());
+ EditorCookie ec = file.getLookup().lookup(EditorCookie.class);
+ Document doc = ec != null ? ec.openDocument() : null;
+ if (doc == null) {
+ continue;
+ }
+ NbDocument.runAtomic((StyledDocument) doc, () -> {
+ e.getValue()
+ .stream()
+ .sorted((te1, te2) -> te1.getRange().getEnd().getLine() == te2.getRange().getEnd().getLine() ? te1.getRange().getEnd().getCharacter() - te2.getRange().getEnd().getCharacter() : te1.getRange().getEnd().getLine() - te2.getRange().getEnd().getLine())
+ .forEach(te -> {
+ try {
+ int start = Utils.getOffset(doc, te.getRange().getStart());
+ int end = Utils.getOffset(doc, te.getRange().getEnd());
+ doc.remove(start, end - start);
+ doc.insertString(start, te.getNewText(), null);
+ } catch (BadLocationException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ });
+ });
+ } catch (URISyntaxException | IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
+ }
+
+ public static void applyCodeAction(LSPBindings server, Either<Command, CodeAction> cmd) {
+ try {
+ Command command;
+
+ if (cmd.isLeft()) {
+ command = cmd.getLeft();
+ } else {
+ Utils.applyWorkspaceEditor(cmd.getRight().getEdit());
+ command = cmd.getRight().getCommand();
+ }
+ if (command != null) {
+ server.getWorkspaceService().executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments())).get();
+ }
+ } catch (InterruptedException | ExecutionException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
}
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java
index 982da88..6ba877c 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/CodeActions.java
@@ -24,12 +24,14 @@ import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
+import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.modules.editor.NbEditorUtilities;
import org.netbeans.modules.lsp.client.LSPBindings;
@@ -62,7 +64,7 @@ public class CodeActions implements CodeGenerator.Factory {
}
String uri = Utils.toURI(file);
try {
- List<? extends Command> commands =
+ List<Either<Command, CodeAction>> commands =
server.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(uri),
new Range(Utils.createPosition(component.getDocument(), component.getSelectionStart()),
Utils.createPosition(component.getDocument(), component.getSelectionEnd())),
@@ -70,16 +72,12 @@ public class CodeActions implements CodeGenerator.Factory {
return commands.stream().map(cmd -> new CodeGenerator() {
@Override
public String getDisplayName() {
- return cmd.getTitle();
+ return cmd.isLeft() ? cmd.getLeft().getTitle() : cmd.getRight().getTitle();
}
@Override
public void invoke() {
- try {
- server.getWorkspaceService().executeCommand(new ExecuteCommandParams(cmd.getCommand(), cmd.getArguments())).get();
- } catch (InterruptedException | ExecutionException ex) {
- Exceptions.printStackTrace(ex);
- }
+ Utils.applyCodeAction(server, cmd);
}
}).collect(Collectors.toList());
} catch (BadLocationException | InterruptedException | ExecutionException ex) {
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java
index 4f1cb70..3419d7e 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/HyperlinkProviderImpl.java
@@ -29,8 +29,11 @@ import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import org.eclipse.lsp4j.Location;
+import org.eclipse.lsp4j.LocationLink;
+import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextDocumentPositionParams;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.Utilities;
@@ -91,32 +94,44 @@ public class HyperlinkProviderImpl implements HyperlinkProviderExt {
params = new TextDocumentPositionParams(new TextDocumentIdentifier(uri),
Utils.createPosition(doc, offset));
//TODO: Location or Location[]
- CompletableFuture<List<? extends Location>> def = server.getTextDocumentService().definition(params);
+ CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> def = server.getTextDocumentService().definition(params);
def.handleAsync((locations, exception) -> {
if (exception != null) {
exception.printStackTrace();
}
- if (locations != null && locations.size() == 1) { //TODO: what to do when there are multiple locations?
- try {
- URI target = URI.create(locations.get(0).getUri());
- FileObject targetFile = URLMapper.findFileObject(target.toURL());
+ if (locations == null) {
+ return null;
+ }
+ String targetUri;
+ Range targetRange;
+ if (locations.isLeft() && locations.getLeft().size() == 1) { //TODO: what to do when there are multiple locations?
+ targetUri = locations.getLeft().get(0).getUri();
+ targetRange = locations.getLeft().get(0).getRange();
+ } else if (locations.isRight() && locations.getRight().size() == 1) { //TODO: what to do when there are multiple locations?
+ targetUri = locations.getRight().get(0).getTargetUri();
+ targetRange = locations.getRight().get(0).getTargetRange();
+ } else {
+ return null;
+ }
+ try {
+ URI target = URI.create(targetUri);
+ FileObject targetFile = URLMapper.findFileObject(target.toURL());
- if (targetFile != null) {
- LineCookie lc = targetFile.getLookup().lookup(LineCookie.class);
+ if (targetFile != null) {
+ LineCookie lc = targetFile.getLookup().lookup(LineCookie.class);
- //TODO: expecting lc != null!
+ //TODO: expecting lc != null!
- Line line = lc.getLineSet().getCurrent(locations.get(0).getRange().getStart().getLine());
+ Line line = lc.getLineSet().getCurrent(targetRange.getStart().getLine());
- SwingUtilities.invokeLater(() ->
- line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, locations.get(0).getRange().getStart().getCharacter())
- );
- } else {
- //TODO: beep
- }
- } catch (MalformedURLException ex) {
- Exceptions.printStackTrace(ex);
+ SwingUtilities.invokeLater(() ->
+ line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, targetRange.getStart().getCharacter())
+ );
+ } else {
+ //TODO: beep
}
+ } catch (MalformedURLException ex) {
+ Exceptions.printStackTrace(ex);
}
return null;
}).get();
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java
index fe2ebdd..bb4abce 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/LanguageClientImpl.java
@@ -40,7 +40,9 @@ import javax.swing.text.Document;
import javax.swing.text.StyledDocument;
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
import org.eclipse.lsp4j.ApplyWorkspaceEditResponse;
+import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionContext;
+import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.ConfigurationItem;
@@ -56,6 +58,7 @@ import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
import org.netbeans.modules.lsp.client.LSPBindings;
import org.netbeans.modules.lsp.client.Utils;
@@ -88,8 +91,8 @@ public class LanguageClientImpl implements LanguageClient {
public void setBindings(LSPBindings bindings) {
this.bindings = bindings;
ServerCapabilities serverCapabilities = bindings.getInitResult().getCapabilities();
- Boolean codeActions = serverCapabilities.getCodeActionProvider();
- allowCodeActions = codeActions != null && codeActions;
+ Either<Boolean, CodeActionOptions> codeActions = serverCapabilities.getCodeActionProvider();
+ allowCodeActions = codeActions != null && (!codeActions.isLeft() || codeActions.getLeft());
}
@Override
@@ -126,34 +129,7 @@ public class LanguageClientImpl implements LanguageClient {
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
- WorkspaceEdit edit = params.getEdit();
- for (Entry<String, List<TextEdit>> e : edit.getChanges().entrySet()) {
- try {
- FileObject file = URLMapper.findFileObject(new URI(e.getKey()).toURL());
- EditorCookie ec = file.getLookup().lookup(EditorCookie.class);
- Document doc = ec != null ? ec.openDocument() : null;
- if (doc == null) {
- continue;
- }
- NbDocument.runAtomic((StyledDocument) doc, () -> {
- e.getValue()
- .stream()
- .sorted((te1, te2) -> te1.getRange().getEnd().getLine() == te2.getRange().getEnd().getLine() ? te1.getRange().getEnd().getCharacter() - te2.getRange().getEnd().getCharacter() : te1.getRange().getEnd().getLine() - te2.getRange().getEnd().getLine())
- .forEach(te -> {
- try {
- int start = Utils.getOffset(doc, te.getRange().getStart());
- int end = Utils.getOffset(doc, te.getRange().getEnd());
- doc.remove(start, end - start);
- doc.insertString(start, te.getNewText(), null);
- } catch (BadLocationException ex) {
- Exceptions.printStackTrace(ex);
- }
- });
- });
- } catch (URISyntaxException | IOException ex) {
- Exceptions.printStackTrace(ex);
- }
- }
+ Utils.applyWorkspaceEditor(params.getEdit());
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
@@ -221,7 +197,7 @@ public class LanguageClientImpl implements LanguageClient {
computing = true;
bindings.runOnBackground(() -> {
try {
- List<? extends Command> commands =
+ List<Either<Command, CodeAction>> commands =
bindings.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(fileUri),
diagnostic.getRange(),
new CodeActionContext(Collections.singletonList(diagnostic)))).get();
@@ -250,25 +226,20 @@ public class LanguageClientImpl implements LanguageClient {
private class CommandBasedFix implements Fix {
- private final Command cmd;
+ private final Either<Command, CodeAction> cmd;
- public CommandBasedFix(Command cmd) {
+ public CommandBasedFix(Either<Command, CodeAction> cmd) {
this.cmd = cmd;
}
@Override
public String getText() {
- return cmd.getTitle();
+ return cmd.isLeft() ? cmd.getLeft().getTitle() : cmd.getRight().getTitle();
}
@Override
public ChangeInfo implement() throws Exception {
- try {
- bindings.getWorkspaceService().executeCommand(new ExecuteCommandParams(cmd.getCommand(), cmd.getArguments())).get();
- } catch (InterruptedException | ExecutionException ex) {
- Exceptions.printStackTrace(ex);
- }
-
+ Utils.applyCodeAction(bindings, cmd);
return null;
}
}
diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java
index def4911..56c01b9 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/NavigatorPanelImpl.java
@@ -27,9 +27,11 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.JComponent;
import javax.swing.JPanel;
+import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentIdentifier;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.modules.lsp.client.LSPBindings;
import org.netbeans.modules.lsp.client.LSPBindings.BackgroundTask;
import org.netbeans.modules.lsp.client.Utils;
@@ -52,7 +54,7 @@ import org.openide.util.lookup.ServiceProvider;
*
* @author lahvac
*/
-public class NavigatorPanelImpl extends Children.Keys<SymbolInformation> implements NavigatorPanel, BackgroundTask, LookupListener {
+public class NavigatorPanelImpl extends Children.Keys<Either<SymbolInformation, DocumentSymbol>> implements NavigatorPanel, BackgroundTask, LookupListener {
private static final NavigatorPanelImpl INSTANCE = new NavigatorPanelImpl();
@@ -137,7 +139,7 @@ public class NavigatorPanelImpl extends Children.Keys<SymbolInformation> impleme
if (file.equals(this.file)) {
try {
String uri = Utils.toURI(file);
- List<? extends SymbolInformation> symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(uri))).get();
+ List<Either<SymbolInformation, DocumentSymbol>> symbols = bindings.getTextDocumentService().documentSymbol(new DocumentSymbolParams(new TextDocumentIdentifier(uri))).get();
setKeys(symbols);
} catch (InterruptedException | ExecutionException ex) {
@@ -149,11 +151,8 @@ public class NavigatorPanelImpl extends Children.Keys<SymbolInformation> impleme
}
@Override
- protected Node[] createNodes(SymbolInformation sym) {
- AbstractNode n = new AbstractNode(LEAF);
- n.setDisplayName(sym.getName());
- n.setIconBaseWithExtension(Icons.getSymbolIconBase(sym.getKind()));
- return new Node[] {n};
+ protected Node[] createNodes(Either<SymbolInformation, DocumentSymbol> sym) {
+ return new Node[] {new NodeImpl(sym)};
}
@Override
@@ -161,6 +160,59 @@ public class NavigatorPanelImpl extends Children.Keys<SymbolInformation> impleme
updateFile();
}
+ private static final class NodeImpl extends AbstractNode {
+
+ private static Children createChildren(Either<SymbolInformation, DocumentSymbol> sym) {
+ if (sym.isLeft()) {
+ return LEAF;
+ }
+ return createChildren(sym.getRight());
+ }
+
+ private static Children createChildren(DocumentSymbol sym) {
+ if (sym.getChildren().isEmpty()) {
+ return LEAF;
+ }
+ return new Keys<DocumentSymbol>() {
+ @Override
+ protected void addNotify() {
+ setKeys(sym.getChildren());
+ }
+
+ @Override
+ protected Node[] createNodes(DocumentSymbol sym) {
+ return new Node[] {
+ new NodeImpl(sym)
+ };
+ }
+
+ @Override
+ protected void removeNotify() {
+ setKeys(Collections.emptyList());
+ }
+
+ };
+ }
+
+ public NodeImpl(Either<SymbolInformation, DocumentSymbol> symbol) {
+ super(createChildren(symbol));
+ if (symbol.isLeft()) {
+ setDisplayName(symbol.getLeft().getName());
+ setIconBaseWithExtension(Icons.getSymbolIconBase(symbol.getLeft().getKind()));
+ } else {
+ setDisplayName(symbol.getRight().getName());
+ setIconBaseWithExtension(Icons.getSymbolIconBase(symbol.getRight().getKind()));
+ }
+ }
+
+ public NodeImpl(DocumentSymbol symbol) {
+ super(createChildren(symbol));
+ setDisplayName(symbol.getName());
+ setIconBaseWithExtension(Icons.getSymbolIconBase(symbol.getKind()));
+ }
+
+ }
+
@ServiceProvider(service=DynamicRegistration.class)
public static final class DynamicRegistrationImpl implements DynamicRegistration {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists