-
-
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
Vim Settings #508
Vim Settings #508
Conversation
* 4. VSCodeVim flavored Vim option default values | ||
*/ | ||
export class Configuration { | ||
private static _instance: Configuration; |
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.
Use nullable types!
private static _instance: Configuration | null;
Currently you will see some problems as we have bugs in Code microsoft/vscode#9731. |
I have no qualms at all about you leaving this to another PR.
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": { |
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.
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!!!
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 Access
|
Fix #279 as it's real easy to implement based on current Setting design, just 20 lines of code change. |
Hey @rebornix is this good to go? Or are you still working on it? |
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.` |
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 we use for of here as well?
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'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.
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; |
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.
What does the !
at the end mean?
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.
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.
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
@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( |
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.
Holy smokes, this PR includes smartcase as well? Heck yeah!
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) { |
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.
If somebody updates their workspace config, being a singleton, won't the instance retain the old value?
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'm ok with a restart for settings change if you are.
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.
(We could do hot reloading as a feature later on...)
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'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?
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.
Hm, what's the alternative?
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.
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.
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. :) |
Update per comments and resolve conflicts. |
ship it. 🚢 _Edit: As per johnfn's comments. Allow me to change that to ...Ship It*
|
@@ -145,6 +146,7 @@ export class VimState { | |||
* by us or by a mouse action. | |||
*/ | |||
public whatILastSetTheSelectionTo: vscode.Selection; | |||
<<<<<<< b9a0b15742532ecc54e66ee04c417d82e70d29dc |
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.
Wait, there are merge conflicts here.
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 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.
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.
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 :)
Any update on the .vimrc loading feature? |
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.vim.{xxx}
sectionw
should/could respectwordSeparators
settings #487.vimrc
loading.vimrc
)