diff --git a/modules/language-server/src/main/java/nextflow/lsp/ast/ASTNodeCache.java b/modules/language-server/src/main/java/nextflow/lsp/ast/ASTNodeCache.java index 6a57ded..2d14fd1 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/ast/ASTNodeCache.java +++ b/modules/language-server/src/main/java/nextflow/lsp/ast/ASTNodeCache.java @@ -379,9 +379,10 @@ public String getSourceText(ASTNode node, boolean leadingIndent, int maxLines) { var last = node.getLastLineNumber(); var firstCol = node.getColumnNumber(); var lastCol = node.getLastColumnNumber(); - if( maxLines != -1 && first + maxLines < last ) - last = first + maxLines; - for( int i = first; i <= last; i++ ) { + var lastWithMax = maxLines != -1 && first + maxLines < last + ? first + maxLines - 1 + : last; + for( int i = first; i <= lastWithMax; i++ ) { var line = sourceUnit.getSource().getLine(i, null); if( i == first && leadingIndent ) {