PT #162167333: Ask JDT server for hover links (Eclipse, VSCode)
This commit is contained in:
@@ -32,7 +32,6 @@ import org.springframework.ide.vscode.boot.metadata.ClassReferenceProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.LoggerNameProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.ProjectBasedPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.PropertyInfo;
|
||||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
|
||||
import org.springframework.ide.vscode.boot.yaml.completions.ApplicationYamlAssistContext;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DocumentEventListenerManager;
|
||||
@@ -94,8 +93,8 @@ public class BootLanguagServerBootApp {
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
|
||||
@Bean SourceLinks sourceLinks(CompilationUnitCache cuCache) {
|
||||
return SourceLinkFactory.createSourceLinks(cuCache);
|
||||
@Bean SourceLinks sourceLinks(SimpleLanguageServer server, CompilationUnitCache cuCache) {
|
||||
return SourceLinkFactory.createSourceLinks(server, cuCache);
|
||||
}
|
||||
|
||||
@Bean CompilationUnitCache cuCache(BootLanguageServerParams params, SimpleTextDocumentService documents) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.ide.vscode.commons.languageserver.java.CompositeProje
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
import org.springframework.ide.vscode.commons.maven.java.MavenProjectCache;
|
||||
|
||||
@@ -222,6 +222,10 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
server.onShutdown(this::shutdown);
|
||||
}
|
||||
|
||||
public SimpleLanguageServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICompletionEngine getCompletionEngine() {
|
||||
return createCompletionEngine(projectFinder, propertyIndexProvider, adHocPropertyIndexProvider);
|
||||
|
||||
@@ -18,8 +18,8 @@ import java.util.Set;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.util.CollectorUtil;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.links;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.JavaDataParams;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
|
||||
public class JavaServerSourceLinks implements SourceLinks {
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
|
||||
public JavaServerSourceLinks(SimpleLanguageServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkUrlForFQName(IJavaProject project, String fqName) {
|
||||
StringBuilder bindingKey = new StringBuilder();
|
||||
bindingKey.append('L');
|
||||
bindingKey.append(fqName.replace('.', '/'));
|
||||
bindingKey.append(';');
|
||||
CompletableFuture<Optional<String>> link = server.getClient().javadocHoverLink(new JavaDataParams(project.getLocationUri().toString(), bindingKey.toString()))
|
||||
.thenApply(response -> Optional.ofNullable(response.getLink()));
|
||||
try {
|
||||
return link.get(10, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkUrlForClasspathResource(IJavaProject project, String path) {
|
||||
int idx = path.lastIndexOf(CLASS);
|
||||
if (idx >= 0) {
|
||||
Path p = Paths.get(path.substring(0, idx));
|
||||
return sourceLinkUrlForFQName(project, p.toString().replace(File.separator, "."));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> sourceLinkForResourcePath(Path path) {
|
||||
return Optional.ofNullable(path).map(p -> p.toUri().toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents
|
||||
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LspClient;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
|
||||
/**
|
||||
* Factory for creating {@link SourceLinks}
|
||||
@@ -50,13 +51,14 @@ public final class SourceLinkFactory {
|
||||
* @param server the boot LS
|
||||
* @return appropriate source links object
|
||||
*/
|
||||
public static SourceLinks createSourceLinks(CompilationUnitCache cuCache) {
|
||||
public static SourceLinks createSourceLinks(SimpleLanguageServer server, CompilationUnitCache cuCache) {
|
||||
switch (LspClient.currentClient()) {
|
||||
case VSCODE:
|
||||
return /*new VSCodeSourceLinks(cuCache);*/new JavaServerSourceLinks(server);
|
||||
case THEIA:
|
||||
return new VSCodeSourceLinks(cuCache);
|
||||
case ECLIPSE:
|
||||
return new EclipseSourceLinks();
|
||||
return /*new EclipseSourceLinks();*/new JavaServerSourceLinks(server);
|
||||
case ATOM:
|
||||
return new AtomSourceLinks(cuCache);
|
||||
default:
|
||||
@@ -68,7 +70,7 @@ public final class SourceLinkFactory {
|
||||
@Deprecated
|
||||
public static SourceLinks createSourceLinks(BootJavaLanguageServerComponents server) {
|
||||
return server == null
|
||||
? createSourceLinks((CompilationUnitCache)null)
|
||||
: createSourceLinks(server.getCompilationUnitCache());
|
||||
? createSourceLinks(null, (CompilationUnitCache)null)
|
||||
: createSourceLinks(server.getServer(), server.getCompilationUnitCache());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.JavaProject;
|
||||
import org.springframework.ide.vscode.commons.javadoc.JdtLsJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListener;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.ClasspathListener;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
@@ -34,8 +34,8 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.IOUtil;
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
|
||||
Reference in New Issue
Block a user