Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prefix with selection text #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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;
let match;
while (match = logRegex.exec(documentText)) {
Expand Down Expand Up @@ -55,11 +54,11 @@ function activate(context) {

const selection = editor.selection;
const text = editor.document.getText(selection);

const prefix = vscode.workspace.getConfiguration('js-console-utils').prefix;
text
? vscode.commands.executeCommand('editor.action.insertLineAfter')
.then(() => {
const logToInsert = `console.log('${text}: ', ${text});`;
const logToInsert = `console.log('${prefix}${text}: ', ${text});`;
insertText(logToInsert);
})
: insertText('console.log();');
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -53,4 +64,4 @@
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
}
}
}