createContextString:

Improve formatting somewhat
This commit is contained in:
John 2022-04-24 02:34:03 -07:00
parent 17c410eae2
commit 2fdd176dd6

View File

@ -165,7 +165,7 @@ function createContextString(context: pl.LexNode[], line: number): string {
}
let contextString: string = `Line ${line + 1}`; // 1 based
// Print the current line
if (context[0].token && context[0].token.attr) {
let tokenTypeString: string = `${context[0].token.type.toString()}`;
contextString += `: ${tokenTypeString !== 'INDENT'?tokenTypeString:""
@ -175,16 +175,7 @@ function createContextString(context: pl.LexNode[], line: number): string {
for (let i: number = 1; i < context.length; i++) {
const node: pl.LexNode = context[i];
const inside: string = "in";
if (node.label === 'root') {
// root
if (vscode.window.activeTextEditor?.document.uri) {
contextString += ` ${inside} ${vscode.workspace.asRelativePath(vscode.window.activeTextEditor?.document.uri)}`;
} else {
contextString += ` ${inside} the Document`;
}
continue;
}
// Node contains information relevant to the current line
if (node.token && node.token.type !== pl.PylexSymbol.EMPTY &&
node.token.type !== pl.PylexSymbol.INDENT) {
contextString += ` ${inside} ${node.token.type.toString()}`;
@ -192,6 +183,16 @@ function createContextString(context: pl.LexNode[], line: number): string {
contextString += ` ${node.token.attr.toString()}`;
}
}
// Node is the document root
if (node.label === 'root') {
// Append the name (relative path) of the document in the workspace
if (vscode.window.activeTextEditor?.document.uri) {
contextString += ` ${inside} ${vscode.workspace.asRelativePath(vscode.window.activeTextEditor?.document.uri)}`;
} else {
contextString += ` ${inside} the Document`;
}
continue;
}
}
return contextString;