Skip to content

Commit

Permalink
Avoid libs.lsp, avoid using lsp4j in SPI, adding test for navigator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahoda committed Sep 11, 2018
1 parent 345cd76 commit 4ba531e
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 174 deletions.
25 changes: 0 additions & 25 deletions ide/libs.lsp/build.xml

This file was deleted.

6 changes: 0 additions & 6 deletions ide/libs.lsp/manifest.mf

This file was deleted.

25 changes: 0 additions & 25 deletions ide/libs.lsp/nbproject/project.properties

This file was deleted.

80 changes: 0 additions & 80 deletions ide/libs.lsp/nbproject/project.xml

This file was deleted.

18 changes: 0 additions & 18 deletions ide/libs.lsp/src/org/netbeans/modules/libs/lsp/Bundle.properties

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions ide/lsp.client/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@

javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial
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.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
57 changes: 49 additions & 8 deletions ide/lsp.client/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.netbeans.modules.lsp.client</code-name-base>
<module-dependencies>
<dependency>
<code-name-base>com.google.gson</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>2.7</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.google.guava</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>15.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.annotations.common</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.30</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.progress</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -87,14 +112,6 @@
<specification-version>1.43</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.libs.lsp</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -207,6 +224,30 @@
<friend>org.netbeans.modules.kotlin.support</friend>
<package>org.netbeans.modules.lsp.client.spi</package>
</friend-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>
</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>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/org.eclipse.xtend.lib-2.14.0.jar</runtime-relative-path>
<binary-origin>external/org.eclipse.xtend.lib-2.14.0.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/org.eclipse.xtext.xbase.lib-2.14.0.jar</runtime-relative-path>
<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>
</class-path-extension>
</data>
</configuration>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.netbeans.api.project.Project;
import org.netbeans.modules.lsp.client.bindings.LanguageClientImpl;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider.LanguageServerDescription;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
Expand Down Expand Up @@ -90,12 +91,17 @@ public static LSPBindings getBindings(FileObject file) {
LSPBindings bindings =
project2MimeType2Server.computeIfAbsent(prj, p -> new HashMap<>())
.computeIfAbsent(mimeType, mt -> {
LanguageClientImpl lci = new LanguageClientImpl();
for (LanguageServerProvider provider : MimeLookup.getLookup(mimeType).lookupAll(LanguageServerProvider.class)) {
LanguageServer server = provider.startServer(prj, lci);
LanguageServerDescription desc = provider.startServer(prj);

if (server != null) {
if (desc != null) {
try {
LanguageClientImpl lci = new LanguageClientImpl();
InputStream in = LanguageServerProviderAccessor.getINSTANCE().getInputStream(desc);
OutputStream out = LanguageServerProviderAccessor.getINSTANCE().getOutputStream(desc);
Launcher<LanguageServer> launcher = LSPLauncher.createClientLauncher(lci, in, out);
launcher.startListening();
LanguageServer server = launcher.getRemoteProxy();
InitializeParams initParams = new InitializeParams();
initParams.setRootUri(prj.getProjectDirectory().toURI().toString()); //XXX: what if a different root is expected????
initParams.setRootPath(FileUtil.toFile(prj.getProjectDirectory()).getAbsolutePath()); //some servers still expect root path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.lsp.client;

import java.io.InputStream;
import java.io.OutputStream;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider.LanguageServerDescription;
import org.openide.util.Exceptions;

/**
*
* @author lahvac
*/
public abstract class LanguageServerProviderAccessor {

public static synchronized LanguageServerProviderAccessor getINSTANCE () {
if (INSTANCE == null) {
try {
Class.forName(LanguageServerDescription.class.getName(), true, LanguageServerDescription.class.getClassLoader()); //NOI18N
assert INSTANCE != null;
} catch (ClassNotFoundException e) {
Exceptions.printStackTrace(e);
}
}
return INSTANCE;
}

public static void setINSTANCE (LanguageServerProviderAccessor instance) {
assert instance != null;
INSTANCE = instance;
}

private static volatile LanguageServerProviderAccessor INSTANCE;

public abstract InputStream getInputStream(LanguageServerDescription desc);
public abstract OutputStream getOutputStream(LanguageServerDescription desc);
public abstract Process getProcess(LanguageServerDescription desc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.netbeans.modules.lsp.client.bindings;

import java.awt.BorderLayout;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -34,6 +36,7 @@
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.view.BeanTreeView;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
Expand Down Expand Up @@ -160,8 +163,18 @@ public void resultChanged(LookupEvent arg0) {
public static final class DynamicRegistrationImpl implements DynamicRegistration {

@Override
public Collection<? extends NavigatorPanel> panelsFor(FileObject file) {
return LSPBindings.getBindings(file) != null ? Collections.singletonList(INSTANCE) : Collections.emptyList();
public Collection<? extends NavigatorPanel> panelsFor(URI uri) {
try {
FileObject file = URLMapper.findFileObject(uri.toURL());
if (file != null) {
return LSPBindings.getBindings(file) != null ? Collections.singletonList(INSTANCE) : Collections.emptyList();
} else {
return Collections.emptyList();
}
} catch (MalformedURLException ex) {
//ignore
return Collections.emptyList();
}
}

}
Expand Down
Loading

0 comments on commit 4ba531e

Please sign in to comment.