mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
createContextString:
Improve formatting somewhat
This commit is contained in:
parent
17c410eae2
commit
2fdd176dd6
@ -165,26 +165,17 @@ function createContextString(context: pl.LexNode[], line: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let contextString: string = `Line ${line + 1}`; // 1 based
|
let contextString: string = `Line ${line + 1}`; // 1 based
|
||||||
|
// Print the current line
|
||||||
if (context[0].token && context[0].token.attr) {
|
if (context[0].token && context[0].token.attr) {
|
||||||
let tokenTypeString: string = ` ${context[0].token.type.toString()}`;
|
let tokenTypeString: string = `${context[0].token.type.toString()}`;
|
||||||
contextString += `:${tokenTypeString !== 'INDENT'?tokenTypeString:" "
|
contextString += `: ${tokenTypeString !== 'INDENT'?tokenTypeString:""
|
||||||
} ${context[0].token.attr.toString()}`;
|
} ${context[0].token.attr.toString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i: number = 1; i < context.length; i++) {
|
for (let i: number = 1; i < context.length; i++) {
|
||||||
const node: pl.LexNode = context[i];
|
const node: pl.LexNode = context[i];
|
||||||
const inside: string = "in";
|
const inside: string = "in";
|
||||||
if (node.label === 'root') {
|
// Node contains information relevant to the current line
|
||||||
// root
|
|
||||||
if (vscode.window.activeTextEditor?.document.uri) {
|
|
||||||
contextString += ` ${inside} ${vscode.workspace.asRelativePath(vscode.window.activeTextEditor?.document.uri)}`;
|
|
||||||
} else {
|
|
||||||
contextString += ` ${inside} the Document`;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.token && node.token.type !== pl.PylexSymbol.EMPTY &&
|
if (node.token && node.token.type !== pl.PylexSymbol.EMPTY &&
|
||||||
node.token.type !== pl.PylexSymbol.INDENT) {
|
node.token.type !== pl.PylexSymbol.INDENT) {
|
||||||
contextString += ` ${inside} ${node.token.type.toString()}`;
|
contextString += ` ${inside} ${node.token.type.toString()}`;
|
||||||
@ -192,6 +183,16 @@ function createContextString(context: pl.LexNode[], line: number): string {
|
|||||||
contextString += ` ${node.token.attr.toString()}`;
|
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;
|
return contextString;
|
||||||
|
Loading…
Reference in New Issue
Block a user