Skip to content

Commit

Permalink
fix: proc python auto-indent (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
scnwwu authored Jan 27, 2025
1 parent f2d06d3 commit f9092dc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
19 changes: 19 additions & 0 deletions server/src/sas/FormatOnTypeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,25 @@ export class FormatOnTypeProvider {
curToken.style === Lexer.TOKEN_TYPES.MKEYWORD ||
curToken.style === Lexer.TOKEN_TYPES.MSKEYWORD
) {
if (
curToken.style === Lexer.TOKEN_TYPES.KEYWORD &&
/^(submit|interactive|i)$/i.test(curTokenText)
) {
const block = this.syntaxProvider.getFoldingBlock(
curLine,
curIndex,
true,
true,
true,
);
if (
block &&
block.type === LexerEx.SEC_TYPE.PROC &&
this.syntaxProvider.getSymbolName(block) === "PROC PYTHON"
) {
return -curIndent;
}
}
if (
curTokenText.toUpperCase() === "DATA" ||
curTokenText.toUpperCase() === "PROC" ||
Expand Down
30 changes: 1 addition & 29 deletions server/src/sas/LanguageServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class LanguageServiceProvider {
end: { line: block.endFoldingLine, character: block.endFoldingCol },
};
const docSymbol: DocumentSymbol = {
name: this._getSymbolName(block),
name: this.syntaxProvider.getSymbolName(block),
kind: SymbolKinds[block.type],
range,
selectionRange: range,
Expand Down Expand Up @@ -246,32 +246,4 @@ export class LanguageServiceProvider {
setLibService(fn: LibService): void {
return this.syntaxProvider.lexer.syntaxDb.setLibService(fn);
}

private _getSymbolName(block: FoldingBlock) {
const line = block.startLine;
const tokens = this.syntaxProvider.getSyntax(line);
for (let i = 2; i < tokens.length; i++) {
const token = tokens[i];
if (token.start <= block.startCol) {
continue;
}
if (token.style === "proc-name" || token.style === "text") {
const end =
i === tokens.length - 1
? this.model.getColumnCount(line)
: tokens[i + 1].start;
const tokenText = this.model.getText({
start: { line, column: token.start },
end: { line, column: end },
});
if (tokenText.trim() === "") {
continue;
}
return `${block.name} ${
token.style === "proc-name" ? tokenText.toUpperCase() : tokenText
}`;
}
}
return block.name;
}
}
27 changes: 27 additions & 0 deletions server/src/sas/SyntaxProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,31 @@ export class SyntaxProvider {
setTokenCallback(cb: ((token: Token) => void) | undefined): void {
this._tokenCallback = cb;
}
getSymbolName(block: FoldingBlock) {
const line = block.startLine;
const tokens = this.getSyntax(line);
for (let i = 2; i < tokens.length; i++) {
const token = tokens[i];
if (token.start <= block.startCol) {
continue;
}
if (token.style === "proc-name" || token.style === "text") {
const end =
i === tokens.length - 1
? this.model.getColumnCount(line)
: tokens[i + 1].start;
const tokenText = this.model.getText({
start: { line, column: token.start },
end: { line, column: end },
});
if (tokenText.trim() === "") {
continue;
}
return `${block.name} ${
token.style === "proc-name" ? tokenText.toUpperCase() : tokenText
}`;
}
}
return block.name;
}
}

0 comments on commit f9092dc

Please sign in to comment.