document formatting: format composed parameter
This commit is contained in:
parent
3f47c16aaa
commit
e702be53e7
|
@ -1,6 +1,5 @@
|
||||||
import CMakeLexer from "./parser/CMakeLexer";
|
import CMakeLexer from "./parser/CMakeLexer";
|
||||||
import CMakeListener from "./parser/CMakeListener";
|
import CMakeListener from "./parser/CMakeListener";
|
||||||
import { incToBaseDir } from "./symbolTable/goToDefination";
|
|
||||||
|
|
||||||
export class Formatter extends CMakeListener {
|
export class Formatter extends CMakeListener {
|
||||||
private _indent: number;
|
private _indent: number;
|
||||||
|
@ -144,15 +143,29 @@ export class Formatter extends CMakeListener {
|
||||||
const lParenIndex: number = argCtx.LParen().symbol.tokenIndex;
|
const lParenIndex: number = argCtx.LParen().symbol.tokenIndex;
|
||||||
result += this.getHiddenTextOnRight(lParenIndex, indent);
|
result += this.getHiddenTextOnRight(lParenIndex, indent);
|
||||||
const innerCnt = argCtx.argument().length;
|
const innerCnt = argCtx.argument().length;
|
||||||
|
const innerIndent = indent + this._indent;
|
||||||
|
let prevLineNo: number = argCtx.LParen().symbol.line;
|
||||||
argCtx.argument().forEach((innerCtx, index) => {
|
argCtx.argument().forEach((innerCtx, index) => {
|
||||||
|
const curLineNo: number = innerCtx.stop.line;
|
||||||
|
if (curLineNo !== prevLineNo) {
|
||||||
|
result += ' '.repeat(innerIndent);
|
||||||
|
}
|
||||||
result += this.getArgumentText(innerCtx, indent);
|
result += this.getArgumentText(innerCtx, indent);
|
||||||
if (index < innerCnt - 1) {
|
if (index < innerCnt - 1) {
|
||||||
result += ' ';
|
result += ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevLineNo = curLineNo;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rParenToken = argCtx.RParen().symbol;
|
||||||
|
if ((innerCnt > 0) &&
|
||||||
|
(argCtx.argument()[innerCnt-1].stop.line !== rParenToken.line)){
|
||||||
|
result += ' '.repeat(indent);
|
||||||
|
}
|
||||||
|
|
||||||
result += ')';
|
result += ')';
|
||||||
const rParenIndex: number = argCtx.RParen().symbol.tokenIndex;
|
result += this.getHiddenTextOnRight(rParenToken.tokenIndex, indent);
|
||||||
result += this.getHiddenTextOnRight(rParenIndex, indent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -194,12 +207,12 @@ export class Formatter extends CMakeListener {
|
||||||
|
|
||||||
const next = index + 1;
|
const next = index + 1;
|
||||||
if (next < cnt) {
|
if (next < cnt) {
|
||||||
if (array[next].start.line === curLineNo) {
|
if (array[next].start.line === argCtx.stop.line) {
|
||||||
this._formatted += ' ';
|
this._formatted += ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prevLineNo = curLineNo;
|
prevLineNo = argCtx.stop.line;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue