Skip to content

Commit 9e35a28

Browse files
Improve rendering of DAG preview (#131)
--------- Signed-off-by: ErikDanielsson <[email protected]> Co-authored-by: Ben Sherman <[email protected]>
1 parent cf6ee9a commit 9e35a28

File tree

10 files changed

+1000
-193
lines changed

10 files changed

+1000
-193
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
450450

451451
var oldConfiguration = configuration;
452452
configuration = new LanguageServerConfiguration(
453+
withDefault(JsonUtils.getString(settings, "nextflow.dag.direction"), configuration.dagDirection()),
454+
withDefault(JsonUtils.getBoolean(settings, "nextflow.dag.verbose"), configuration.dagVerbose()),
453455
withDefault(errorReportingMode(settings), configuration.errorReportingMode()),
454456
withDefault(JsonUtils.getStringArray(settings, "nextflow.files.exclude"), configuration.excludePatterns()),
455457
withDefault(JsonUtils.getBoolean(settings, "nextflow.completion.extended"), configuration.extendedCompletion()),
@@ -553,14 +555,14 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
553555
var uri = JsonUtils.getString(arguments.get(0));
554556
var service = getLanguageService(uri);
555557
if( service != null )
556-
return service.executeCommand(command, arguments);
558+
return service.executeCommand(command, arguments, configuration);
557559
}
558560
if( "nextflow.server.previewWorkspace".equals(command) && arguments.size() == 1 ) {
559561
log.debug(String.format("textDocument/previewWorkspace %s", arguments.toString()));
560562
var name = JsonUtils.getString(arguments.get(0));
561563
var service = scriptServices.get(name);
562564
if( service != null )
563-
return service.executeCommand(command, arguments);
565+
return service.executeCommand(command, arguments, configuration);
564566
}
565567
return null;
566568
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.List;
2020

2121
public record LanguageServerConfiguration(
22+
String dagDirection,
23+
boolean dagVerbose,
2224
ErrorReportingMode errorReportingMode,
2325
List<String> excludePatterns,
2426
boolean extendedCompletion,
@@ -31,6 +33,8 @@ public record LanguageServerConfiguration(
3133

3234
public static LanguageServerConfiguration defaults() {
3335
return new LanguageServerConfiguration(
36+
"TB",
37+
false,
3438
ErrorReportingMode.WARNINGS,
3539
Collections.emptyList(),
3640
false,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(DocumentSy
230230
return provider.documentSymbol(params.getTextDocument());
231231
}
232232

233-
public Object executeCommand(String command, List<Object> arguments) {
233+
public Object executeCommand(String command, List<Object> arguments, LanguageServerConfiguration configuration) {
234234
return null;
235235
}
236236

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ public List<CodeLens> codeLens(TextDocumentIdentifier textDocument) {
7070
return result;
7171
}
7272

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

7878
var sourceUnit = ast.getSourceUnit(uri);
7979
return ast.getWorkflowNodes(uri).stream()
8080
.filter(wn -> wn.isEntry() ? name == null : wn.getName().equals(name))
8181
.findFirst()
8282
.map((wn) -> {
83-
var visitor = new DataflowVisitor(sourceUnit, ast);
83+
var visitor = new DataflowVisitor(sourceUnit, ast, verbose);
8484
visitor.visit();
8585

8686
var graph = visitor.getGraph(wn.isEntry() ? "<entry>" : wn.getName());
87-
var result = new MermaidRenderer().render(wn.getName(), graph);
87+
var result = new MermaidRenderer(direction, verbose).render(wn.getName(), graph);
8888
log.debug(result);
89-
return Map.ofEntries(Map.entry("result", result));
89+
return Map.of("result", result);
9090
})
9191
.orElse(null);
9292
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ protected SymbolProvider getSymbolProvider() {
121121
}
122122

123123
@Override
124-
public Object executeCommand(String command, List<Object> arguments) {
124+
public Object executeCommand(String command, List<Object> arguments, LanguageServerConfiguration configuration) {
125125
updateNow();
126126
if( "nextflow.server.previewDag".equals(command) && arguments.size() == 2 ) {
127127
var uri = getJsonString(arguments.get(0));
128128
var name = getJsonString(arguments.get(1));
129129
var provider = new ScriptCodeLensProvider(astCache);
130-
return provider.previewDag(uri, name);
130+
return provider.previewDag(uri, name, configuration.dagDirection(), configuration.dagVerbose());
131131
}
132132
if( "nextflow.server.previewWorkspace".equals(command) ) {
133133
var provider = new WorkspacePreviewProvider(astCache);

0 commit comments

Comments
 (0)