diff --git a/.gitignore b/.gitignore index dcd8530..d2059f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ out node_modules -*.vsix \ No newline at end of file +*.vsix +issues \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d6dfd27..bece16c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ # CHANGELOG +## 1.7.2 +##### 2019-02-19 + +### Fixed + +- Setting `.emptyLineAction` using wrong default value + +--- + ## 1.7.1 ##### 2019-01-15 @@ -18,19 +27,19 @@ ##### 2019-01-13 ### Added -- Setting `logFunctionName` has been added -- Setting `logString` has been added -- Setting `prefixFunctionName` has been added -- Setting `prefixString` has been added +- Setting `.logFunctionName` has been added +- Setting `.logString` has been added +- Setting `.prefixFunctionName` has been added +- Setting `.prefixString` has been added ### Changed -- Setting `setCursorOnNewLine` renamed to `configuration.moveToLine` -- Setting `cursorPositionNewLine` renamed to `configuration.moveToPosition` -- Setting `onEmptyLineAction` renamed to `configuration.emptyLineAction` +- Setting `.setCursorOnNewLine` renamed to `configuration.moveToLine` +- Setting `.cursorPositionNewLine` renamed to `configuration.moveToPosition` +- Setting `.onEmptyLineAction` renamed to `configuration.emptyLineAction` - Various settings descriptions ### Removed - - Setting `wrapText` has been removed in favor of the new custom log settings + - Setting `.wrapText` has been removed in favor of the new custom log settings ## More custom log support Get finer control over the inserted log string. It is now possible to set a custom function name for the default log command as well as the prefix command. diff --git a/package.json b/package.json index 5f69dab..1e8343e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/midnightsyntax/vscode-wrap-console-log" }, - "version": "1.7.1", + "version": "1.7.2", "publisher": "midnightsyntax", "icon": "images/icon.png", "engines": { @@ -54,7 +54,7 @@ "Replace empty" ], "markdownDescription": "Defines the default text action when logging to an empty line. \n\n`Insert and push` will push the target line in the direction of the log command. \n\n`Replace empty` will replace the target line. No existing rows will be moved.", - "default": "Insert" + "default": "Insert and push" }, "wrap-console-log.configuration.moveToLine": { "type": "string", diff --git a/src/extension.ts b/src/extension.ts index 2d55d6d..6bc91d1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,13 +2,31 @@ import * as vscode from 'vscode'; import { window, QuickPickItem, workspace } from 'vscode'; +import * as path from 'path'; +import * as fs from 'fs'; let currentEditor:vscode.TextEditor; +let currentContext:vscode.ExtensionContext; export function activate(context: vscode.ExtensionContext) { - + currentContext = context; currentEditor = vscode.window.activeTextEditor; - + var props = JSON.parse(fs.readFileSync(path.join(currentContext.extensionPath, 'package.json'), 'utf8')).contributes.configuration.properties; + Object.keys(props).forEach((prop, i) => { + let pName = prop.replace('wrap-console-log.',''); + let pObj = props[prop]; + let settingValue = getSetting(pName); + if (pObj) { + if (pObj.hasOwnProperty("enum")) { + console.log(`Checking enum config '${pName}'`); + let valueValid = pObj.enum.some(val => val == settingValue); + if (!valueValid) { + vscode.workspace.getConfiguration("wrap-console-log").update(pName, undefined); + console.log(`Invalid setting value! '${pName}' has been set to default value '${pObj.default}'`); + } + } + } + }); vscode.window.onDidChangeActiveTextEditor(editor => currentEditor = editor); context.subscriptions.push( @@ -212,14 +230,20 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: Form nxtNonEmpty = (nxtLine.isEmptyOrWhitespace) ? wrap.doc.lineAt(getTargetLine(Wrap.Down)) : undefined; } if (wrap.lastLine == false && nxtLine.isEmptyOrWhitespace) { - if (onEmptyAction == "Insert and push") { + function defaultAction() { e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character), "\n".concat((nxtLineInd > wrap.ind ? nxtLineInd : wrap.ind), wrap.txt)); + }; + if (onEmptyAction == "Insert and push") { + defaultAction(); } else if (onEmptyAction == "Replace empty") { if (nxtLine && (nxtNonEmpty.firstNonWhitespaceCharacterIndex > 0)) { e.replace(new vscode.Position(nxtLine.lineNumber, 0), " ".repeat(nxtNonEmpty.firstNonWhitespaceCharacterIndex).concat(wrap.txt)); } else { e.replace(new vscode.Position(nxtLine.lineNumber, 0), wrap.ind.concat(wrap.txt)); } + } else { + console.log(`Invalid config setting! Using 'emptyLineAction' default value`); + defaultAction(); } } else { e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character),