PT #150711096: start symbol parsing at language server startup
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.eclipse.lsp4j.InitializedParams;
|
||||
import org.springframework.ide.vscode.boot.java.beans.BeansSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.beans.ComponentSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.BootJavaCodeLensEngine;
|
||||
@@ -72,6 +73,7 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
});
|
||||
|
||||
private final VscodeCompletionEngineAdapter completionEngine;
|
||||
private final SpringIndexer indexer;
|
||||
|
||||
public BootJavaLanguageServer(JavaProjectFinder javaProjectFinder, SpringPropertyIndexProvider indexProvider) {
|
||||
super("vscode-boot-java");
|
||||
@@ -96,20 +98,25 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
ReferencesHandler referencesHandler = createReferenceHandler(this, javaProjectFinder);
|
||||
documents.onReferences(referencesHandler);
|
||||
|
||||
SpringIndexer indexer = createAnnotationIndexer(this, javaProjectFinder);
|
||||
indexer = createAnnotationIndexer(this, javaProjectFinder);
|
||||
documents.onDocumentSymbol(new BootJavaDocumentSymbolHandler(indexer));
|
||||
workspaceService.onWorkspaceSymbol(new BootJavaWorkspaceSymbolHandler(indexer));
|
||||
|
||||
BootJavaCodeLensEngine codeLensHandler = createCodeLensEngine(this, javaProjectFinder);
|
||||
documents.onCodeLens(codeLensHandler::createCodeLenses);
|
||||
documents.onCodeLensResolve(codeLensHandler::resolveCodeLens);
|
||||
|
||||
}
|
||||
|
||||
public void setMaxCompletionsNumber(int number) {
|
||||
completionEngine.setMaxCompletions(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialized(InitializedParams params) {
|
||||
super.initialized(params);
|
||||
this.indexer.initialize(this.getWorkspaceRoot());
|
||||
}
|
||||
|
||||
protected ICompletionEngine createCompletionEngine(JavaProjectFinder javaProjectFinder, SpringPropertyIndexProvider indexProvider) {
|
||||
Map<String, CompletionProvider> providers = new HashMap<>();
|
||||
providers.put(org.springframework.ide.vscode.boot.java.scope.Constants.SPRING_SCOPE, new ScopeCompletionProcessor());
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -71,32 +72,19 @@ public class SpringIndexer {
|
||||
this.symbolsByDoc = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
public void initialize(final Path workspaceRoot) {
|
||||
synchronized(this) {
|
||||
if (this.initializeTask == null) {
|
||||
this.initializeTask = CompletableFuture.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("start initial scan...");
|
||||
Path workspaceRoot = server.getWorkspaceRoot();
|
||||
reset();
|
||||
scanFiles(workspaceRoot.toFile());
|
||||
System.out.println("initial scan done...!!!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.initializeTask.get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.symbols.clear();
|
||||
this.symbolsByDoc.clear();
|
||||
}
|
||||
|
||||
public void updateDocument(String docURI) {
|
||||
@@ -104,18 +92,45 @@ public class SpringIndexer {
|
||||
}
|
||||
|
||||
public List<? extends SymbolInformation> getAllSymbols(String query) {
|
||||
initialize();
|
||||
if (query != null && query.length() > 0) {
|
||||
return searchMatchingSymbols(this.symbols, query);
|
||||
if (initializeTask != null) {
|
||||
try {
|
||||
initializeTask.get();
|
||||
if (query != null && query.length() > 0) {
|
||||
return searchMatchingSymbols(this.symbols, query);
|
||||
} else {
|
||||
return this.symbols;
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
return this.symbols;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<? extends SymbolInformation> getSymbols(String docURI) {
|
||||
if (initializeTask != null) {
|
||||
try {
|
||||
initializeTask.get();
|
||||
return this.symbolsByDoc.get(docURI);
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<SymbolInformation> searchMatchingSymbols(List<SymbolInformation> allsymbols, String query) {
|
||||
return allsymbols.stream()
|
||||
.filter(symbol -> containsCharacters(symbol.getName().toCharArray(), query.toCharArray())).collect(Collectors.toList());
|
||||
if (initializeTask != null) {
|
||||
try {
|
||||
initializeTask.get();
|
||||
return allsymbols.stream()
|
||||
.filter(symbol -> containsCharacters(symbol.getName().toCharArray(), query.toCharArray()))
|
||||
.collect(Collectors.toList());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean containsCharacters(char[] symbolChars, char[] queryChars) {
|
||||
@@ -132,12 +147,7 @@ public class SpringIndexer {
|
||||
return queryindex == queryChars.length;
|
||||
}
|
||||
|
||||
public List<? extends SymbolInformation> getSymbols(String docURI) {
|
||||
initialize();
|
||||
return this.symbolsByDoc.get(docURI);
|
||||
}
|
||||
|
||||
public void scanFiles(File directory) {
|
||||
private void scanFiles(File directory) {
|
||||
try {
|
||||
System.out.println("scan directory...");
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class RequestMappingSymbolProviderTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/SimpleMappingClass.java");
|
||||
@@ -89,7 +89,7 @@ public class RequestMappingSymbolProviderTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/ParentMappingClass.java");
|
||||
|
||||
@@ -76,7 +76,7 @@ public class SpringIndexerBeansTest {
|
||||
public void testScanSimpleConfigurationClass() throws Exception {
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-beans/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/SimpleConfiguration.java");
|
||||
@@ -88,7 +88,7 @@ public class SpringIndexerBeansTest {
|
||||
public void testScanSimpleFunctionBean() throws Exception {
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-beans/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/FunctionClass.java");
|
||||
@@ -100,7 +100,7 @@ public class SpringIndexerBeansTest {
|
||||
public void testScanSimpleComponentClass() throws Exception {
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-beans/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/SimpleComponent.java");
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("");
|
||||
|
||||
@@ -99,7 +99,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/MainClass.java");
|
||||
@@ -126,7 +126,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("");
|
||||
|
||||
@@ -150,7 +150,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("mapp");
|
||||
|
||||
@@ -172,7 +172,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("@/foo-root-mapping -- (no method defined)");
|
||||
|
||||
@@ -190,7 +190,7 @@ public class SpringIndexerTest {
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
indexer.scanFiles(directory);
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("@/foo-root-mapping/embedded-foo-mapping-with-root -- (no method defined)");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user