show 'progress' message while building index.

This commit is contained in:
Kris De Volder
2016-12-08 09:45:25 -08:00
parent c2cf531956
commit 5e98569cc7
6 changed files with 68 additions and 21 deletions

View File

@@ -33,6 +33,7 @@ export function activate(options : ActivatorOptions, context: VSCode.ExtensionCo
var log_output = VSCode.window.createOutputChannel(options.extensionId+"-debug-log");
log("Activating '"+options.extensionId+"' extension");
window.showInformationMessage("Activating spring-boot extension!");
function log(msg : string) {
if (log_output) {
@@ -106,7 +107,6 @@ export function activate(options : ActivatorOptions, context: VSCode.ExtensionCo
);
let progressService = new ProgressService();
client.onNotification({method: "sts/progress"}, (params : ProgressParams) => {
log("progress: "+JSON.stringify(params));
progressService.handle(params);
});
let disposable = client.start();

View File

@@ -2,6 +2,7 @@ package org.springframework.ide.vscode.application.properties.metadata;
import org.springframework.ide.vscode.application.properties.metadata.util.FuzzyMap;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
@@ -10,17 +11,34 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
private JavaProjectFinder javaProjectFinder;
private SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(ValueProviderRegistry.getDefault());
private ProgressService progressService = (id, msg) -> { /*ignore*/ };
private static int progressIdCt = 0;
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder) {
this.javaProjectFinder = javaProjectFinder;
}
@Override
public FuzzyMap<PropertyInfo> getIndex(IDocument doc) {
IJavaProject jp = javaProjectFinder.find(doc);
if (jp!=null) {
return indexManager.get(jp);
String progressId = getProgressId();
progressService.progressEvent(progressId, "Indexing Spring Boot Properties...");
try {
IJavaProject jp = javaProjectFinder.find(doc);
if (jp!=null) {
return indexManager.get(jp);
}
} finally {
progressService.progressEvent(progressId, null);
}
return null;
}
private static synchronized String getProgressId() {
return DefaultSpringPropertyIndexProvider.class.getName()+ (progressIdCt++);
}
public void setProgressService(ProgressService progressService) {
this.progressService = progressService;
}
}

View File

@@ -4,7 +4,11 @@ import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;
public interface IJavaProject extends IJavaElement {
/**
* TypeFilter is deprecated. Should use java.util.funcion.Predicate<IType> instead.
*/
@Deprecated
@FunctionalInterface
public static interface TypeFilter {
boolean accept(IType type);

View File

@@ -0,0 +1,24 @@
package org.springframework.ide.vscode.commons.languageserver;
@FunctionalInterface
public interface ProgressService {
/**
* Sends a progress event to the LSP client. A taskId is an arbirary id
* that can be chosen by the caller. The purpose of the id is to be a 'unique'
* id for some kind of 'long running job'. Only a single 'statusMsg' is associated
* with a given taskId at any one time. Each event updates the message shown
* to the user replacing the old one.
* <p>
* Updating the message to 'null' erases the previous message without showing
* a new one.
* <p>
* More than one message may be shown simultaneously to the user, if they
* have different taskId.
*
* @param taskId
* @param statusMsg
*/
void progressEvent(String taskId, String statusMsg);
}

View File

@@ -2,7 +2,6 @@ package org.springframework.ide.vscode.commons.languageserver.util;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -20,6 +19,7 @@ import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageClientAware;
import org.eclipse.lsp4j.services.LanguageServer;
import org.springframework.ide.vscode.commons.languageserver.ProgressParams;
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
import org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient;
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
@@ -27,8 +27,6 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSe
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblem;
import org.springframework.ide.vscode.commons.util.Futures;
import reactor.core.publisher.Flux;
/**
* Abstract base class to implement LanguageServer. Bits and pieces copied from
* the 'JavaLanguageServer' example which seem generally useful / reusable end up in
@@ -47,18 +45,16 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
private STS4LanguageClient client;
private ProgressService progressService = (String taskId, String statusMsg) -> {
STS4LanguageClient client = SimpleLanguageServer.this.client;
if (client!=null) {
client.progress(new ProgressParams(taskId, statusMsg));
}
};
@Override
public void connect(LanguageClient _client) {
this.client = (STS4LanguageClient) _client;
Flux.range(1, 10)
.delay(Duration.ofMillis(2000))
.doOnNext((i) -> {
client.progress(new ProgressParams("test-progress", "Progress ["+i+"] ..."));
})
.doAfterTerminate(() -> {
client.progress(new ProgressParams("test-progress", null));
})
.subscribe();
}
@Override
@@ -191,4 +187,9 @@ public abstract class SimpleLanguageServer implements LanguageServer, LanguageCl
public LanguageClient getClient() {
return client;
}
public ProgressService getProgressService() {
return progressService;
}
}

View File

@@ -12,14 +12,13 @@ package org.springframework.ide.vscode.boot;
import java.io.IOException;
import org.eclipse.lsp4j.services.LanguageServer;
import org.springframework.ide.vscode.application.properties.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.application.properties.metadata.SpringPropertyIndexProvider;
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil;
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtilProvider;
import org.springframework.ide.vscode.commons.languageserver.LaunguageServerApp;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
/**
* Starts up Language Server process
@@ -33,9 +32,10 @@ public class Main {
public static void main(String[] args) throws IOException {
LaunguageServerApp.start(() -> {
JavaProjectFinder javaProjectFinder = JavaProjectFinder.DEFAULT;
SpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder);
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder);
TypeUtilProvider typeUtilProvider = (IDocument doc) -> new TypeUtil(javaProjectFinder.find(doc));
LanguageServer server = new BootPropertiesLanguageServer(indexProvider, typeUtilProvider, javaProjectFinder);
SimpleLanguageServer server = new BootPropertiesLanguageServer(indexProvider, typeUtilProvider, javaProjectFinder);
indexProvider.setProgressService(server.getProgressService());
return server;
});
}