Disable boot-java language server internally on non-boot project
Also use Optional in project finder to avoid some NPE bugs for missing project context.
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 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;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
|
||||
import org.springframework.ide.vscode.boot.java.utils.BootProjectUtil;
|
||||
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.commons.gradle.GradleCore;
|
||||
@@ -52,7 +63,7 @@ public class BootJavaLanguageServerParams {
|
||||
CompositeProjectOvserver projectObserver = new CompositeProjectOvserver(Arrays.asList(mavenProjectCache, gradleProjectCache));
|
||||
|
||||
return new BootJavaLanguageServerParams(
|
||||
javaProjectFinder,
|
||||
javaProjectFinder.filter(BootProjectUtil::isBootProject),
|
||||
projectObserver,
|
||||
new DefaultSpringPropertyIndexProvider(javaProjectFinder),
|
||||
RunningAppProvider.DEFAULT
|
||||
|
||||
@@ -109,7 +109,7 @@ public class BootJavaCompletionEngine implements ICompletionEngine {
|
||||
}
|
||||
|
||||
private String[] getClasspathEntries(IDocument doc) throws Exception {
|
||||
IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri()));
|
||||
IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri())).get();
|
||||
IClasspath classpath = project.getClasspath();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntries();
|
||||
return classpathEntries
|
||||
|
||||
@@ -213,7 +213,7 @@ public class BootJavaHoverProvider implements HoverHandler {
|
||||
}
|
||||
|
||||
private IJavaProject getProject(IDocument doc) throws Exception {
|
||||
return this.projectFinder.find(new TextDocumentIdentifier(doc.getUri()));
|
||||
return this.projectFinder.find(new TextDocumentIdentifier(doc.getUri())).get();
|
||||
}
|
||||
|
||||
private String[] getClasspathEntries(IJavaProject project) throws Exception {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class BootJavaReferencesHandler implements ReferencesHandler {
|
||||
}
|
||||
|
||||
private String[] getClasspathEntries(IDocument doc) throws Exception {
|
||||
IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri()));
|
||||
IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri())).get();
|
||||
IClasspath classpath = project.getClasspath();
|
||||
Stream<Path> classpathEntries = classpath.getClasspathEntries();
|
||||
return classpathEntries
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -186,9 +187,9 @@ public class SpringIndexer {
|
||||
try {
|
||||
initializeTask.get();
|
||||
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
if (project != null) {
|
||||
String[] classpathEntries = getClasspathEntries(project);
|
||||
Optional<IJavaProject> maybeProject = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
if (maybeProject.isPresent()) {
|
||||
String[] classpathEntries = getClasspathEntries(maybeProject.get());
|
||||
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
UpdateItem updateItem = new UpdateItem(docURI, content, classpathEntries, future);
|
||||
@@ -265,7 +266,7 @@ public class SpringIndexer {
|
||||
try {
|
||||
System.out.println("scan directory...");
|
||||
|
||||
Map<IJavaProject, List<String>> projects = Files.walk(directory.toPath())
|
||||
Map<Optional<IJavaProject>, List<String>> projects = Files.walk(directory.toPath())
|
||||
.filter(path -> path.getFileName().toString().endsWith(".java"))
|
||||
.filter(Files::isRegularFile)
|
||||
.map(path -> path.toAbsolutePath().toString())
|
||||
@@ -273,7 +274,7 @@ public class SpringIndexer {
|
||||
|
||||
System.out.println("scan directory done!!!");
|
||||
|
||||
projects.forEach((project, files) -> scanProject(project, files.toArray(new String[0])));
|
||||
projects.forEach((maybeProject, files) -> maybeProject.ifPresent(project -> scanProject(project, files.toArray(new String[0]))));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
package org.springframework.ide.vscode.boot.metadata;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
@@ -35,9 +37,9 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
|
||||
|
||||
@Override
|
||||
public FuzzyMap<ConfigurationMetadataProperty> getIndex(IDocument doc) {
|
||||
IJavaProject jp = javaProjectFinder.find(new TextDocumentIdentifier(doc.getUri()));
|
||||
if (jp != null) {
|
||||
return indexManager.get(jp, progressService);
|
||||
Optional<IJavaProject> jp = javaProjectFinder.find(new TextDocumentIdentifier(doc.getUri()));
|
||||
if (jp.isPresent()) {
|
||||
return indexManager.get(jp.get(), progressService);
|
||||
}
|
||||
return EMPTY_INDEX;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -41,20 +40,16 @@ import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServer;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.AutowiredHoverProvider;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.SpringBootAppProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.CompositeJavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.ide.vscode.project.harness.PropertyIndexHarness;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -77,7 +72,7 @@ public class AutowiredHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutowiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
@@ -103,7 +98,7 @@ public class AutowiredHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutowiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
@@ -122,7 +117,7 @@ public class AutowiredHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutowiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
@@ -143,7 +138,7 @@ public class AutowiredHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutowiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ComponentHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutomaticallyWiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ComponentHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutowiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class ComponentHoverProviderTest {
|
||||
|
||||
String docURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/MyAutomaticallyWiredComponent.java";
|
||||
TextDocument document = createTempTextDocument(docURI);
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI));
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(docURI)).get();
|
||||
|
||||
CompilationUnit cu = parse(document, project);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
@@ -52,7 +53,7 @@ public class ValueCompletionTest {
|
||||
testProject = ProjectsHarness.INSTANCE.mavenProject("test-annotations");
|
||||
harness = BootLanguageServerHarness.builder()
|
||||
.mockDefaults()
|
||||
.projectFinder(d -> getTestProject())
|
||||
.projectFinder(d -> Optional.ofNullable(getTestProject()))
|
||||
.build();
|
||||
indexHarness = harness.getPropertyIndexHarness();
|
||||
harness.intialize(null);
|
||||
|
||||
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.project.harness;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
import org.springframework.boot.configurationmetadata.Deprecation;
|
||||
@@ -563,7 +564,7 @@ public class PropertyIndexHarness {
|
||||
}
|
||||
|
||||
public JavaProjectFinder getProjectFinder() {
|
||||
return (doc) -> testProject;
|
||||
return (doc) -> Optional.ofNullable(testProject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user