Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/src/sas/LanguageServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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];
Expand Down
17 changes: 17 additions & 0 deletions server/src/sas/SyntaxProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -423,4 +437,7 @@ export class SyntaxProvider {
}
return block.name;
}
getMultilineComments(): Array<{ startLine: number; endLine: number }> {
return this._multilineComments;
}
}
Loading