Skip to content

Conversation

@Veetaha
Copy link
Contributor

@Veetaha Veetaha commented Feb 13, 2020

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

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 13, 2020

Saved 100+ lines of TypeScript code!

@Veetaha Veetaha requested review from kjeremy, lnicola and matklad and removed request for matklad February 13, 2020 20:51
Comment on lines 143 to 149
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,
};
Copy link
Contributor Author

@Veetaha Veetaha Feb 13, 2020

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?

Copy link
Contributor

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

Choose a reason for hiding this comment

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

This will give us a better view on user's config in bug reports:
image

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 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.

Copy link
Contributor Author

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...

Copy link
Contributor

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 log somewhere, which just forwards to console.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);
Copy link
Contributor Author

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...

Copy link
Member

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 ~.

Copy link
Contributor Author

@Veetaha Veetaha Feb 13, 2020

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:
image

I know, this is counterintuitive, I even heard about string.replaceAll() proposal

Copy link
Member

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

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);
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 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.

}
this.prevCargoFeatures = { ...this.cargoFeatures };
// FIXME: add codegen for primitive configurations
highlightingOn() { return this.cfg.get("highlightingOn") as boolean; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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?

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 am not a fan of getters sugar... but I won't stand against.

Copy link
Contributor Author

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?

Copy link
Contributor

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

@Veetaha Veetaha requested a review from matklad February 14, 2020 21:08
Copy link
Contributor

@matklad matklad left a 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';
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

bors bot added a commit that referenced this pull request Feb 14, 2020
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>
@bors
Copy link
Contributor

bors bot commented Feb 14, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • Rust (windows-latest)
  • TypeScript

@bors bors bot merged commit 20fabaf into rust-lang:master Feb 14, 2020
@Veetaha Veetaha deleted the feature/vscode-redesign-config branch February 24, 2020 20:11
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.

3 participants