Skip to content

Add option for lightweight startup #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/nextflow/lsp/NextflowLanguageServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.harshilAlignment"), configuration.harshilAlignment()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.maheshForm"), configuration.maheshForm()),
withDefault(JsonUtils.getInteger(settings, "nextflow.completion.maxItems"), configuration.maxCompletionItems()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.files.scanWorkspace"), configuration.scanWorkspace()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.formatting.sortDeclarations"), configuration.sortDeclarations()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.typeChecking"), configuration.typeChecking())
);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/nextflow/lsp/ast/ASTNodeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {

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

// perform additional ast analysis
var changedUris = analyze(uris);
var changedUris = analyze(uris, fileCache);

// update ast parents cache
for( var sourceUnit : sources ) {
Expand Down Expand Up @@ -164,8 +164,9 @@ public Set<URI> update(Set<URI> uris, FileCache fileCache) {
* Return the set of files whose errors have changed.
*
* @param uris
* @param fileCache
*/
protected abstract Set<URI> analyze(Set<URI> uris);
protected abstract Set<URI> analyze(Set<URI> uris, FileCache fileCache);

/**
* Visit the AST of a source file and retrieve the set of relevant
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/nextflow/lsp/compiler/LanguageServerCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public LanguageServerCompiler(CompilerConfiguration configuration, GroovyClassLo
*
* @param uri
*/
public SourceUnit getSource(URI uri, FileCache fileCache) {
public SourceUnit newSourceUnit(URI uri, FileCache fileCache) {
if( fileCache.isOpen(uri) ) {
var contents = fileCache.getContents(uri);
return new SourceUnit(
Expand All @@ -60,18 +60,14 @@ public SourceUnit getSource(URI uri, FileCache fileCache) {
classLoader(),
newErrorCollector());
}
else if( Files.exists(Path.of(uri)) ) {
return new SourceUnit(
new File(uri),
configuration(),
classLoader(),
newErrorCollector());
if( Files.exists(Path.of(uri)) ) {
return super.newSourceUnit(new File(uri));
}
else
return null;
return null;
}

private ErrorCollector newErrorCollector() {
@Override
protected ErrorCollector newErrorCollector() {
return new LanguageServerErrorCollector(configuration());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public record LanguageServerConfiguration(
boolean harshilAlignment,
boolean maheshForm,
int maxCompletionItems,
boolean scanWorkspace,
boolean sortDeclarations,
boolean typeChecking
) {
Expand All @@ -38,6 +39,7 @@ public static LanguageServerConfiguration defaults() {
false,
100,
false,
false,
false
);
}
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/nextflow/lsp/services/LanguageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,27 @@ public void initialize(String rootUri, LanguageServerConfiguration configuration
this.initialized = false;
this.configuration = configuration;

var uris = rootUri != null
? getWorkspaceFiles(rootUri)
: fileCache.getOpenFiles();

var astCache = getAstCache();
astCache.clear();
var changedUris = astCache.update(uris, fileCache);
publishDiagnostics(changedUris);

if( configuration.scanWorkspace() ) {
var uris = getWorkspaceFiles(rootUri);
astCache.clear();
var changedUris = astCache.update(uris, fileCache);
publishDiagnostics(changedUris);
}
else {
clearDiagnostics();
astCache.clear();
}

this.initialized = true;
}
}

protected Set<URI> getWorkspaceFiles(String rootUri) {
if( rootUri == null ) {
return fileCache.getOpenFiles();
}
try {
var result = new HashSet<URI>();
PathUtils.visitFiles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import nextflow.lsp.ast.ASTNodeCache;
import nextflow.lsp.compiler.LanguageServerCompiler;
import nextflow.lsp.compiler.LanguageServerErrorCollector;
import nextflow.lsp.file.FileCache;
import nextflow.lsp.services.LanguageServerConfiguration;
import nextflow.script.control.PhaseAware;
import nextflow.script.control.Phases;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void initialize(LanguageServerConfiguration configuration) {
}

@Override
protected Set<URI> analyze(Set<URI> uris) {
protected Set<URI> analyze(Set<URI> uris, FileCache fileCache) {
// phase 2: include checking
var changedUris = new HashSet<>(uris);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/nextflow/lsp/services/script/ScriptAstCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import nextflow.lsp.ast.ASTNodeCache;
import nextflow.lsp.compiler.LanguageServerCompiler;
import nextflow.lsp.compiler.LanguageServerErrorCollector;
import nextflow.lsp.file.FileCache;
import nextflow.lsp.services.LanguageServerConfiguration;
import nextflow.script.ast.FunctionNode;
import nextflow.script.ast.IncludeNode;
import nextflow.script.ast.ProcessNode;
import nextflow.script.ast.ScriptNode;
import nextflow.script.ast.WorkflowNode;
import nextflow.script.control.ModuleResolver;
import nextflow.script.control.PhaseAware;
import nextflow.script.control.Phases;
import nextflow.script.control.ResolveIncludeVisitor;
Expand Down Expand Up @@ -86,7 +88,13 @@ public void initialize(String rootUri, LanguageServerConfiguration configuration
}

@Override
protected Set<URI> analyze(Set<URI> uris) {
protected Set<URI> analyze(Set<URI> uris, FileCache fileCache) {
// recursively load included modules
for( var uri : uris ) {
var source = compiler().getSource(uri);
new ModuleResolver(compiler()).resolve(source, (includeUri) -> compiler().newSourceUnit(includeUri, fileCache));
}

// phase 2: include checking
var changedUris = new HashSet<>(uris);

Expand Down
Loading