do not delete symbols from indexer if file is not re-scanned by the individual indexer, e.g. because of unchanged timestamps

This commit is contained in:
Martin Lippert
2020-02-06 11:42:27 +01:00
parent fbb306b9ad
commit ed3e6aee58
4 changed files with 19 additions and 7 deletions

View File

@@ -672,8 +672,6 @@ public class SpringSymbolIndex implements InitializingBean {
try {
log.debug("updateItem {}. {}, {}, {}", project.getElementName(), updatedDoc.getDocURI(), updatedDoc.getLastModified(), indexer);
removeSymbolsByDoc(project, updatedDoc.getDocURI());
indexer.updateFile(project, updatedDoc);
} catch (Exception e) {
log.error("{}", e);
@@ -691,7 +689,6 @@ public class SpringSymbolIndex implements InitializingBean {
try {
for (UpdatedDoc doc : updatedDoc) {
log.debug("updateItem {}. {}, {}, {}", project.getElementName(), doc.getDocURI(), doc.getLastModified(), indexer);
removeSymbolsByDoc(project, doc.getDocURI());
}
indexer.updateFiles(project, updatedDoc);

View File

@@ -144,7 +144,8 @@ public class SpringIndexerJava implements SpringIndexer {
public void updateFile(IJavaProject project, UpdatedDoc updatedDoc) throws Exception {
SymbolCacheKey cacheKey = getCacheKey(project);
if (updatedDoc != null && shouldProcessDocument(project, updatedDoc.getDocURI())
&& hasNewerModificationTimestamp(cacheKey, updatedDoc.getDocURI(), updatedDoc.getLastModified())) {
&& isCacheOutdated(cacheKey, updatedDoc.getDocURI(), updatedDoc.getLastModified())) {
this.symbolHandler.removeSymbols(project, updatedDoc.getDocURI());
scanFile(project, updatedDoc);
}
}
@@ -153,6 +154,11 @@ public class SpringIndexerJava implements SpringIndexer {
public void updateFiles(IJavaProject project, UpdatedDoc[] updatedDocs) throws Exception {
if (updatedDocs != null) {
UpdatedDoc[] docs = filterDocuments(project, updatedDocs);
for (UpdatedDoc updatedDoc : docs) {
this.symbolHandler.removeSymbols(project, updatedDoc.getDocURI());
}
scanFiles(project, docs);
}
}
@@ -160,7 +166,7 @@ public class SpringIndexerJava implements SpringIndexer {
private UpdatedDoc[] filterDocuments(IJavaProject project, UpdatedDoc[] updatedDocs) {
SymbolCacheKey cacheKey = getCacheKey(project);
return Arrays.stream(updatedDocs).filter(doc -> shouldProcessDocument(project, doc.getDocURI()))
.filter(doc -> hasNewerModificationTimestamp(cacheKey, doc.getDocURI(), doc.getLastModified())).toArray(UpdatedDoc[]::new);
.filter(doc -> isCacheOutdated(cacheKey, doc.getDocURI(), doc.getLastModified())).toArray(UpdatedDoc[]::new);
}
@Override
@@ -181,7 +187,7 @@ public class SpringIndexerJava implements SpringIndexer {
.isPresent();
}
private boolean hasNewerModificationTimestamp(SymbolCacheKey cacheKey, String docURI, long modifiedTimestamp) {
private boolean isCacheOutdated(SymbolCacheKey cacheKey, String docURI, long modifiedTimestamp) {
long cachedModificationTImestamp = this.cache.getModificationTimestamp(cacheKey, UriUtil.toFileString(docURI));
return modifiedTimestamp > cachedModificationTImestamp;
}

View File

@@ -141,6 +141,8 @@ public class SpringIndexerXML implements SpringIndexer {
@Override
public void updateFile(IJavaProject project, UpdatedDoc updatedDoc) throws Exception {
this.symbolHandler.removeSymbols(project, updatedDoc.getDocURI());
List<CachedSymbol> generatedSymbols = new ArrayList<CachedSymbol>();
String docURI = updatedDoc.getDocURI();
@@ -162,6 +164,8 @@ public class SpringIndexerXML implements SpringIndexer {
for (UpdatedDoc updatedDoc : updatedDocs) {
String docURI = updatedDoc.getDocURI();
this.symbolHandler.removeSymbols(project, docURI);
scanFile(project, updatedDoc.getContent().get(), docURI, updatedDoc.getLastModified(), generatedSymbols);

View File

@@ -28,7 +28,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
@@ -171,6 +170,9 @@ public class SpringIndexerMultipleFilesTest {
fileScanListener.assertScannedUris();
fileScanListener.assertScannedUri(unchangedDocURI, 0);
List<? extends SymbolInformation> symbols = indexer.getSymbols(unchangedDocURI);
assertEquals(2, symbols.size());
}
@Test
@@ -203,6 +205,9 @@ public class SpringIndexerMultipleFilesTest {
assertTrue(containsSymbol(symbols1, "@/mapping1-CHANGED", doc1URI, 6, 1, 6, 36));
assertTrue(containsSymbol(symbols1, "@/mapping2", doc1URI, 11, 1, 11, 28));
List<? extends SymbolInformation> symbols2 = indexer.getSymbols(doc2URI);
assertEquals(3, symbols2.size());
List<? extends SymbolInformation> symbols3 = indexer.getSymbols(doc3URI);
assertTrue(containsSymbol(symbols3, "@/classlevel-CHANGED/mapping-subpackage", doc3URI, 7, 1, 7, 38));