Outline with JDT LS LightWeight mode
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 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
|
||||
@@ -36,4 +36,9 @@ public class CompositeProjectOvserver implements ProjectObserver {
|
||||
observers.forEach(o -> o.removeListener(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return observers.stream().map(o -> o.isSupported()).reduce(false, (a, b) -> a || b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,14 @@ public class FutureProjectFinder implements DisposableBean {
|
||||
@Override
|
||||
public void changed(IJavaProject project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void supported() {
|
||||
if (!projectObserver.isSupported()) {
|
||||
resolveAllPendingRquests();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -52,6 +60,14 @@ public class FutureProjectFinder implements DisposableBean {
|
||||
this.projectObserver.addListener(LISTENER);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private void resolveAllPendingRquests() {
|
||||
for (Map.Entry<URI, CompletableFuture<IJavaProject>> e : pendingFindProjectRequests.entrySet()) {
|
||||
Optional<IJavaProject> jp = projectFinder.find(new TextDocumentIdentifier(e.getKey().toString()));
|
||||
e.getValue().complete(jp.orElse(null));
|
||||
pendingFindProjectRequests.remove(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private void resolvePendingRequests(IJavaProject project) {
|
||||
for (Map.Entry<URI, CompletableFuture<IJavaProject>> e : pendingFindProjectRequests.entrySet()) {
|
||||
@@ -79,12 +95,16 @@ public class FutureProjectFinder implements DisposableBean {
|
||||
if (projectObserver == null) {
|
||||
throw new IllegalStateException("Future project lookup not supported without ProjectObserver bean present");
|
||||
}
|
||||
CompletableFuture<IJavaProject> cf = pendingFindProjectRequests.get(uri);
|
||||
if (cf == null) {
|
||||
cf = new CompletableFuture<IJavaProject>();
|
||||
pendingFindProjectRequests.put(uri, cf);
|
||||
if (projectObserver.isSupported()) {
|
||||
CompletableFuture<IJavaProject> cf = pendingFindProjectRequests.get(uri);
|
||||
if (cf == null) {
|
||||
cf = new CompletableFuture<IJavaProject>();
|
||||
pendingFindProjectRequests.put(uri, cf);
|
||||
}
|
||||
return cf;
|
||||
} else {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return cf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 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
|
||||
@@ -26,7 +26,9 @@ public interface ProjectObserver {
|
||||
void created(IJavaProject project);
|
||||
void changed(IJavaProject project);
|
||||
void deleted(IJavaProject project);
|
||||
default void supported() { }
|
||||
}
|
||||
default boolean isSupported() { return true; };
|
||||
void addListener(Listener listener);
|
||||
void removeListener(Listener listener);
|
||||
|
||||
@@ -38,6 +40,11 @@ public interface ProjectObserver {
|
||||
@Override
|
||||
public void removeListener(Listener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2021 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
|
||||
@@ -546,7 +546,8 @@ public class SpringSymbolIndex implements InitializingBean {
|
||||
|
||||
public List<? extends SymbolInformation> getSymbols(String docURI) {
|
||||
try {
|
||||
CompletableFuture<Void> projectInitialized = futureProjectFinder.findFuture(URI.create(docURI)).thenCompose(project -> projectInitializedFuture(project));
|
||||
URI uri = URI.create(docURI);
|
||||
CompletableFuture<Void> projectInitialized = futureProjectFinder.findFuture(uri).thenCompose(project -> projectInitializedFuture(project));
|
||||
projectInitialized.get(60, TimeUnit.SECONDS);
|
||||
List<EnhancedSymbolInformation> docSymbols = this.symbolsByDoc.get(docURI);
|
||||
if (docSymbols != null) {
|
||||
|
||||
@@ -37,14 +37,11 @@ import org.springframework.ide.vscode.commons.javadoc.JdtLsJavadocProvider;
|
||||
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.protocol.java.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.UriUtil;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
|
||||
@@ -57,6 +54,8 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
private Map<String, IJavaProject> table = new HashMap<String, IJavaProject>();
|
||||
private Logger log = LoggerFactory.getLogger(JdtLsProjectCache.class);
|
||||
private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
private boolean projectWatchingSupported = true;
|
||||
|
||||
public JdtLsProjectCache(SimpleLanguageServer server, boolean isJandexIndex) {
|
||||
this.server = server;
|
||||
@@ -70,6 +69,7 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
})
|
||||
.doOnError(error -> {
|
||||
log.error("JDT-based JavaProject service not available!", error);
|
||||
switchOffProjectObserver();
|
||||
})
|
||||
.toFuture();
|
||||
}
|
||||
@@ -78,14 +78,6 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
return server.getWorkspaceService().getFileObserver();
|
||||
}
|
||||
|
||||
private boolean isOldJdt(Throwable e) {
|
||||
return ExceptionUtil.getMessage(e).contains("'sts.java.addClasspathListener' not supported");
|
||||
}
|
||||
|
||||
private boolean isNoJdtError(Throwable e) {
|
||||
return ExceptionUtil.getMessage(e).contains("command 'java.execute.workspaceCommand' not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener) {
|
||||
synchronized (listeners) {
|
||||
@@ -139,6 +131,15 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyProjectObserverSupported() {
|
||||
log.info("Project Observer is " + (projectWatchingSupported ? "" : "not ") + "supported");
|
||||
synchronized (listeners) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.supported();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logEvent(String type, IJavaProject project) {
|
||||
try {
|
||||
@@ -274,12 +275,24 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
.doOnSubscribe(x -> log.info("addClasspathListener ..."))
|
||||
.doOnSuccess(x -> log.info("addClasspathListener DONE"))
|
||||
.doOnError(t -> {
|
||||
log.error("Unexpected error registering classpath listener with JDT. Fallback classpath provider will be used instead.", t);
|
||||
log.error("Unexpected error registering classpath listener with JDT.", t);
|
||||
switchOffProjectObserver();
|
||||
}));
|
||||
}
|
||||
|
||||
private void switchOffProjectObserver() {
|
||||
projectWatchingSupported = false;
|
||||
notifyProjectObserverSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends IJavaProject> all() {
|
||||
return table.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return projectWatchingSupported;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
import * as VSCode from 'vscode';
|
||||
import { RequestType } from 'vscode-languageclient';
|
||||
import { LanguageClient } from 'vscode-languageclient/node';
|
||||
import { workspace } from 'vscode';
|
||||
|
||||
export function registerClasspathService(client : LanguageClient) : void {
|
||||
|
||||
let addRequest = new RequestType<ClasspathListenerParams, ClasspathListenerResponse, void>("sts/addClasspathListener");
|
||||
client.onRequest(addRequest, async (params: ClasspathListenerParams) => {
|
||||
const jdtConfig = workspace.getConfiguration('java')
|
||||
const launchMode = jdtConfig?.get('server.launchMode');
|
||||
if (launchMode === 'LightWeight') {
|
||||
throw new Error('Classpath listener not supported while Java Language Server is in LightWeight mode');
|
||||
}
|
||||
return <ClasspathListenerResponse> await VSCode.commands.executeCommand("java.execute.workspaceCommand", "sts.java.addClasspathListener", params.callbackCommandId);
|
||||
});
|
||||
|
||||
|
||||
@@ -15,4 +15,5 @@ src/test/resources/test-projects/**/.classpath
|
||||
src/test/resources/test-projects/**/.project
|
||||
src/test/resources/test-projects/**/.factorypath
|
||||
src/test/resources/test-projects/**/.settings/**
|
||||
src/test/resources/test-projects/**/bin/**
|
||||
src/test/resources/test-projects/**/bin/**
|
||||
/package-lock.json
|
||||
|
||||
1757
vscode-extensions/vscode-spring-boot/package-lock.json
generated
1757
vscode-extensions/vscode-spring-boot/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user