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

Fixes #2113: Start in Disabled mode configuration. #2115

Merged
merged 9 commits into from
Nov 12, 2017

Conversation

westim
Copy link
Contributor

@westim westim commented Nov 3, 2017

This PR is to add the configuration to package.json to start Vim in the Disabled mode by calling the toggleVim command.

This configuration is false by default, and therefore has no effect on default configuration behavior of VSCodeVim.

@jpoon jpoon self-requested a review November 4, 2017 19:32
Copy link
Member

@jpoon jpoon left a 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.

  1. We should extend the functionality to have a disableExtension configuration rather than a start-up flag.
  2. In doing so, we can get rid of the Globals.active
  3. 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.

@westim
Copy link
Contributor Author

westim commented Nov 6, 2017

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;
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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);
Copy link
Member

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() {
Copy link
Member

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)

@jpoon
Copy link
Member

jpoon commented Nov 9, 2017

@westim let me know when this is ready for review.

@westim
Copy link
Contributor Author

westim commented Nov 9, 2017

Hi @jpoon ,
I believe all 4 comments from the second review were addressed in f68b16f. This currently ready for review.

Copy link
Member

@jpoon jpoon left a 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?

/**
* Determines whether VSCodeVim is in Disabled mode or not.
*/
private _disableExtension: boolean | undefined;
Copy link
Member

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?

Copy link
Contributor Author

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!

jpoon and others added 2 commits November 9, 2017 23:15
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.
@westim
Copy link
Contributor Author

westim commented Nov 12, 2017

Hello @jpoon,

Another update on this. I was able to get the configuration to change correctly after fixing two issues:

  1. The private backing field needed to match the name in config, not the getter/setter.
  2. The vscode.WorkspaceConfiguration.update() API needed a ConfigurationTarget argument. When that argument was undefined, the update() method actually attempts to remove the section from config.

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.

@jpoon jpoon merged commit 9936d8d into VSCodeVim:master Nov 12, 2017
@jpoon
Copy link
Member

jpoon commented Nov 12, 2017

Thanks @westim

@westim westim deleted the start-disabled-config branch November 14, 2017 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants