Skip to content

Commit dc03ddf

Browse files
committed
Add workspace indexing progress notifications
Implement LSP $/progress notifications during workspace file indexing to provide visual feedback in editors/clients. - Add progress callback parameter to ASTNodeCache.update() - Report per-file progress using AtomicInteger for thread-safe counting - Create ProgressNotification in LanguageService.update0() for multi-file updates - Show progress when indexing > 1 file (initial scan or batch updates) - Use workspace-specific token to support multiple workspaces Closes #148
1 parent f705740 commit dc03ddf

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main/java/nextflow/lsp/ast/ASTNodeCache.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.List;
2626
import java.util.Map;
2727
import java.util.Set;
28+
import java.util.concurrent.atomic.AtomicInteger;
29+
import java.util.function.BiConsumer;
2830
import java.util.stream.Collectors;
2931

3032
import nextflow.lsp.compiler.LanguageServerCompiler;
@@ -86,8 +88,9 @@ public void clear() {
8688
*
8789
* @param uris
8890
* @param fileCache
91+
* @param progress optional callback to report progress as (current, total)
8992
*/
90-
public Set<URI> update(Set<URI> uris, FileCache fileCache) {
93+
public Set<URI> update(Set<URI> uris, FileCache fileCache, BiConsumer<Integer, Integer> progress) {
9194
// invalidate cache for each source file
9295
for( var uri : uris ) {
9396
var nodes = nodesByURI.remove(uri);
@@ -101,12 +104,17 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {
101104
}
102105

103106
// parse source files
107+
var counter = new AtomicInteger(0);
108+
var total = uris.size();
104109
var sources = uris.parallelStream()
105110
.map(uri -> compiler.createSourceUnit(uri, fileCache))
106111
.filter(sourceUnit -> sourceUnit != null)
107112
.map(sourceUnit -> {
108113
compiler.addSource(sourceUnit);
109114
compiler.compile(sourceUnit);
115+
if( progress != null ) {
116+
progress.accept(counter.incrementAndGet(), total);
117+
}
110118
return sourceUnit;
111119
})
112120
.sequential()

src/main/java/nextflow/lsp/services/LanguageService.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import nextflow.lsp.util.DebouncingExecutor;
3939
import nextflow.lsp.util.LanguageServerUtils;
4040
import nextflow.lsp.util.Logger;
41+
import nextflow.lsp.util.ProgressNotification;
4142
import nextflow.lsp.util.Positions;
4243
import nextflow.script.control.ParanoidWarning;
4344
import nextflow.script.control.RelatedInformationAware;
@@ -363,14 +364,34 @@ private void update0() {
363364
log.debug(builder.toString());
364365
}
365366

367+
// Create progress notification for multi-file updates
368+
ProgressNotification progress = null;
369+
if( uris.size() > 1 && client != null ) {
370+
var token = "indexing-" + (rootUri != null ? rootUri.hashCode() : "default");
371+
progress = new ProgressNotification(client, token);
372+
progress.create();
373+
progress.begin(String.format("Indexing %d files...", uris.size()));
374+
}
375+
366376
try {
367-
var changedUris = astCache.update(uris, fileCache);
377+
final var progressNotification = progress;
378+
var changedUris = astCache.update(uris, fileCache,
379+
progressNotification != null
380+
? (current, total) -> progressNotification.update(
381+
String.format("Indexing: %d / %d files", current, total),
382+
current * 100 / total)
383+
: null);
368384
publishDiagnostics(changedUris);
369385
}
370386
catch( Throwable e ) {
371387
System.err.println(e);
372388
e.printStackTrace();
373389
}
390+
finally {
391+
if( progress != null ) {
392+
progress.end();
393+
}
394+
}
374395
}
375396

376397
/**

0 commit comments

Comments
 (0)