From 48aae0cfa0b85fb9a4fce8589f76573aeff0a018 Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Tue, 1 Jan 2019 17:57:58 -0800 Subject: [PATCH] refactor: disableExtension configuration should follow pattern of rest of configs --- extension.ts | 20 ++++++------- package.json | 2 +- src/configuration/configuration.ts | 45 ++++++++++------------------- src/configuration/iconfiguration.ts | 7 ++++- src/mode/modeHandler.ts | 2 +- test/testConfiguration.ts | 2 +- 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/extension.ts b/extension.ts index 15c83e62699..d7cb4e7aca3 100644 --- a/extension.ts +++ b/extension.ts @@ -94,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) { event.contentChanges[0].range.start.line === event.contentChanges[0].range.end.line; vscode.workspace.onDidChangeTextDocument(async event => { - if (configuration.disableExt) { + if (configuration.disableExtension) { return; } @@ -165,7 +165,7 @@ export async function activate(context: vscode.ExtensionContext) { // window events vscode.window.onDidChangeActiveTextEditor(async () => { - if (configuration.disableExt) { + if (configuration.disableExtension) { return; } @@ -297,8 +297,8 @@ export async function activate(context: vscode.ExtensionContext) { }); registerCommand(context, 'toggleVim', async () => { - configuration.disableExt = !configuration.disableExt; - toggleExtension(configuration.disableExt, compositionState); + configuration.disableExtension = !configuration.disableExtension; + toggleExtension(configuration.disableExtension, compositionState); }); for (const boundKey of configuration.boundKeyCombinations) { @@ -316,7 +316,7 @@ export async function activate(context: vscode.ExtensionContext) { globalState.load(), configurationValidator.initialize(), // This is called last because getAndUpdateModeHandler() will change cursor - toggleExtension(configuration.disableExt, compositionState), + toggleExtension(configuration.disableExtension, compositionState), ]); } @@ -349,9 +349,8 @@ function overrideCommand( callback: (...args: any[]) => any ) { const disposable = vscode.commands.registerCommand(command, async args => { - if (configuration.disableExt) { - await vscode.commands.executeCommand('default:' + command, args); - return; + if (configuration.disableExtension) { + return vscode.commands.executeCommand('default:' + command, args); } if (!vscode.window.activeTextEditor) { @@ -362,11 +361,10 @@ function overrideCommand( vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === 'debug:input' ) { - await vscode.commands.executeCommand('default:' + command, args); - return; + return vscode.commands.executeCommand('default:' + command, args); } - callback(args); + return callback(args); }); context.subscriptions.push(disposable); } diff --git a/package.json b/package.json index 1210a85f819..15dcfafd9d2 100644 --- a/package.json +++ b/package.json @@ -594,7 +594,7 @@ }, "vim.disableExtension": { "type": "boolean", - "description": "Disables the VSCodeVim extension.", + "description": "Disables the VSCodeVim extension. Extension will continue to be loaded and activated, but VIM functionality will be disabled.", "default": false }, "vim.enableNeovim": { diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 33ab8e9c014..7385d3e11fb 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -52,7 +52,7 @@ interface IKeyBinding { * 1. `:set {option}` on the fly * 2. `vim.{option}` * 3. VS Code configuration - * 4. VSCodeVim flavored Vim option default values + * 4. VSCodeVim configuration default values * */ class Configuration implements IConfiguration { @@ -81,7 +81,7 @@ class Configuration implements IConfiguration { let val = vimConfigs[option] as any; if (val !== null && val !== undefined) { if (val.constructor.name === Object.name) { - val = this.unproxify(val); + val = Configuration.unproxify(val); } this[option] = val; } @@ -166,23 +166,9 @@ class Configuration implements IConfiguration { VsCodeContext.Set('vim.overrideCtrlC', this.overrideCopy || this.useCtrlKeys); } - unproxify(obj: Object): Object { - let result = {}; - for (const key in obj) { - let val = obj[key] as any; - if (val !== null && val !== undefined) { - result[key] = val; - } - } - return result; - } - getConfiguration(section: string = ''): vscode.WorkspaceConfiguration { - let resource: vscode.Uri | undefined = undefined; let activeTextEditor = vscode.window.activeTextEditor; - if (activeTextEditor) { - resource = activeTextEditor.document.uri; - } + let resource = activeTextEditor ? activeTextEditor.document.uri : undefined; return vscode.workspace.getConfiguration(section, resource); } @@ -310,19 +296,7 @@ class Configuration implements IConfiguration { foldfix = false; - private disableExtension: boolean = false; - - get disableExt(): boolean { - return this.disableExtension; - } - set disableExt(isDisabled: boolean) { - this.disableExtension = isDisabled; - this.getConfiguration('vim').update( - 'disableExtension', - isDisabled, - vscode.ConfigurationTarget.Global - ); - } + disableExtension: boolean = false; enableNeovim = false; neovimPath = 'nvim'; @@ -356,6 +330,17 @@ class Configuration implements IConfiguration { normalModeKeyBindingsNonRecursive: IKeyRemapping[] = []; visualModeKeyBindings: IKeyRemapping[] = []; visualModeKeyBindingsNonRecursive: IKeyRemapping[] = []; + + private static unproxify(obj: Object): Object { + let result = {}; + for (const key in obj) { + let val = obj[key] as any; + if (val !== null && val !== undefined) { + result[key] = val; + } + } + return result; + } } // handle mapped settings between vscode to vim diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index bc345463376..4acc5e869b2 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -207,7 +207,12 @@ export interface IConfiguration { */ foldfix: boolean; - disableExt: boolean; + /** + * "Soft"-disabling of extension. + * Differs from VS Code's disablng of the extension as the extension + * will still be loaded and activated, but all functionality will be disabled. + */ + disableExtension: boolean; /** * Neovim diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 611608df627..33a26e3fb76 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -81,7 +81,7 @@ export class ModeHandler implements vscode.Disposable { // Handle scenarios where mouse used to change current position. const onChangeTextEditorSelection = vscode.window.onDidChangeTextEditorSelection( (e: vscode.TextEditorSelectionChangeEvent) => { - if (configuration.disableExt) { + if (configuration.disableExtension) { return; } diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index cb15962fc1a..093625fba27 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -65,7 +65,7 @@ export class Configuration implements IConfiguration { mouseSelectionGoesIntoVisualMode = true; changeWordIncludesWhitespace = false; foldfix = false; - disableExt = false; + disableExtension = false; enableNeovim = false; neovimPath = 'nvim'; substituteGlobalFlag = false;