implemented update notifications for new spring index

This commit is contained in:
Martin Lippert
2023-05-10 14:00:25 +02:00
parent 2dfcdd0f29
commit 98a4c9b3e7
3 changed files with 39 additions and 8 deletions

View File

@@ -159,6 +159,8 @@ public class LanguageServerHarness {
private boolean enableHierarchicalDocumentSymbols = false;
private int indexUpdated;
public LanguageServerHarness(SimpleLanguageServer server, LanguageId defaultLanguageId) {
this.defaultLanguageId = defaultLanguageId;
@@ -242,6 +244,14 @@ public class LanguageServerHarness {
future.complete(highlights);
}
}
private void receiveIndexUpdated() {
this.indexUpdated++;
}
public int getIndexUpdatedCount() {
return this.indexUpdated;
}
public void ensureInitialized() throws Exception {
if (initResult==null) {
@@ -418,7 +428,8 @@ public class LanguageServerHarness {
}
@Override
public void modelUpdated() {
public void indexUpdated() {
receiveIndexUpdated();
}
});

View File

@@ -200,7 +200,6 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
springIndex.updateBeans(project.getElementName(), docURI, (Bean[]) beans.toArray(new Bean[beans.size()]));
}
}
@Override
@@ -370,7 +369,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
CompletableFuture<Void> future = CompletableFuture.allOf(futures);
future.thenAccept(v -> listeners.fire(v));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
this.latestScheduledTaskByProject.put(project.getElementName(), future);
return future;
@@ -428,7 +427,9 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
}
}
return CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
return future;
}
}
@@ -455,7 +456,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
}
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
future.thenAccept(v -> listeners.fire(v));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
return future;
}
}
@@ -484,7 +485,9 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
}
}
}
return CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
return future;
}
}
@@ -514,7 +517,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
}
}
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
future.thenAccept(v -> listeners.fire(v));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
return future;
}
}
@@ -589,7 +592,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
}
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
future.thenAccept(v -> listeners.fire(v));
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
return future;
}
catch (Exception e) {
@@ -865,6 +868,9 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
for (SpringIndexer index : this.indexer) {
index.removeFiles(project, docURIs);
}
server.getClient().indexUpdated();
} catch (Exception e) {
log.error("{}", e);
}
@@ -891,6 +897,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringModelService {
index.removeProject(project);
}
springIndex.removeBeans(project.getElementName());
server.getClient().indexUpdated();
log.debug("{} completed", this);
} catch (Throwable e) {

View File

@@ -66,6 +66,11 @@ public class SpringMetamodelIndexingTest {
initProject.get(5, TimeUnit.SECONDS);
}
@Test
void testUpdateNotificationAfterProjectCreation() {
assertEquals(1, harness.getIndexUpdatedCount());
}
@Test
void testDeleteProject() throws Exception {
Bean[] beans = springIndex.getBeansOfProject("test-spring-indexing");
@@ -76,6 +81,8 @@ public class SpringMetamodelIndexingTest {
Bean[] noBeansAnymore = springIndex.getBeansOfProject("test-spring-indexing");
assertNull(noBeansAnymore);
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x project deleted
}
@Test
@@ -99,6 +106,8 @@ public class SpringMetamodelIndexingTest {
// check for updated index in all symbols
Bean[] lessBeansOfProject = springIndex.getBeansOfProject("test-spring-indexing");
assertEquals(10, lessBeansOfProject.length);
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x document deleted
}
@Test
@@ -126,6 +135,8 @@ public class SpringMetamodelIndexingTest {
assertEquals(1, updatedInjectionPoints.length);
assertEquals("org.test.BeanClass1", updatedInjectionPoints[0].getType());
assertEquals("bean1", updatedInjectionPoints[0].getName());
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x document updated
}
@Test
@@ -167,6 +178,8 @@ public class SpringMetamodelIndexingTest {
assertEquals("createdClassBean", newBeans[1].getName());
assertEquals("org.test.BeanClass1", newBeans[1].getType());
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x new document created
}
finally {
FileUtils.deleteQuietly(new File(new URI(createdDocURI)));