Skip to content

Commit 3724b64

Browse files
committed
spring index update events now contain a list of affected projects
1 parent ae340e9 commit 3724b64

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -633,7 +633,7 @@ public void liveProcessMemoryMetricsDataUpdated(LiveProcessSummary arg0) {
633633
}
634634

635635
@Override
636-
public void indexUpdated() {
636+
public void indexUpdated(List<String> affectedProjects) {
637637
}
638638

639639
@Override

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/SpringIndexLanguageClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 VMware, Inc.
2+
* Copyright (c) 2023, 2025 VMware, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -10,12 +10,14 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.protocol.spring;
1212

13+
import java.util.List;
14+
1315
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
1416
import org.eclipse.lsp4j.services.LanguageClient;
1517

1618
public interface SpringIndexLanguageClient extends LanguageClient {
1719

1820
@JsonNotification("spring/index/updated")
19-
void indexUpdated();
21+
void indexUpdated(List<String> affectedProjects);
2022

2123
}

headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2024 Pivotal, Inc.
2+
* Copyright (c) 2016, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -176,7 +176,7 @@ public class LanguageServerHarness {
176176

177177
private boolean enableHierarchicalDocumentSymbols = false;
178178

179-
private int indexUpdated;
179+
private List<List<String>> indexUpdated = new ArrayList<>();
180180

181181

182182
public LanguageServerHarness(SimpleLanguageServer server, LanguageId defaultLanguageId) {
@@ -262,12 +262,16 @@ private void receiveHighlights(HighlightParams highlights) {
262262
}
263263
}
264264

265-
private void receiveIndexUpdated() {
266-
this.indexUpdated++;
265+
private void receiveIndexUpdated(List<String> affectedProjects) {
266+
this.indexUpdated.add(affectedProjects);
267267
}
268268

269269
public int getIndexUpdatedCount() {
270-
return this.indexUpdated;
270+
return this.indexUpdated.size();
271+
}
272+
273+
public List<String> getIndexUpdatedDetails(int updateNo) {
274+
return this.indexUpdated.get(updateNo);
271275
}
272276

273277
public void ensureInitialized() throws Exception {
@@ -453,8 +457,8 @@ public void liveProcessGcPausesMetricsDataUpdated(LiveProcessSummary processKey)
453457
}
454458

455459
@Override
456-
public void indexUpdated() {
457-
receiveIndexUpdated();
460+
public void indexUpdated(List<String> affectedProjects) {
461+
receiveIndexUpdated(affectedProjects);
458462
}
459463

460464
@Override

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/SpringSymbolIndex.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private CompletableFuture<Void> _initializeProject(IJavaProject project, boolean
410410

411411
CompletableFuture<Void> future = CompletableFuture.allOf(futures);
412412

413-
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
413+
future = future.thenAccept(v -> server.getClient().indexUpdated(List.of(project.getElementName()))).thenAccept(v -> listeners.fire(v));
414414

415415
this.latestScheduledTaskByProject.put(project.getElementName(), future);
416416
return future;
@@ -458,6 +458,8 @@ public CompletableFuture<Void> createDocuments(String[] docURIs) {
458458
List<CompletableFuture<Void>> futures = new ArrayList<>();
459459

460460
docURIs = unfold(docURIs);
461+
462+
List<String> affectedProjects = new ArrayList<>();
461463

462464
for (SpringIndexer indexer : this.indexers) {
463465
String[] interestingDocs = getDocumentsInterestingForIndexer(indexer, docURIs);
@@ -474,11 +476,13 @@ public CompletableFuture<Void> createDocuments(String[] docURIs) {
474476
catch (Exception e) {
475477
log.error("{}", e);
476478
}
479+
480+
affectedProjects.add(project.getElementName());
477481
}
478482
}
479483

480484
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
481-
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
485+
future = future.thenAccept(v -> server.getClient().indexUpdated(affectedProjects)).thenAccept(v -> listeners.fire(v));
482486
return future;
483487
}
484488
}
@@ -518,6 +522,7 @@ public CompletableFuture<Void> updateDocument(String docURI, String content, Str
518522

519523
synchronized(this) {
520524
List<CompletableFuture<Void>> futures = new ArrayList<>();
525+
List<String> affectedProjects = new ArrayList<>();
521526

522527
for (SpringIndexer indexer : this.indexers) {
523528
if (indexer.isInterestedIn(docURI)) {
@@ -530,11 +535,12 @@ public CompletableFuture<Void> updateDocument(String docURI, String content, Str
530535
catch (Exception e) {
531536
log.error("{}", e);
532537
}
538+
affectedProjects.add(maybeProject.get().getElementName());
533539
}
534540
}
535541
}
536542
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
537-
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
543+
future = future.thenAccept(v -> server.getClient().indexUpdated(affectedProjects)).thenAccept(v -> listeners.fire(v));
538544
return future;
539545
}
540546
}
@@ -546,6 +552,7 @@ public CompletableFuture<Void> updateDocuments(String[] docURIs, String reason)
546552

547553
synchronized(this) {
548554
List<CompletableFuture<Void>> futures = new ArrayList<>();
555+
List<String> affectedProjects = new ArrayList<>();
549556

550557
for (SpringIndexer indexer : this.indexers) {
551558
String[] interestingDocs = getDocumentsInterestingForIndexer(indexer, docURIs);
@@ -562,10 +569,12 @@ public CompletableFuture<Void> updateDocuments(String[] docURIs, String reason)
562569
catch (Exception e) {
563570
log.error("{}", e);
564571
}
572+
573+
affectedProjects.add(project.getElementName());
565574
}
566575
}
567576
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
568-
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
577+
future = future.thenAccept(v -> server.getClient().indexUpdated(affectedProjects)).thenAccept(v -> listeners.fire(v));
569578
return future;
570579
}
571580
}
@@ -642,6 +651,7 @@ public CompletableFuture<Void> deleteDocuments(String[] deletedPathURIs) {
642651
synchronized(this) {
643652
try {
644653
List<CompletableFuture<Void>> futures = new ArrayList<>();
654+
List<String> affectedProjects = new ArrayList<>();
645655
Map<IJavaProject, Set<String>> projectMapping = getDocsPerProjectFromPaths(deletedPathURIs);
646656

647657
for (IJavaProject project : projectMapping.keySet()) {
@@ -653,12 +663,14 @@ public CompletableFuture<Void> deleteDocuments(String[] deletedPathURIs) {
653663

654664
this.latestScheduledTaskByProject.put(project.getElementName(), future);
655665
futures.add(future);
666+
667+
affectedProjects.add(project.getElementName());
656668
}
657669
}
658670

659671
if (futures.size() > 0) {
660672
CompletableFuture<Void> future = CompletableFuture.allOf((CompletableFuture[]) futures.toArray(new CompletableFuture[futures.size()]));
661-
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
673+
future = future.thenAccept(v -> server.getClient().indexUpdated(affectedProjects)).thenAccept(v -> listeners.fire(v));
662674
return future;
663675
}
664676
else {
@@ -1097,7 +1109,7 @@ public void run() {
10971109
index.removeProject(project);
10981110
}
10991111
springIndex.removeProject(project.getElementName());
1100-
server.getClient().indexUpdated();
1112+
server.getClient().indexUpdated(List.of(project.getElementName()));
11011113

11021114
log.debug("{} completed", this);
11031115
} catch (Throwable e) {

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/index/test/SpringMetamodelIndexingTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 VMware, Inc.
2+
* Copyright (c) 2023, 2025 VMware, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -71,6 +71,8 @@ public void setup() throws Exception {
7171
@Test
7272
void testUpdateNotificationAfterProjectCreation() {
7373
assertEquals(1, harness.getIndexUpdatedCount());
74+
assertEquals(1, harness.getIndexUpdatedDetails(0).size());
75+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(0).get(0));
7476
}
7577

7678
@Test
@@ -85,6 +87,10 @@ void testDeleteProject() throws Exception {
8587
assertEquals(0, noBeansAnymore.length);
8688

8789
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x project deleted
90+
assertEquals(1, harness.getIndexUpdatedDetails(0).size());
91+
assertEquals(1, harness.getIndexUpdatedDetails(1).size());
92+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(0).get(0));
93+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(1).get(0));
8894
}
8995

9096
@Test
@@ -110,6 +116,10 @@ void testRemoveSymbolsFromDeletedDocument() throws Exception {
110116
assertEquals(allBeansOfProject.length - 1, lessBeansOfProject.length);
111117

112118
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x document deleted
119+
assertEquals(1, harness.getIndexUpdatedDetails(0).size());
120+
assertEquals(1, harness.getIndexUpdatedDetails(1).size());
121+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(0).get(0));
122+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(1).get(0));
113123
}
114124

115125
@Test
@@ -139,6 +149,10 @@ void testUpdateChangedDocument() throws Exception {
139149
assertEquals("bean1", updatedInjectionPoints[0].getName());
140150

141151
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x document updated
152+
assertEquals(1, harness.getIndexUpdatedDetails(0).size());
153+
assertEquals(1, harness.getIndexUpdatedDetails(1).size());
154+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(0).get(0));
155+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(1).get(0));
142156
}
143157

144158
@Test
@@ -198,6 +212,10 @@ void testNewDocumentCreated() throws Exception {
198212
assertEquals("org.test.BeanClass1", newBeans[1].getType());
199213

200214
assertEquals(2, harness.getIndexUpdatedCount()); // 1x project created, 1x new document created
215+
assertEquals(1, harness.getIndexUpdatedDetails(0).size());
216+
assertEquals(1, harness.getIndexUpdatedDetails(1).size());
217+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(0).get(0));
218+
assertEquals("test-spring-indexing", harness.getIndexUpdatedDetails(1).get(0));
201219
}
202220
finally {
203221
FileUtils.deleteQuietly(new File(new URI(createdDocURI)));

0 commit comments

Comments
 (0)