allow spring indexer to remove symbols from deleted document
This commit is contained in:
@@ -163,7 +163,7 @@ public class SpringIndexer {
|
||||
return lastInitializeItem != null && !lastInitializeItem.getFuture().isDone();
|
||||
}
|
||||
|
||||
private void waitForInitializeTask() {
|
||||
public void waitForInitializeTask() {
|
||||
synchronized (this) {
|
||||
if (lastInitializeItem != null) {
|
||||
try {
|
||||
@@ -216,7 +216,7 @@ public class SpringIndexer {
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,6 +224,21 @@ public class SpringIndexer {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> deleteDocument(String deletedDocURI) {
|
||||
synchronized(this) {
|
||||
try {
|
||||
DeleteItem deleteItem = new DeleteItem(deletedDocURI);
|
||||
updateQueue.put(deleteItem);
|
||||
return deleteItem.getFuture();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SymbolInformation> getAllSymbols(String query) {
|
||||
waitForInitializeTask();
|
||||
|
||||
@@ -481,37 +496,6 @@ public class SpringIndexer {
|
||||
|
||||
}
|
||||
|
||||
private class UpdateItem implements WorkerItem {
|
||||
|
||||
private final String docURI;
|
||||
private final String content;
|
||||
private final String[] classpathEntries;
|
||||
|
||||
private final CompletableFuture<Void> future;
|
||||
|
||||
public UpdateItem(String docURI, String content, String[] classpathEntries) {
|
||||
this.docURI = docURI;
|
||||
this.content = content;
|
||||
this.classpathEntries = classpathEntries;
|
||||
this.future = new CompletableFuture<Void>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SpringIndexer.this.scanFile(docURI, content, classpathEntries);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
future.complete(null);
|
||||
}
|
||||
}
|
||||
|
||||
private class InitializeItem implements WorkerItem {
|
||||
|
||||
private final WorkspaceFolder[] workspaceRoots;
|
||||
@@ -548,4 +532,64 @@ public class SpringIndexer {
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateItem implements WorkerItem {
|
||||
|
||||
private final String docURI;
|
||||
private final String content;
|
||||
private final String[] classpathEntries;
|
||||
|
||||
private final CompletableFuture<Void> future;
|
||||
|
||||
public UpdateItem(String docURI, String content, String[] classpathEntries) {
|
||||
this.docURI = docURI;
|
||||
this.content = content;
|
||||
this.classpathEntries = classpathEntries;
|
||||
this.future = new CompletableFuture<Void>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SpringIndexer.this.scanFile(docURI, content, classpathEntries);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
future.complete(null);
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteItem implements WorkerItem {
|
||||
|
||||
private final String docURI;
|
||||
private final CompletableFuture<Void> future;
|
||||
|
||||
public DeleteItem(String docURI) {
|
||||
this.docURI = docURI;
|
||||
this.future = new CompletableFuture<Void>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<SymbolInformation> oldSymbols = symbolsByDoc.remove(docURI);
|
||||
if (oldSymbols != null) {
|
||||
symbols.removeAll(oldSymbols);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
future.complete(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.boot.java.utils.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
@@ -153,6 +154,32 @@ public class SpringIndexerTest {
|
||||
assertTrue(containsSymbol(allSymbols, "@/classlevel/mapping-subpackage", uriPrefix + "/src/main/java/org/test/sub/MappingClassSubpackage.java", 7, 1, 7, 38));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveSymbolsFromDeletedDocument() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI()));
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI());
|
||||
|
||||
// update document and update index
|
||||
String deletedDocURI = "file://" + directory.getAbsolutePath() + "/src/main/java/org/test/SimpleMappingClass.java";
|
||||
CompletableFuture<Void> deleteFuture = indexer().deleteDocument(deletedDocURI);
|
||||
deleteFuture.get(5, TimeUnit.SECONDS);
|
||||
|
||||
// check for updated index per document
|
||||
List<? extends SymbolInformation> symbols = indexer().getSymbols(deletedDocURI);
|
||||
assertNull(symbols);
|
||||
|
||||
// check for updated index in all symbols
|
||||
List<? extends SymbolInformation> allSymbols = indexer().getAllSymbols("");
|
||||
assertEquals(4, allSymbols.size());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
|
||||
assertTrue(containsSymbol(allSymbols, "@+ 'mainClass' (@SpringBootApplication <: @SpringBootConfiguration, @Configuration, @Component) MainClass", uriPrefix + "/src/main/java/org/test/MainClass.java", 6, 0, 6, 22));
|
||||
assertTrue(containsSymbol(allSymbols, "@/embedded-foo-mapping", uriPrefix + "/src/main/java/org/test/MainClass.java", 17, 1, 17, 41));
|
||||
assertTrue(containsSymbol(allSymbols, "@/foo-root-mapping/embedded-foo-mapping-with-root", uriPrefix + "/src/main/java/org/test/MainClass.java", 27, 1, 27, 51));
|
||||
assertTrue(containsSymbol(allSymbols, "@/classlevel/mapping-subpackage", uriPrefix + "/src/main/java/org/test/sub/MappingClassSubpackage.java", 7, 1, 7, 38));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterSymbolsUsingQueryString() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-indexing-parent/test-annotation-indexing/").toURI()));
|
||||
|
||||
Reference in New Issue
Block a user