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:
@@ -10,16 +10,15 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
* Composite project manager that acts a single project manager but consissts of many project managers
|
||||
@@ -48,7 +47,8 @@ public class CompositeJavaProjectFinder implements JavaProjectFinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavaProject find(TextDocumentIdentifier doc) {
|
||||
public Optional<IJavaProject> find(TextDocumentIdentifier doc) {
|
||||
return projectFinders.stream().map(finder -> finder.find(doc)).filter(Objects::nonNull).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
@@ -31,7 +32,7 @@ import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
public abstract class FileBasedJavaProjectFinder implements JavaProjectFinder {
|
||||
|
||||
@Override
|
||||
public final IJavaProject find(TextDocumentIdentifier doc) {
|
||||
public final Optional<IJavaProject> find(TextDocumentIdentifier doc) {
|
||||
try {
|
||||
String uriStr = doc.getUri();
|
||||
if (StringUtil.hasText(uriStr)) {
|
||||
@@ -45,9 +46,9 @@ public abstract class FileBasedJavaProjectFinder implements JavaProjectFinder {
|
||||
catch (URISyntaxException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
protected abstract IJavaProject find(File file);
|
||||
protected abstract Optional<IJavaProject> find(File file);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
* Java project finder provides a means to obtain the project context associated with
|
||||
@@ -25,6 +25,15 @@ import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
*/
|
||||
public interface JavaProjectFinder {
|
||||
|
||||
IJavaProject find(TextDocumentIdentifier doc);
|
||||
Optional<IJavaProject> find(TextDocumentIdentifier doc);
|
||||
|
||||
default JavaProjectFinder filter(Predicate<IJavaProject> acceptWhen) {
|
||||
return doc -> this.find(doc).flatMap(jp -> {
|
||||
if (acceptWhen.test(jp)) {
|
||||
return Optional.of(jp);
|
||||
}
|
||||
return Optional.empty();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user