From 73f2de05a474ec8ce30a911c7c84caa1f30791e2 Mon Sep 17 00:00:00 2001 From: leoytliu Date: Wed, 21 Nov 2018 17:50:59 +0800 Subject: [PATCH 1/3] support prefix before logging --- extension.js | 10 ++++++---- package.json | 13 ++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/extension.js b/extension.js index 2944408..190a9e9 100644 --- a/extension.js +++ b/extension.js @@ -19,8 +19,9 @@ const insertText = (val) => { function getAllLogStatements(document, documentText) { let logStatements = []; - - const logRegex = /console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?/g; + const prefix = vscode.workspace.getConfiguration('js-console-utils').prefix; + // const logRegex = /console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?/g; + const logRegex = new RegExp(prefix + 'console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?', 'g'); let match; while (match = logRegex.exec(documentText)) { let matchRange = @@ -55,11 +56,12 @@ function activate(context) { const selection = editor.selection; const text = editor.document.getText(selection); - + const prefix = vscode.workspace.getConfiguration('js-console-utils').prefix; + console.log('get prefix configuration of js-console-utils', prefix); text ? vscode.commands.executeCommand('editor.action.insertLineAfter') .then(() => { - const logToInsert = `console.log('${text}: ', ${text});`; + const logToInsert = `${prefix}console.log('${text}: ', ${text});`; insertText(logToInsert); }) : insertText('console.log();'); diff --git a/package.json b/package.json index 49753e2..a53a59c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,17 @@ ], "main": "./extension", "contributes": { + "configuration": { + "type": "object", + "title": "Js console utils configuration", + "properties": { + "js-console-utils.prefix": { + "type": "string", + "default": "", + "description": "Add prefix before the variable name when printed in console." + } + } + }, "commands": [ { "command": "extension.insertLogStatement", @@ -53,4 +64,4 @@ "@types/node": "^6.0.40", "@types/mocha": "^2.2.32" } -} \ No newline at end of file +} From 60fd7a800965195da82975cd680d3b848b4622db Mon Sep 17 00:00:00 2001 From: leoytliu Date: Wed, 21 Nov 2018 18:15:52 +0800 Subject: [PATCH 2/3] fix position of prefix --- extension.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extension.js b/extension.js index 190a9e9..60ac591 100644 --- a/extension.js +++ b/extension.js @@ -19,9 +19,7 @@ const insertText = (val) => { function getAllLogStatements(document, documentText) { let logStatements = []; - const prefix = vscode.workspace.getConfiguration('js-console-utils').prefix; - // const logRegex = /console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?/g; - const logRegex = new RegExp(prefix + 'console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?', 'g'); + const logRegex = /console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?/g; let match; while (match = logRegex.exec(documentText)) { let matchRange = @@ -61,7 +59,7 @@ function activate(context) { text ? vscode.commands.executeCommand('editor.action.insertLineAfter') .then(() => { - const logToInsert = `${prefix}console.log('${text}: ', ${text});`; + const logToInsert = `console.log('${prefix}${text}: ', ${text});`; insertText(logToInsert); }) : insertText('console.log();'); From c714068fea548062f79c2c8099be4ca946c5f6da Mon Sep 17 00:00:00 2001 From: leoytliu Date: Fri, 23 Nov 2018 11:43:21 +0800 Subject: [PATCH 3/3] remove console.log --- extension.js | 1 - 1 file changed, 1 deletion(-) diff --git a/extension.js b/extension.js index 60ac591..1803aeb 100644 --- a/extension.js +++ b/extension.js @@ -55,7 +55,6 @@ function activate(context) { const selection = editor.selection; const text = editor.document.getText(selection); const prefix = vscode.workspace.getConfiguration('js-console-utils').prefix; - console.log('get prefix configuration of js-console-utils', prefix); text ? vscode.commands.executeCommand('editor.action.insertLineAfter') .then(() => {