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

Vim Settings #508

Merged
merged 12 commits into from
Aug 12, 2016
Merged

Vim Settings #508

merged 12 commits into from
Aug 12, 2016

Conversation

rebornix
Copy link
Member

@rebornix rebornix commented Jul 25, 2016

  • Commit message has a short title & issue references
  • Commits are squashed
  • It builds and tests pass (e.g gulp tslint)

This feature is related to #433, #463, #487 and #481. The basic idea is maintaining a singleton of Vim Settings. This Vim Seting object reads configuration from User Settings, .vimrc, Code configuration then our own (VSCodeVim) default value.

* 4. VSCodeVim flavored Vim option default values
*/
export class Configuration {
private static _instance: Configuration;
Copy link
Member

@johnfn johnfn Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use nullable types!

private static _instance: Configuration | null;

@rebornix
Copy link
Member Author

Currently you will see some problems as we have bugs in Code microsoft/vscode#9731.

@johnfn johnfn added WIP and removed WIP labels Jul 26, 2016
@johnfn
Copy link
Member

johnfn commented Jul 26, 2016

.vimrc loading

I have no qualms at all about you leaving this to another PR.

Auto update (monitoring both Code's configuration and .vimrc)

This would be very awesome, but low priority. Most people expect to have to restart their editor anyways.

@@ -145,6 +145,30 @@
"vim.scroll": {
"type": "number",
"description": "Number of lines to scroll with CTRL-U and CTRL-D commands."
},
"vim.tabstop": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't know how happy it makes me to see we support all this stuff. My god, it's like we're actually making a real Vim plugin!!!

@rebornix
Copy link
Member Author

Did a huge refactor to VimSettings. I can't imagine before that we can make this real simple with a little bit hack of Accessor Decorator.

With the new design, we only have one single Class/Object maintaining all Vim options' definition, intialization and updating. It's called Configuration.

Access Configuration

Use Configuration.getInstance(), it's the only way of getting an object of Configuration and yeah we make it a Singleton.

getInstance() is the only public method in Configuration.

Access a single Vim option

  1. Get: Configuration.getInstance().{OptionName}, eg, Configuration.getInstance().tabstop.
  2. Set: Configuration.getInstance().{OptionName} = {NewValue}, eg, Configuration.getInstance().tabstop = 4.
  3. Bracket notation: eg, Configuration.getInstance()["tabstop"], Configuration.getInstance()["tabstop"] = 4.

Lastly, we will support .vimrc later on and the update of .vimrc should trigger Configuration to update automatically.

@rebornix
Copy link
Member Author

Fix #279 as it's real easy to implement based on current Setting design, just 20 lines of code change.

@johnfn
Copy link
Member

johnfn commented Aug 9, 2016

Hey @rebornix is this good to go? Or are you still working on it?

@rebornix
Copy link
Member Author

rebornix commented Aug 9, 2016

I updated the code after our last sync up on Slack. Feel free to review and let me know what else you think can be improved.

*/
let vimOptions = vscode.workspace.getConfiguration("vim");
/* tslint:disable:forin */
// Disable forin rule here as we make accessors enumerable.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use for of here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to for of if possible but for of is specific to collections, which requires the object has a [Symbol.iterator] property. So I just kept using for in to avoid making it complex.

@johnfn
Copy link
Member

johnfn commented Aug 9, 2016

Instead of the object being a singleton, is it possible to export an instance of the class (rather than the class itself) and then use that directly? (keeping the class private)

I'm not actually sure if this is possible, but if it is it would improve the code a little. :-)

async execute(): Promise<void> {
switch (this._arguments.operator) {
case SetOptionOperator.Set:
Configuration.getInstance()[this._arguments.name!] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the ! at the end mean?

Copy link
Member

@johnfn johnfn Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a new feature related to nullable types in Typescript 2.0.

this._arguments.name is an optional type - it's either a string or undefined. The ! converts the type to a string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@jpoon
Copy link
Member

jpoon commented Aug 9, 2016

@rebornix Sweeeet. I added a couple of minor comments but LGTM!

this._matchRanges.push(new vscode.Range(
new Position(lineIdx, i),
new Position(lineIdx, i + search.length)
this.matchRanges.push(new vscode.Range(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy smokes, this PR includes smartcase as well? Heck yeah!

@jpoon jpoon removed the WIP label Aug 9, 2016
@johnfn
Copy link
Member

johnfn commented Aug 9, 2016

This is great! I think we together (ok, mostly you!) have arrived at a really good design for settings that should be really pleasant to add to in the future. Fix my few minor complaints and we should be good to go here.

}

public static getInstance(): Configuration {
if (Configuration._instance == null) {
Copy link
Member

@jpoon jpoon Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If somebody updates their workspace config, being a singleton, won't the instance retain the old value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with a restart for settings change if you are.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We could do hot reloading as a feature later on...)

Copy link
Member

@jpoon jpoon Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with it so long as we document it (aka put it on the readme).

Although, I don't see a reason for this to be a singleton, is it a huge perf hit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what's the alternative?

Copy link
Member

@jpoon jpoon Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, we use this A LOT in our code. The alternative I had in mind initially was to read the configs from the file every time.

@johnfn
Copy link
Member

johnfn commented Aug 9, 2016

And please ping me if I don't respond to a finished PR for a day or two. It's a little hard for me to sort through the PRs to know which ones are done, and I definitely don't want to leave anything that is done hanging around. :)

@rebornix
Copy link
Member Author

Update per comments and resolve conflicts.

@jpoon
Copy link
Member

jpoon commented Aug 11, 2016

ship it. 🚢

_Edit: As per johnfn's comments. Allow me to change that to ...Ship It*

  • builds should pass._

@@ -145,6 +146,7 @@ export class VimState {
* by us or by a mouse action.
*/
public whatILastSetTheSelectionTo: vscode.Selection;
<<<<<<< b9a0b15742532ecc54e66ee04c417d82e70d29dc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, there are merge conflicts here.

Copy link
Member Author

@rebornix rebornix Aug 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I start to doubt myself as it happens several times. I remember correctly yesterday that I did remove these lines by dd and save them then use git add . & git rebase --continue. After that, I even search ==== globally as I made this kind of mistakes before, but damn, it still happens.

I'll try to track this down next time I do rebasing. The only potential catch came to my mind now is I always reload the window as jsdiff is hanging, I'm not sure if this leads to the unsuccessful saving.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful, you want to use git add . && git rebase --continue. Using a single & will cause a process to be backgrounded.

But yeah, it's annoying and it eventually happens to everyone. No worries :)

@moopie
Copy link

moopie commented Nov 3, 2016

Any update on the .vimrc loading feature?

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.

4 participants