Skip to content

Commit f6f3329

Browse files
committed
Add formatting option for Mahesh form
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 24ba82d commit f6f3329

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

modules/compiler/src/main/java/script/formatter/Formatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
public class Formatter extends CodeVisitorSupport {
7070

7171
public static String prettyPrintTypeName(ClassNode type) {
72-
var fmt = new Formatter(new FormattingOptions(0, false, false));
72+
var fmt = new Formatter(new FormattingOptions(0, false));
7373
fmt.visitTypeName(type);
7474
return fmt.toString();
7575
}

modules/compiler/src/main/java/script/formatter/FormattingOptions.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
public record FormattingOptions(
1919
int tabSize,
2020
boolean insertSpaces,
21-
boolean harshilAlignment
22-
) {}
21+
boolean harshilAlignment,
22+
boolean maheshForm
23+
) {
24+
public FormattingOptions(int tabSize, boolean insertSpaces) {
25+
this(tabSize, insertSpaces, false, false);
26+
}
27+
}

modules/compiler/src/main/java/script/formatter/ScriptFormattingVisitor.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,8 @@ public void visitProcess(ProcessNode node) {
339339
visitDirectives(node.inputs);
340340
fmt.appendNewLine();
341341
}
342-
if( node.outputs instanceof BlockStatement ) {
343-
fmt.appendIndent();
344-
fmt.append("output:\n");
345-
visitDirectives(node.outputs);
342+
if( !options.maheshForm() && node.outputs instanceof BlockStatement ) {
343+
visitProcessOutputs(node.outputs);
346344
fmt.appendNewLine();
347345
}
348346
if( !(node.when instanceof EmptyExpression) ) {
@@ -362,10 +360,20 @@ public void visitProcess(ProcessNode node) {
362360
fmt.append("stub:\n");
363361
fmt.visit(node.stub);
364362
}
363+
if( options.maheshForm() && node.outputs instanceof BlockStatement ) {
364+
fmt.appendNewLine();
365+
visitProcessOutputs(node.outputs);
366+
}
365367
fmt.decIndent();
366368
fmt.append("}\n");
367369
}
368370

371+
private void visitProcessOutputs(Statement outputs) {
372+
fmt.appendIndent();
373+
fmt.append("output:\n");
374+
visitDirectives(outputs);
375+
}
376+
369377
@Override
370378
public void visitFunction(FunctionNode node) {
371379
fmt.appendLeadingComments(node);

modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public static void main(String[] args) {
129129

130130
private List<String> excludePatterns;
131131
private boolean harshilAlignment;
132+
private boolean maheshForm;
132133
private boolean paranoidWarnings;
133134

134135
// -- LanguageServer
@@ -371,7 +372,8 @@ public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormatting
371372
var options = new FormattingOptions(
372373
params.getOptions().getTabSize(),
373374
params.getOptions().isInsertSpaces(),
374-
harshilAlignment
375+
harshilAlignment,
376+
maheshForm
375377
);
376378
log.debug(String.format("textDocument/formatting %s %s %d", relativePath(uri), options.insertSpaces() ? "spaces" : "tabs", options.tabSize()));
377379
var service = getLanguageService(uri);
@@ -456,6 +458,10 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
456458
if( harshilAlignment != null )
457459
this.harshilAlignment = harshilAlignment;
458460

461+
var maheshForm = getJsonBoolean(params.getSettings(), "nextflow.formatting.maheshForm");
462+
if( maheshForm != null )
463+
this.maheshForm = maheshForm;
464+
459465
var paranoidWarnings = getJsonBoolean(params.getSettings(), "nextflow.paranoidWarnings");
460466
if( paranoidWarnings != null && this.paranoidWarnings != paranoidWarnings ) {
461467
this.paranoidWarnings = paranoidWarnings;

modules/language-server/src/main/java/nextflow/lsp/ast/ASTNodeStringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static String featureFlagToLabel(FeatureFlagNode node) {
9494
private static String workflowToLabel(WorkflowNode node) {
9595
if( node.isEntry() )
9696
return "workflow <entry>";
97-
var fmt = new Formatter(new FormattingOptions(2, true, false));
97+
var fmt = new Formatter(new FormattingOptions(2, true));
9898
fmt.append("workflow ");
9999
fmt.append(node.getName());
100100
fmt.append(" {\n");
@@ -134,7 +134,7 @@ private static String workflowToLabel(WorkflowNode node) {
134134
}
135135

136136
private static String processToLabel(ProcessNode node) {
137-
var fmt = new Formatter(new FormattingOptions(2, true, false));
137+
var fmt = new Formatter(new FormattingOptions(2, true));
138138
fmt.append("process ");
139139
fmt.append(node.getName());
140140
fmt.append(" {\n");

modules/language-server/src/test/groovy/nextflow/lsp/services/config/ConfigFormattingTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ConfigFormattingTest extends Specification {
3636
def uri = filePath.toUri()
3737
def textDocumentItem = new TextDocumentItem(uri.toString(), 'nextflow-config', 1, contents)
3838
service.didOpen(new DidOpenTextDocumentParams(textDocumentItem))
39-
def textEdits = service.formatting(uri, new FormattingOptions(4, true, false))
39+
def textEdits = service.formatting(uri, new FormattingOptions(4, true))
4040
return textEdits.first().getNewText()
4141
}
4242

modules/language-server/src/test/groovy/nextflow/lsp/services/script/ScriptFormattingTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ScriptFormattingTest extends Specification {
5050
def uri = filePath.toUri()
5151
def textDocumentItem = new TextDocumentItem(uri.toString(), 'nextflow', 1, contents)
5252
service.didOpen(new DidOpenTextDocumentParams(textDocumentItem))
53-
def textEdits = service.formatting(uri, new FormattingOptions(4, true, false))
53+
def textEdits = service.formatting(uri, new FormattingOptions(4, true))
5454
return textEdits.first().getNewText()
5555
}
5656

0 commit comments

Comments
 (0)