Skip to content

Commit 8821dd9

Browse files
committed
feat(LanguageServiceProvider): refactored logic to be in addItem()
Signed-off-by: Kishan Patel <[email protected]>
1 parent cb014d2 commit 8821dd9

File tree

2 files changed

+18
-52
lines changed

2 files changed

+18
-52
lines changed

server/src/sas/LanguageServiceProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ export class LanguageServiceProvider {
216216
}
217217

218218
private addCommentFolding(result: FoldingRange[]) {
219-
// Get all comment ranges from the lexer
220-
const commentRanges = this.syntaxProvider.getAllCommentRanges();
219+
// Get multiline comments directly from lexer token processing
220+
const commentRanges = this.syntaxProvider.getMultilineComments();
221221

222222
for (const range of commentRanges) {
223223
result.push({

server/src/sas/SyntaxProvider.ts

Lines changed: 16 additions & 50 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
@@ -426,55 +440,7 @@ export class SyntaxProvider {
426440
getTokenBlocks(): any[] {
427441
return this.lexer.tknBlks || [];
428442
}
429-
getAllCommentRanges(): Array<{ startLine: number; endLine: number }> {
430-
const ranges: Array<{ startLine: number; endLine: number }> = [];
431-
const lineCount = this.model.getLineCount();
432-
433-
// First, get comment blocks from lexer token blocks
434-
const tokenBlocks = this.getTokenBlocks();
435-
for (const block of tokenBlocks) {
436-
const isComment = block.blockComment === true || block.type === "comment";
437-
if (isComment && block.endLine > block.startLine) {
438-
ranges.push({
439-
startLine: block.startLine,
440-
endLine: block.endLine,
441-
});
442-
}
443-
}
444-
445-
// Then scan for any multiline comment tokens that might not be in token blocks
446-
for (let lineNum = 0; lineNum < lineCount; lineNum++) {
447-
const tokens = this.getSyntax(lineNum);
448-
449-
for (const token of tokens) {
450-
if (token.style === "comment" || token.style === "macro-comment") {
451-
// Check if this token indicates a multiline span
452-
if (
453-
token.state &&
454-
typeof token.state === "object" &&
455-
token.state.line !== undefined
456-
) {
457-
const endLine = token.state.line;
458-
if (endLine > lineNum) {
459-
// Check if this range is already covered
460-
const isAlreadyCovered = ranges.some(
461-
(range) =>
462-
range.startLine === lineNum && range.endLine === endLine,
463-
);
464-
465-
if (!isAlreadyCovered) {
466-
ranges.push({
467-
startLine: lineNum,
468-
endLine: endLine,
469-
});
470-
}
471-
}
472-
}
473-
break; // Only need first comment token per line
474-
}
475-
}
476-
}
477-
478-
return ranges;
443+
getMultilineComments(): Array<{ startLine: number; endLine: number }> {
444+
return this._multilineComments;
479445
}
480446
}

0 commit comments

Comments
 (0)