diff --git a/server/src/sas/LanguageServiceProvider.ts b/server/src/sas/LanguageServiceProvider.ts index b75d937c8..5fdf8f1e2 100644 --- a/server/src/sas/LanguageServiceProvider.ts +++ b/server/src/sas/LanguageServiceProvider.ts @@ -188,6 +188,7 @@ export class LanguageServiceProvider { getFoldingRanges(): FoldingRange[] { const lineCount = this.model.getLineCount(); const result: FoldingRange[] = []; + this.addCommentFolding(result); for (let i = 0; i < lineCount; i++) { const rootBlock = this.syntaxProvider.getFoldingBlock( @@ -210,9 +211,21 @@ export class LanguageServiceProvider { continue; } } + return result; } + private addCommentFolding(result: FoldingRange[]) { + // Get multiline comments directly from lexer token processing + const commentRanges = this.syntaxProvider.getMultilineComments(); + for (const range of commentRanges) { + result.push({ + startLine: range.startLine, + endLine: range.endLine, + kind: "comment", + }); + } + } // DFS private _flattenFoldingBlockTree(rootBlock: FoldingBlock): FoldingBlock[] { const stack: FoldingBlock[] = [rootBlock]; diff --git a/server/src/sas/SyntaxProvider.ts b/server/src/sas/SyntaxProvider.ts index 45d6f6b01..537d8929f 100644 --- a/server/src/sas/SyntaxProvider.ts +++ b/server/src/sas/SyntaxProvider.ts @@ -29,6 +29,8 @@ export class SyntaxProvider { private tailUnchangedSyntaxTable: SyntaxToken[][] = []; private removedSyntaxTable: SyntaxToken[][] = []; private _tokenCallback: ((token: Token) => void) | undefined; + private _multilineComments: Array<{ startLine: number; endLine: number }> = + []; public blockComment = { start: "/*", end: "*/" }; public lexer; @@ -45,6 +47,7 @@ export class SyntaxProvider { let startLine = 0; this.currTokenIndex = 0; this.lastToken = null; + this._multilineComments = []; // Clear previous comments this.parsingState = 1; //LanguageService.ParsingState.STARTING; this.parsedRange = this.lexer.start(change); @@ -345,6 +348,17 @@ export class SyntaxProvider { end: { line: token.end.line, column: token.end.column }, }); } + + // Collect multiline comments as they're processed by the lexer + if ( + (token.type === "comment" || token.type === "macro-comment") && + token.end.line > token.start.line + ) { + this._multilineComments.push({ + startLine: token.start.line, + endLine: token.end.line, + }); + } } // public functions @@ -423,4 +437,7 @@ export class SyntaxProvider { } return block.name; } + getMultilineComments(): Array<{ startLine: number; endLine: number }> { + return this._multilineComments; + } }