Skip to content

Improve rendering of DAG preview #131

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 16 commits into from
Aug 5, 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
6 changes: 4 additions & 2 deletions src/main/java/nextflow/lsp/NextflowLanguageServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {

var oldConfiguration = configuration;
configuration = new LanguageServerConfiguration(
withDefault(JsonUtils.getString(settings, "nextflow.dag.direction"), configuration.dagDirection()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.dag.verbose"), configuration.dagVerbose()),
withDefault(errorReportingMode(settings), configuration.errorReportingMode()),
withDefault(JsonUtils.getStringArray(settings, "nextflow.files.exclude"), configuration.excludePatterns()),
withDefault(JsonUtils.getBoolean(settings, "nextflow.completion.extended"), configuration.extendedCompletion()),
Expand Down Expand Up @@ -553,14 +555,14 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
var uri = JsonUtils.getString(arguments.get(0));
var service = getLanguageService(uri);
if( service != null )
return service.executeCommand(command, arguments);
return service.executeCommand(command, arguments, configuration);
}
if( "nextflow.server.previewWorkspace".equals(command) && arguments.size() == 1 ) {
log.debug(String.format("textDocument/previewWorkspace %s", arguments.toString()));
var name = JsonUtils.getString(arguments.get(0));
var service = scriptServices.get(name);
if( service != null )
return service.executeCommand(command, arguments);
return service.executeCommand(command, arguments, configuration);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.List;

public record LanguageServerConfiguration(
String dagDirection,
boolean dagVerbose,
ErrorReportingMode errorReportingMode,
List<String> excludePatterns,
boolean extendedCompletion,
Expand All @@ -31,6 +33,8 @@ public record LanguageServerConfiguration(

public static LanguageServerConfiguration defaults() {
return new LanguageServerConfiguration(
"TB",
false,
ErrorReportingMode.WARNINGS,
Collections.emptyList(),
false,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nextflow/lsp/services/LanguageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(DocumentSy
return provider.documentSymbol(params.getTextDocument());
}

public Object executeCommand(String command, List<Object> arguments) {
public Object executeCommand(String command, List<Object> arguments, LanguageServerConfiguration configuration) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ public List<CodeLens> codeLens(TextDocumentIdentifier textDocument) {
return result;
}

public Map<String,String> previewDag(String documentUri, String name) {
public Map<String,String> previewDag(String documentUri, String name, String direction, boolean verbose) {
var uri = URI.create(documentUri);
if( !ast.hasAST(uri) || ast.hasErrors(uri) )
return Map.ofEntries(Map.entry("error", "DAG preview cannot be shown because the script has errors."));
return Map.of("error", "DAG preview cannot be shown because the script has errors.");

var sourceUnit = ast.getSourceUnit(uri);
return ast.getWorkflowNodes(uri).stream()
.filter(wn -> wn.isEntry() ? name == null : wn.getName().equals(name))
.findFirst()
.map((wn) -> {
var visitor = new DataflowVisitor(sourceUnit, ast);
var visitor = new DataflowVisitor(sourceUnit, ast, verbose);
visitor.visit();

var graph = visitor.getGraph(wn.isEntry() ? "<entry>" : wn.getName());
var result = new MermaidRenderer().render(wn.getName(), graph);
var result = new MermaidRenderer(direction, verbose).render(wn.getName(), graph);
log.debug(result);
return Map.ofEntries(Map.entry("result", result));
return Map.of("result", result);
})
.orElse(null);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nextflow/lsp/services/script/ScriptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ protected SymbolProvider getSymbolProvider() {
}

@Override
public Object executeCommand(String command, List<Object> arguments) {
public Object executeCommand(String command, List<Object> arguments, LanguageServerConfiguration configuration) {
updateNow();
if( "nextflow.server.previewDag".equals(command) && arguments.size() == 2 ) {
var uri = getJsonString(arguments.get(0));
var name = getJsonString(arguments.get(1));
var provider = new ScriptCodeLensProvider(astCache);
return provider.previewDag(uri, name);
return provider.previewDag(uri, name, configuration.dagDirection(), configuration.dagVerbose());
}
if( "nextflow.server.previewWorkspace".equals(command) ) {
var provider = new WorkspacePreviewProvider(astCache);
Expand Down
Loading