diff --git a/modules/compiler/src/main/java/script/parser/PositionConfigureUtils.java b/modules/compiler/src/main/java/script/parser/PositionConfigureUtils.java index 4b60f97..840ecad 100644 --- a/modules/compiler/src/main/java/script/parser/PositionConfigureUtils.java +++ b/modules/compiler/src/main/java/script/parser/PositionConfigureUtils.java @@ -136,6 +136,11 @@ public static T ast(T astNode, ASTNode start, ASTNode stop) return astNode; } + /** + * Get the zero-based start position (line, character) of a token. + * + * @param ctx + */ public static TokenPosition tokenPosition(ParserRuleContext ctx) { var token = ctx.getStart(); return new TokenPosition( diff --git a/modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java b/modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java index be8f509..a7946f7 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java +++ b/modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java @@ -172,7 +172,7 @@ public CompletableFuture initialize(InitializeParams params) { var semanticTokensOptions = new SemanticTokensWithRegistrationOptions( new SemanticTokensLegend( SemanticTokensVisitor.TOKEN_TYPES, - List.of() + Collections.emptyList() ), true, false); diff --git a/modules/language-server/src/main/java/nextflow/lsp/services/SemanticTokensVisitor.java b/modules/language-server/src/main/java/nextflow/lsp/services/SemanticTokensVisitor.java index 4969596..607d7e5 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/services/SemanticTokensVisitor.java +++ b/modules/language-server/src/main/java/nextflow/lsp/services/SemanticTokensVisitor.java @@ -108,7 +108,7 @@ public SemanticTokens getTokens() { 0 )) .collect(Collectors.toList()); - + return new SemanticTokens(data); } @@ -186,19 +186,17 @@ public void visitGStringExpression(GStringExpression node) { inGString = igs; } -} - + private static record SemanticToken( + Position position, + int length, + String type + ) {} -record SemanticToken( - Position position, - int length, - String type -) {} + private static record SemanticTokenDelta( + int deltaLine, + int deltaStartChar, + int length, + String type + ) {} - -record SemanticTokenDelta( - int deltaLine, - int deltaStartChar, - int length, - String type -) {} +} diff --git a/modules/language-server/src/main/java/nextflow/lsp/services/config/ConfigSemanticTokensProvider.java b/modules/language-server/src/main/java/nextflow/lsp/services/config/ConfigSemanticTokensProvider.java index c96ce2e..368d347 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/services/config/ConfigSemanticTokensProvider.java +++ b/modules/language-server/src/main/java/nextflow/lsp/services/config/ConfigSemanticTokensProvider.java @@ -61,43 +61,43 @@ public SemanticTokens semanticTokensFull(TextDocumentIdentifier textDocument) { } private static class Visitor extends ConfigVisitorSupport { - + private SourceUnit sourceUnit; - + private SemanticTokensVisitor tok; - + public Visitor(SourceUnit sourceUnit) { this.sourceUnit = sourceUnit; this.tok = new SemanticTokensVisitor(); } - + @Override protected SourceUnit getSourceUnit() { return sourceUnit; } - + public void visit() { var moduleNode = sourceUnit.getAST(); if( moduleNode instanceof ConfigNode cn ) super.visit(cn); } - + public SemanticTokens getTokens() { return tok.getTokens(); } - + // config statements - + @Override public void visitConfigAssign(ConfigAssignNode node) { tok.visit(node.value); } - + @Override public void visitConfigInclude(ConfigIncludeNode node) { tok.visit(node.source); } - + } } diff --git a/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptSemanticTokensProvider.java b/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptSemanticTokensProvider.java index 0750d6c..abbae92 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptSemanticTokensProvider.java +++ b/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptSemanticTokensProvider.java @@ -75,36 +75,36 @@ public SemanticTokens semanticTokensFull(TextDocumentIdentifier textDocument) { } private static class Visitor extends ScriptVisitorSupport { - + private SourceUnit sourceUnit; - + private SemanticTokensVisitor tok; - + public Visitor(SourceUnit sourceUnit) { this.sourceUnit = sourceUnit; this.tok = new SemanticTokensVisitor(); } - + @Override protected SourceUnit getSourceUnit() { return sourceUnit; } - + public void visit() { var moduleNode = sourceUnit.getAST(); if( moduleNode instanceof ScriptNode sn ) visit(sn); } - + public SemanticTokens getTokens() { return tok.getTokens(); } - + @Override public void visitFeatureFlag(FeatureFlagNode node) { tok.visit(node.value); } - + @Override public void visitInclude(IncludeNode node) { for( var module : node.modules ) { @@ -113,33 +113,33 @@ public void visitInclude(IncludeNode node) { tok.append(module.getNodeMetaData("_START_ALIAS"), module.alias, SemanticTokenTypes.Function); } } - + @Override public void visitParam(ParamNode node) { tok.visit(node.target); tok.visit(node.value); } - + @Override public void visitWorkflow(WorkflowNode node) { if( node.takes instanceof BlockStatement block ) visitWorkflowTakes(block.getStatements()); - + tok.visit(node.main); - + if( node.emits instanceof BlockStatement block ) visitWorkflowEmits(block.getStatements()); - + tok.visit(node.publishers); } - + protected void visitWorkflowTakes(List takes) { for( var stmt : takes ) { var ve = (VariableExpression) asVarX(stmt); tok.append(ve, SemanticTokenTypes.Parameter); } } - + protected void visitWorkflowEmits(List emits) { for( var stmt : emits ) { var es = (ExpressionStatement)stmt; @@ -160,7 +160,7 @@ else if( emit instanceof VariableExpression ve ) { } } } - + @Override public void visitProcess(ProcessNode node) { tok.visit(node.directives); @@ -170,30 +170,30 @@ public void visitProcess(ProcessNode node) { tok.visit(node.exec); tok.visit(node.stub); } - + @Override public void visitFunction(FunctionNode node) { tok.visitParameters(node.getParameters()); tok.visit(node.getCode()); } - + @Override public void visitEnum(ClassNode node) { for( var fn : node.getFields() ) tok.append(fn, SemanticTokenTypes.EnumMember); } - + @Override public void visitOutput(OutputNode node) { visitOutputBody(node.body); } - + protected void visitOutputBody(Statement body) { asBlockStatements(body).forEach((stmt) -> { var call = asMethodCallX(stmt); if( call == null ) return; - + var code = asDslBlock(call, 1); if( code != null ) { tok.append(call.getMethod(), SemanticTokenTypes.Parameter); @@ -201,7 +201,7 @@ protected void visitOutputBody(Statement body) { } }); } - + } }