This is an automated email from the ASF dual-hosted git repository. skygo 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 fe18ae4 Improving LSP client: ability to share language servers across different mime-types; improving span of hyperlinks based on TextMate grammars, if available. new 6d25b27 Merge pull request #2052 from jlahoda/improve-lsp-client-march-2020 fe18ae4 is described below commit fe18ae4b99bceb566749df3a72e7fd312b4f45c3 Author: Jan Lahoda <jlah...@netbeans.org> AuthorDate: Sun Mar 29 22:23:40 2020 +0200 Improving LSP client: ability to share language servers across different mime-types; improving span of hyperlinks based on TextMate grammars, if available. --- .../org/netbeans/modules/lsp/client/LSPBindings.java | 9 +++++++-- .../lsp/client/LanguageServerProviderAccessor.java | 2 ++ .../lsp/client/bindings/HyperlinkProviderImpl.java | 17 ++++++++++++++++- .../modules/lsp/client/spi/LanguageServerProvider.java | 12 ++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) 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 c45b117..f641477 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 @@ -120,7 +120,7 @@ public class LSPBindings { if (p != null) { LSPBindings b = project2MimeType2Server.getOrDefault(p, Collections.emptyMap()).remove(mimeType); - if (b != null) { + if (b != null && b.process != null) { b.process.destroy(); } } @@ -131,6 +131,10 @@ public class LSPBindings { LanguageServerDescription desc = provider.startServer(Lookups.fixed(prj, mimeTypeInfo, restarter)); if (desc != null) { + LSPBindings b = LanguageServerProviderAccessor.getINSTANCE().getBindings(desc); + if (b != null) { + return b; + } try { LanguageClientImpl lci = new LanguageClientImpl(); InputStream in = LanguageServerProviderAccessor.getINSTANCE().getInputStream(desc); @@ -140,8 +144,9 @@ public class LSPBindings { launcher.startListening(); LanguageServer server = launcher.getRemoteProxy(); InitializeResult result = initServer(p, server, prj.getProjectDirectory()); //XXX: what if a different root is expected???? - LSPBindings b = new LSPBindings(server, result, LanguageServerProviderAccessor.getINSTANCE().getProcess(desc)); + b = new LSPBindings(server, result, LanguageServerProviderAccessor.getINSTANCE().getProcess(desc)); lci.setBindings(b); + LanguageServerProviderAccessor.getINSTANCE().setBindings(desc, b); return b; } catch (InterruptedException | ExecutionException ex) { LOG.log(Level.WARNING, null, ex); diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java index 42d7234..e62d4e6 100644 --- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/LanguageServerProviderAccessor.java @@ -51,4 +51,6 @@ public abstract class LanguageServerProviderAccessor { public abstract InputStream getInputStream(LanguageServerDescription desc); public abstract OutputStream getOutputStream(LanguageServerDescription desc); public abstract Process getProcess(LanguageServerDescription desc); + public abstract LSPBindings getBindings(LanguageServerDescription desc); + public abstract void setBindings(LanguageServerDescription desc, LSPBindings bindings); } 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 c652743..34c7dfa 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 @@ -35,6 +35,9 @@ 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.api.lexer.Language; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.lib.editor.hyperlink.spi.HyperlinkProviderExt; @@ -42,6 +45,8 @@ import org.netbeans.lib.editor.hyperlink.spi.HyperlinkType; import org.netbeans.modules.editor.NbEditorUtilities; import org.netbeans.modules.lsp.client.LSPBindings; import org.netbeans.modules.lsp.client.Utils; +import org.netbeans.modules.textmate.lexer.TextmateTokenId; +import org.netbeans.spi.lexer.LanguageHierarchy; import org.openide.cookies.LineCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; @@ -76,7 +81,17 @@ public class HyperlinkProviderImpl implements HyperlinkProviderExt { try { //XXX: not really using the server, are we? - return Utilities.getIdentifierBlock((BaseDocument) doc, offset); + int[] ident = Utilities.getIdentifierBlock((BaseDocument) doc, offset); + TokenSequence<?> ts = TokenHierarchy.get(doc).tokenSequence(); + ts.move(offset); + if (ts.moveNext() && ts.token().id() == TextmateTokenId.TEXTMATE) { + if (ident != null) { + return new int[] {ts.offset(), ts.offset() + ts.token().length()}; + } else { + return null; + } + } + return ident; } catch (BadLocationException ex) { return null; } diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java index 5282617..6ad31d2 100644 --- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java +++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/spi/LanguageServerProvider.java @@ -23,6 +23,7 @@ import java.io.OutputStream; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.modules.lsp.client.LSPBindings; import org.netbeans.modules.lsp.client.LanguageServerProviderAccessor; import org.openide.util.Lookup; @@ -62,6 +63,7 @@ public interface LanguageServerProvider { private final InputStream in; private final OutputStream out; private final Process process; + private LSPBindings bindings; private LanguageServerDescription(InputStream in, OutputStream out, Process process) { this.in = in; @@ -85,6 +87,16 @@ public interface LanguageServerProvider { public Process getProcess(LanguageServerDescription desc) { return desc.process; } + + @Override + public LSPBindings getBindings(LanguageServerDescription desc) { + return desc.bindings; + } + + @Override + public void setBindings(LanguageServerDescription desc, LSPBindings bindings) { + desc.bindings = bindings; + } }); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists