Skip to content

Commit f9092dc

Browse files
authored
fix: proc python auto-indent (#1377)
1 parent f2d06d3 commit f9092dc

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

server/src/sas/FormatOnTypeProvider.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@ export class FormatOnTypeProvider {
351351
curToken.style === Lexer.TOKEN_TYPES.MKEYWORD ||
352352
curToken.style === Lexer.TOKEN_TYPES.MSKEYWORD
353353
) {
354+
if (
355+
curToken.style === Lexer.TOKEN_TYPES.KEYWORD &&
356+
/^(submit|interactive|i)$/i.test(curTokenText)
357+
) {
358+
const block = this.syntaxProvider.getFoldingBlock(
359+
curLine,
360+
curIndex,
361+
true,
362+
true,
363+
true,
364+
);
365+
if (
366+
block &&
367+
block.type === LexerEx.SEC_TYPE.PROC &&
368+
this.syntaxProvider.getSymbolName(block) === "PROC PYTHON"
369+
) {
370+
return -curIndent;
371+
}
372+
}
354373
if (
355374
curTokenText.toUpperCase() === "DATA" ||
356375
curTokenText.toUpperCase() === "PROC" ||

server/src/sas/LanguageServiceProvider.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class LanguageServiceProvider {
170170
end: { line: block.endFoldingLine, character: block.endFoldingCol },
171171
};
172172
const docSymbol: DocumentSymbol = {
173-
name: this._getSymbolName(block),
173+
name: this.syntaxProvider.getSymbolName(block),
174174
kind: SymbolKinds[block.type],
175175
range,
176176
selectionRange: range,
@@ -246,32 +246,4 @@ export class LanguageServiceProvider {
246246
setLibService(fn: LibService): void {
247247
return this.syntaxProvider.lexer.syntaxDb.setLibService(fn);
248248
}
249-
250-
private _getSymbolName(block: FoldingBlock) {
251-
const line = block.startLine;
252-
const tokens = this.syntaxProvider.getSyntax(line);
253-
for (let i = 2; i < tokens.length; i++) {
254-
const token = tokens[i];
255-
if (token.start <= block.startCol) {
256-
continue;
257-
}
258-
if (token.style === "proc-name" || token.style === "text") {
259-
const end =
260-
i === tokens.length - 1
261-
? this.model.getColumnCount(line)
262-
: tokens[i + 1].start;
263-
const tokenText = this.model.getText({
264-
start: { line, column: token.start },
265-
end: { line, column: end },
266-
});
267-
if (tokenText.trim() === "") {
268-
continue;
269-
}
270-
return `${block.name} ${
271-
token.style === "proc-name" ? tokenText.toUpperCase() : tokenText
272-
}`;
273-
}
274-
}
275-
return block.name;
276-
}
277249
}

server/src/sas/SyntaxProvider.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,31 @@ export class SyntaxProvider {
397397
setTokenCallback(cb: ((token: Token) => void) | undefined): void {
398398
this._tokenCallback = cb;
399399
}
400+
getSymbolName(block: FoldingBlock) {
401+
const line = block.startLine;
402+
const tokens = this.getSyntax(line);
403+
for (let i = 2; i < tokens.length; i++) {
404+
const token = tokens[i];
405+
if (token.start <= block.startCol) {
406+
continue;
407+
}
408+
if (token.style === "proc-name" || token.style === "text") {
409+
const end =
410+
i === tokens.length - 1
411+
? this.model.getColumnCount(line)
412+
: tokens[i + 1].start;
413+
const tokenText = this.model.getText({
414+
start: { line, column: token.start },
415+
end: { line, column: end },
416+
});
417+
if (tokenText.trim() === "") {
418+
continue;
419+
}
420+
return `${block.name} ${
421+
token.style === "proc-name" ? tokenText.toUpperCase() : tokenText
422+
}`;
423+
}
424+
}
425+
return block.name;
426+
}
400427
}

0 commit comments

Comments
 (0)