From 3525963bb095771c0e0c7c0a3740b17d278bf771 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 23 Mar 2022 22:53:46 -0500 Subject: [PATCH] Switch from string concatination to interpolation Improves concision. --- src/commands/text.ts | 18 +++++++++--------- src/pylex/token.ts | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/commands/text.ts b/src/commands/text.ts index 03c4132..2ef811c 100755 --- a/src/commands/text.ts +++ b/src/commands/text.ts @@ -14,7 +14,7 @@ exports.textCommands = [ }, { name: 'mind-reader.getLeadingSpaces', - callback: getLeadingSpaces, + callback: getLeadingSpaces, }, { name: 'mind-reader.runLineContext', @@ -25,7 +25,7 @@ exports.textCommands = [ callback: runCursorContext } ]; -/* Helper Function +/* Helper Function * This function returns the line number of the active text editor window */ function fetchLineNumber(editor) { @@ -35,14 +35,14 @@ function fetchLineNumber(editor) { // Function that outputs the current line number the cursor is on function getLineNumber() { let editor = vscode.window.activeTextEditor; - + if (editor) { let lineNum = fetchLineNumber(editor); - vscode.window.showInformationMessage("Line " + lineNum.toString()); + vscode.window.showInformationMessage(`Line ${lineNum.toString()}`); } else { vscode.window.showErrorMessage('No document currently active'); - } + } } function getIndent() { @@ -51,7 +51,7 @@ function getIndent() { let lineNum = fetchLineNumber(editor); let textLine = editor.document.lineAt(lineNum - 1); if (textLine.isEmptyOrWhitespace) { - vscode.window.showInformationMessage("Line number " + lineNum.toString() + " Is Empty"); + vscode.window.showInformationMessage(`"Line ${lineNum.toString()} is Empty`); } else { // Grab tab format from open document @@ -60,7 +60,7 @@ function getIndent() { hard: !editor.options.insertSpaces }; let i = pl.Lexer.getIndent(textLine.text, tabFmt); - vscode.window.showInformationMessage("Line Number " + lineNum.toString() + " Indentation " + i.toString()); + vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indents`); } } else { @@ -78,12 +78,12 @@ function getLeadingSpaces() { let lineNum = fetchLineNumber(editor); let textLine = editor.document.lineAt(lineNum - 1); if(textLine.isEmptyOrWhitespace) { - vscode.window.showInformationMessage("Line number " + lineNum.toString() + " Is Empty"); + vscode.window.showInformationMessage(`Line ${lineNum.toString()} is empty`); } else { let numSpaces = textLine.firstNonWhitespaceCharacterIndex; // let numSpaces = textLine.text.length - textLine.text.trimStart().length; // Alternative method, same result by calculating the leading spaces - vscode.window.showInformationMessage("Line Number " + lineNum.toString() + " Has " + numSpaces.toString()+ " Leading Spaces "); + vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} spaces`); } } else { diff --git a/src/pylex/token.ts b/src/pylex/token.ts index b6a54e0..54e62be 100644 --- a/src/pylex/token.ts +++ b/src/pylex/token.ts @@ -53,7 +53,7 @@ export default class LineToken { * @return A string representation of the token */ toString(): string { - return this.type + ", linenr:" + (this.linenr+1) + ", indentLevel: " + this.indentLevel + ", attr: " + this.attr; + return `${this.type}, linenr: ${this.linenr+1}, indentLevel: ${this.indentLevel}, attr: ${this.attr}`; } }