-
Notifications
You must be signed in to change notification settings - Fork 1.9k
vscode: simplified config and to removed one source of truth of default values #3131
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
vscode: simplified config and to removed one source of truth of default values #3131
Conversation
|
Saved 100+ lines of TypeScript code! |
editors/code/src/config.ts
Outdated
| cargoWatchOptions(): CargoWatchOptions { | ||
| return { | ||
| enable: this.cfg.get("cargo-watch.enable") as boolean, | ||
| arguments: this.cfg.get("cargo-watch.arguments") as string[], | ||
| allTargets: this.cfg.get("cargo-watch.allTargets") as boolean, | ||
| command: this.cfg.get("cargo-watch.command") as 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.
Not sure entirely whether to keep the config flat and change this to 4 separate getter methods or not. Any opinions?
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 like the nested variant more (a bit)
|
|
||
| private refreshConfig() { | ||
| this.cfg = vscode.workspace.getConfiguration(Config.rootSection); | ||
| console.log("Using configuration:", this.cfg); |
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.
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 not a fan of it. It's useful, but it gets pretty annoying if every extension does that. I mentioned it before, we could have a "report issue" command that dumps that stuff among other things.
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 wish we setup some logging-to-file infrastructure. There is a dedicated ExtensionContext.logPath property for this. But I think @matklad would like to keep console logging at max, though not sure...
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.
Let's do this (in a separate PR):
- define a
function logsomewhere, which just forwards toconsole.log - use log everywhere
- add some config to opt-in into logging
I do think this is useful to print lots of stuff. But printing should be abstracted away, so that it's easier to redirect, silence, elevate to gui popups, etc. Ideally, we should use a built in logger, but there isn't one afaik, so we need to do our own.
| return path.replace('~', os.homedir()); | ||
| private static replaceTildeWithHomeDir(path: string) { | ||
| if (path.startsWith("~/")) { | ||
| return os.homedir() + path.slice("~".length); |
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.
@matklad, I corrected a bit your implementation, to avoid possible caveats of string.replace(). The second argument (which is os.homedir() in this case) is actually a pattern (sorry, template) where $', $$, $1, $2... tokens have special meaning, so I better not rely on user's homedir name, this may blow...
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 also works better with paths that contain ~.
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.
@lnicola, sorry, not sure what you meant. If you think that path.replace("~", blah) will replace all occurences of "~", be informed that it replaces only the first occurence:

I know, this is counterintuitive, I even heard about string.replaceAll() proposal
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.
The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.
Oh... :-(
| "rust-analyzer.excludeGlobs": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "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.
Nice.
|
|
||
| private refreshConfig() { | ||
| this.cfg = vscode.workspace.getConfiguration(Config.rootSection); | ||
| console.log("Using configuration:", this.cfg); |
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 not a fan of it. It's useful, but it gets pretty annoying if every extension does that. I mentioned it before, we could have a "report issue" command that dumps that stuff among other things.
editors/code/src/config.ts
Outdated
| } | ||
| this.prevCargoFeatures = { ...this.cargoFeatures }; | ||
| // FIXME: add codegen for primitive configurations | ||
| highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } |
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.
| highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } | |
| get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } |
Seems like there's no reason not to use getters 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 am not a fan of getters sugar... but I won't stand against.
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.
@matklad do we make everything getters or only simple this.cfg.get("prop") ones?
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 vote for everything
matklad
left a comment
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.
A very nice cleanup, thank you @Veetaha !
bors r+
| @@ -1,39 +1,41 @@ | |||
| import * as lc from 'vscode-languageclient'; | |||
| import * as vscode from 'vscode'; | |||
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.
❤️
3131: vscode: simplified config and to removed one source of truth of default values r=matklad a=Veetaha Though not intended initially, the implementation of config design is alike [dart's one](https://github.com/Dart-Code/Dart-Code/blob/master/src/extension/config.ts) as pointed by @matklad in PM. Co-authored-by: Veetaha <gerzoh1@gmail.com>
Build succeeded
|

Though not intended initially, the implementation of config design is alike dart's one as pointed by @matklad in PM.