Skip to content

Commit

Permalink
fix: completion after comment & foldingRange crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas(Jiajie) Jing authored and Jonas(Jiajie) Jing committed Sep 27, 2024
1 parent ecc5423 commit 492b8d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
32 changes: 27 additions & 5 deletions server/src/python/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,43 @@ export const extractPythonCodes = (
end: pythonCodeEnd ?? symbol.range.end,
})
.split("\n");
let emptyLineCount = 0;

let startingEmptyLineCount = 0;
let firstNotEmptyLine: string | undefined = undefined;
for (const line of pythonCodeLines) {
if (line.trim().length > 0 && !line.trim().startsWith("#")) {
firstNotEmptyLine = line;
break;
} else {
emptyLineCount++;
startingEmptyLineCount++;
}
}
if (emptyLineCount > 0) {
pythonCodeLines.splice(0, emptyLineCount);
pythonCodeStart.line += emptyLineCount;
if (startingEmptyLineCount > 0) {
pythonCodeLines.splice(0, startingEmptyLineCount);
pythonCodeStart.line += startingEmptyLineCount;
pythonCodeStart.character = 0;
}

let tailingEmptyLineCount = 0;
for (let i = pythonCodeLines.length - 1; i >= 0; i--) {
if (
pythonCodeLines[i].trim().length === 0 ||
pythonCodeLines[i].trim().startsWith("#")
) {
tailingEmptyLineCount++;
} else {
break;
}
}
if (tailingEmptyLineCount > 0) {
pythonCodeLines.splice(pythonCodeLines.length - tailingEmptyLineCount);
if (pythonCodeEnd) {
pythonCodeEnd.line -= startingEmptyLineCount;
pythonCodeEnd.character =
pythonCodeLines[pythonCodeLines.length - 1].length;
}
}

const shouldAddDummyBlock: boolean =
!!firstNotEmptyLine && [" ", "\t"].includes(firstNotEmptyLine[0]);
const lineGap = pythonCodeStart.line - pythonDocLines.length;
Expand Down
5 changes: 2 additions & 3 deletions server/src/sas/CodeZoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ export class CodeZoneManager {
text = "",
col = 0,
type: Token["type"] = "text",
i = 0,
token = null;
i = 0;
const lineCount = this._model.getLineCount();

if (context.line >= lineCount) {
Expand Down Expand Up @@ -395,7 +394,7 @@ export class CodeZoneManager {
} while (/^\s*$/.test(text));

if (Lexer.isComment[type] || Lexer.isLiteral[type]) {
token = this._token(context.line, col - 1)!;
const token = this._token(context.line, col)!;
if (!token) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/sas/formatter/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const preserveProcs = (
"text" in region.children[0].children[1] &&
/^(python|lua)$/i.test(region.children[0].children[1].text) &&
"text" in region.children[1].children[0] &&
/^(submit|interactive)$/i.test(region.children[1].children[0].text)
/^(submit|interactive|i)$/i.test(region.children[1].children[0].text)
) {
current = 0;
}
Expand Down

0 comments on commit 492b8d8

Please sign in to comment.