-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixes #2113: Start in Disabled mode configuration. #2115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I have a couple of suggestions.
- We should extend the functionality to have a
disableExtension
configuration rather than a start-up flag. - In doing so, we can get rid of the
Globals.active
toggleVim
would then update this configuration
This would greatly simplify the state of whether the extension is disabled/enabled as right now that information lives across 2 or 3 different variables.
Thanks for the great feedback, @jpoon ! |
extension.ts
Outdated
|
||
vscode.commands.executeCommand('setContext', 'vim.active', Globals.active); | ||
registerCommand(context, 'toggleVim', async () => { | ||
Configuration.disableExtension = !Configuration.disableExtension; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change is only in-memory and doesn't actually change the settings to the configuration file. I don't think we ever call the update
fx in the api docs.
It seems like we should convert Configuration
class to use getters/setters such that if you set any of the configurations, it'll call the aforementioned update api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, for the sake of limiting the scope of these changes, I've only implemented a getter/setter for the Configuration.disableExtension
property.
README.md
Outdated
#### `"vim.disableExtension"` | ||
* VSCodeVim will be in "Disabled" mode | ||
* This can be changed at any time using the `toggleVim` command in the Command Palette | ||
* Note that this is not the same as disabling the VSCodeVim extension |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: probably best to clarify
...disabling the VSCodeVim extension through VS Code.
extension.ts
Outdated
default: | ||
break; | ||
} | ||
editor.options = options; | ||
}); | ||
await vscode.commands.executeCommand('setContext', 'vim.active', Globals.active); | ||
await vscode.commands.executeCommand('setContext', 'vim.active', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call this in two different spots (line 335, line 339)? You can probably consolidate it to outside the if
to use Configuration.disableExtension
await vscode.commands.executeCommand('setContext', 'vim.active', Configuration.disableExtension)
extension.ts
Outdated
let mh = await getAndUpdateModeHandler(); | ||
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false }); | ||
} else { | ||
async function toggleDisabledMode() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm trying to think of a better name as it's not actually toggling the mode (ie. if you call this twice, it doesn't actually toggle and go from disable->enable).
Maybe this signature:
toggleExtension(bool isDisabled)
@westim let me know when this is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a test for this? Otherwise, I presume you've tested it and ensured that the save persists across VS Code instances?
src/configuration/configuration.ts
Outdated
/** | ||
* Determines whether VSCodeVim is in Disabled mode or not. | ||
*/ | ||
private _disableExtension: boolean | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to set this to false
to start? Is there a scenario where it'll be undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some weird behavior I need to work out, and this will be involved in some further changes I need to make. I'll let you know when it's ready. Sorry about all the confusion / edits!
In order to properly access and overwrite the extension configuration values, the name of the private field needed to match the value found in the configuration file, while the getter & setter were given a different name. Also, to properly use the vscode.WorkspaceConfiguration.update() API, ConfigurationTarget.Global had to be specified. The value true could've also been used, but the enum is more explicit.
Hello @jpoon, Another update on this. I was able to get the configuration to change correctly after fixing two issues:
I'm not sure exactly how to test this. I confirmed the configuration value was changing using primitive techniques: console.log(vscode.workspace.getConfiguration('vim').get('disableExtension')); I confirmed that the configuration change carries forward to new Editor Groups in the same Window. I'm not sure I can properly test whether the configuration affects new Windows while using the Extension Development Host. If there is, please let me know. |
Thanks @westim |
This PR is to add the configuration to
package.json
to start Vim in theDisabled
mode by calling thetoggleVim
command.This configuration is
false
by default, and therefore has no effect on default configuration behavior of VSCodeVim.