Skip to content

Commit d23a06a

Browse files
authored
feat(LanguageServiceProvider): added code comment collapsing (#1638)
* feat(LanguageServiceProvider): added code comment collapsing Signed-off-by: Kishan Patel <[email protected]> * feat(LanguageServiceProvider): refactored comment detection Signed-off-by: Kishan Patel <[email protected]> * feat(LanguageServiceProvider): refactored logic to be in addItem() Signed-off-by: Kishan Patel <[email protected]> * feat(LanguageServiceProvider): addresed nits Signed-off-by: Kishan Patel <[email protected]> * feat(LanguageServiceProvider): added back method accidentally removed Signed-off-by: Kishan Patel <[email protected]> --------- Signed-off-by: Kishan Patel <[email protected]>
1 parent eb2d67a commit d23a06a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

server/src/sas/LanguageServiceProvider.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class LanguageServiceProvider {
188188
getFoldingRanges(): FoldingRange[] {
189189
const lineCount = this.model.getLineCount();
190190
const result: FoldingRange[] = [];
191+
this.addCommentFolding(result);
191192

192193
for (let i = 0; i < lineCount; i++) {
193194
const rootBlock = this.syntaxProvider.getFoldingBlock(
@@ -210,9 +211,21 @@ export class LanguageServiceProvider {
210211
continue;
211212
}
212213
}
214+
213215
return result;
214216
}
217+
private addCommentFolding(result: FoldingRange[]) {
218+
// Get multiline comments directly from lexer token processing
219+
const commentRanges = this.syntaxProvider.getMultilineComments();
215220

221+
for (const range of commentRanges) {
222+
result.push({
223+
startLine: range.startLine,
224+
endLine: range.endLine,
225+
kind: "comment",
226+
});
227+
}
228+
}
216229
// DFS
217230
private _flattenFoldingBlockTree(rootBlock: FoldingBlock): FoldingBlock[] {
218231
const stack: FoldingBlock[] = [rootBlock];

server/src/sas/SyntaxProvider.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class SyntaxProvider {
2929
private tailUnchangedSyntaxTable: SyntaxToken[][] = [];
3030
private removedSyntaxTable: SyntaxToken[][] = [];
3131
private _tokenCallback: ((token: Token) => void) | undefined;
32+
private _multilineComments: Array<{ startLine: number; endLine: number }> =
33+
[];
3234

3335
public blockComment = { start: "/*", end: "*/" };
3436
public lexer;
@@ -45,6 +47,7 @@ export class SyntaxProvider {
4547
let startLine = 0;
4648
this.currTokenIndex = 0;
4749
this.lastToken = null;
50+
this._multilineComments = []; // Clear previous comments
4851
this.parsingState = 1; //LanguageService.ParsingState.STARTING;
4952
this.parsedRange = this.lexer.start(change);
5053

@@ -345,6 +348,17 @@ export class SyntaxProvider {
345348
end: { line: token.end.line, column: token.end.column },
346349
});
347350
}
351+
352+
// Collect multiline comments as they're processed by the lexer
353+
if (
354+
(token.type === "comment" || token.type === "macro-comment") &&
355+
token.end.line > token.start.line
356+
) {
357+
this._multilineComments.push({
358+
startLine: token.start.line,
359+
endLine: token.end.line,
360+
});
361+
}
348362
}
349363

350364
// public functions
@@ -423,4 +437,7 @@ export class SyntaxProvider {
423437
}
424438
return block.name;
425439
}
440+
getMultilineComments(): Array<{ startLine: number; endLine: number }> {
441+
return this._multilineComments;
442+
}
426443
}

0 commit comments

Comments
 (0)