Skip to content

Commit 5096358

Browse files
authored
Add option for lightweight startup (#110)
Signed-off-by: Ben Sherman <[email protected]>
1 parent 5b8ded1 commit 5096358

File tree

7 files changed

+38
-22
lines changed

7 files changed

+38
-22
lines changed

src/main/java/nextflow/lsp/NextflowLanguageServer.java

+1
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
452452
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.harshilAlignment"), configuration.harshilAlignment()),
453453
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.maheshForm"), configuration.maheshForm()),
454454
withDefault(JsonUtils.getInteger(settings, "nextflow.completion.maxItems"), configuration.maxCompletionItems()),
455+
withDefault(JsonUtils.getBoolean(settings, "nextflow.files.scanWorkspace"), configuration.scanWorkspace()),
455456
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.sortDeclarations"), configuration.sortDeclarations()),
456457
withDefault(JsonUtils.getBoolean(settings, "nextflow.typeChecking"), configuration.typeChecking())
457458
);

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {
102102

103103
// parse source files
104104
var sources = uris.parallelStream()
105-
.map(uri -> compiler.getSource(uri, fileCache))
105+
.map(uri -> compiler.newSourceUnit(uri, fileCache))
106106
.filter(sourceUnit -> sourceUnit != null)
107107
.map(sourceUnit -> {
108108
compiler.addSource(sourceUnit);
@@ -113,7 +113,7 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {
113113
.collect(Collectors.toSet());
114114

115115
// perform additional ast analysis
116-
var changedUris = analyze(uris);
116+
var changedUris = analyze(uris, fileCache);
117117

118118
// update ast parents cache
119119
for( var sourceUnit : sources ) {
@@ -164,8 +164,9 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {
164164
* Return the set of files whose errors have changed.
165165
*
166166
* @param uris
167+
* @param fileCache
167168
*/
168-
protected abstract Set<URI> analyze(Set<URI> uris);
169+
protected abstract Set<URI> analyze(Set<URI> uris, FileCache fileCache);
169170

170171
/**
171172
* Visit the AST of a source file and retrieve the set of relevant

src/main/java/nextflow/lsp/compiler/LanguageServerCompiler.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public LanguageServerCompiler(CompilerConfiguration configuration, GroovyClassLo
5050
*
5151
* @param uri
5252
*/
53-
public SourceUnit getSource(URI uri, FileCache fileCache) {
53+
public SourceUnit newSourceUnit(URI uri, FileCache fileCache) {
5454
if( fileCache.isOpen(uri) ) {
5555
var contents = fileCache.getContents(uri);
5656
return new SourceUnit(
@@ -60,18 +60,14 @@ public SourceUnit getSource(URI uri, FileCache fileCache) {
6060
classLoader(),
6161
newErrorCollector());
6262
}
63-
else if( Files.exists(Path.of(uri)) ) {
64-
return new SourceUnit(
65-
new File(uri),
66-
configuration(),
67-
classLoader(),
68-
newErrorCollector());
63+
if( Files.exists(Path.of(uri)) ) {
64+
return super.newSourceUnit(new File(uri));
6965
}
70-
else
71-
return null;
66+
return null;
7267
}
7368

74-
private ErrorCollector newErrorCollector() {
69+
@Override
70+
protected ErrorCollector newErrorCollector() {
7571
return new LanguageServerErrorCollector(configuration());
7672
}
7773

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

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public record LanguageServerConfiguration(
2525
boolean harshilAlignment,
2626
boolean maheshForm,
2727
int maxCompletionItems,
28+
boolean scanWorkspace,
2829
boolean sortDeclarations,
2930
boolean typeChecking
3031
) {
@@ -38,6 +39,7 @@ public static LanguageServerConfiguration defaults() {
3839
false,
3940
100,
4041
false,
42+
false,
4143
false
4244
);
4345
}

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,27 @@ public void initialize(String rootUri, LanguageServerConfiguration configuration
128128
this.initialized = false;
129129
this.configuration = configuration;
130130

131-
var uris = rootUri != null
132-
? getWorkspaceFiles(rootUri)
133-
: fileCache.getOpenFiles();
134-
135131
var astCache = getAstCache();
136-
astCache.clear();
137-
var changedUris = astCache.update(uris, fileCache);
138-
publishDiagnostics(changedUris);
132+
133+
if( configuration.scanWorkspace() ) {
134+
var uris = getWorkspaceFiles(rootUri);
135+
astCache.clear();
136+
var changedUris = astCache.update(uris, fileCache);
137+
publishDiagnostics(changedUris);
138+
}
139+
else {
140+
clearDiagnostics();
141+
astCache.clear();
142+
}
139143

140144
this.initialized = true;
141145
}
142146
}
143147

144148
protected Set<URI> getWorkspaceFiles(String rootUri) {
149+
if( rootUri == null ) {
150+
return fileCache.getOpenFiles();
151+
}
145152
try {
146153
var result = new HashSet<URI>();
147154
PathUtils.visitFiles(

src/main/java/nextflow/lsp/services/config/ConfigAstCache.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import nextflow.lsp.ast.ASTNodeCache;
2828
import nextflow.lsp.compiler.LanguageServerCompiler;
2929
import nextflow.lsp.compiler.LanguageServerErrorCollector;
30+
import nextflow.lsp.file.FileCache;
3031
import nextflow.lsp.services.LanguageServerConfiguration;
3132
import nextflow.script.control.PhaseAware;
3233
import nextflow.script.control.Phases;
@@ -65,7 +66,7 @@ public void initialize(LanguageServerConfiguration configuration) {
6566
}
6667

6768
@Override
68-
protected Set<URI> analyze(Set<URI> uris) {
69+
protected Set<URI> analyze(Set<URI> uris, FileCache fileCache) {
6970
// phase 2: include checking
7071
var changedUris = new HashSet<>(uris);
7172

src/main/java/nextflow/lsp/services/script/ScriptAstCache.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
import nextflow.lsp.ast.ASTNodeCache;
2828
import nextflow.lsp.compiler.LanguageServerCompiler;
2929
import nextflow.lsp.compiler.LanguageServerErrorCollector;
30+
import nextflow.lsp.file.FileCache;
3031
import nextflow.lsp.services.LanguageServerConfiguration;
3132
import nextflow.script.ast.FunctionNode;
3233
import nextflow.script.ast.IncludeNode;
3334
import nextflow.script.ast.ProcessNode;
3435
import nextflow.script.ast.ScriptNode;
3536
import nextflow.script.ast.WorkflowNode;
37+
import nextflow.script.control.ModuleResolver;
3638
import nextflow.script.control.PhaseAware;
3739
import nextflow.script.control.Phases;
3840
import nextflow.script.control.ResolveIncludeVisitor;
@@ -86,7 +88,13 @@ public void initialize(String rootUri, LanguageServerConfiguration configuration
8688
}
8789

8890
@Override
89-
protected Set<URI> analyze(Set<URI> uris) {
91+
protected Set<URI> analyze(Set<URI> uris, FileCache fileCache) {
92+
// recursively load included modules
93+
for( var uri : uris ) {
94+
var source = compiler().getSource(uri);
95+
new ModuleResolver(compiler()).resolve(source, (includeUri) -> compiler().newSourceUnit(includeUri, fileCache));
96+
}
97+
9098
// phase 2: include checking
9199
var changedUris = new HashSet<>(uris);
92100

0 commit comments

Comments
 (0)