aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/config.ts39
1 files changed, 30 insertions, 9 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 21c1c9f23..35a05131c 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -66,23 +66,44 @@ export class Config {
66 return vscode.workspace.getConfiguration(this.rootSection); 66 return vscode.workspace.getConfiguration(this.rootSection);
67 } 67 }
68 68
69 get serverPath() { return this.cfg.get<null | string>("serverPath")!; } 69 /**
70 get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; } 70 * Beware that postfix `!` operator erases both `null` and `undefined`.
71 get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; } 71 * This is why the following doesn't work as expected:
72 get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; } 72 *
73 * ```ts
74 * const nullableNum = vscode
75 * .workspace
76 * .getConfiguration
77 * .getConfiguration("rust-analyer")
78 * .get<number | null>(path)!;
79 *
80 * // What happens is that type of `nullableNum` is `number` but not `null | number`:
81 * const fullFledgedNum: number = nullableNum;
82 * ```
83 * So this getter handles this quirk by not requiring the caller to use postfix `!`
84 */
85 private get<T>(path: string): T {
86 return this.cfg.get<T>(path)!;
87 }
88
89 get serverPath() { return this.get<null | string>("serverPath"); }
90 get channel() { return this.get<UpdatesChannel>("updates.channel"); }
91 get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
92 get traceExtension() { return this.get<boolean>("trace.extension"); }
93
73 94
74 get inlayHints() { 95 get inlayHints() {
75 return { 96 return {
76 typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!, 97 typeHints: this.get<boolean>("inlayHints.typeHints"),
77 parameterHints: this.cfg.get<boolean>("inlayHints.parameterHints")!, 98 parameterHints: this.get<boolean>("inlayHints.parameterHints"),
78 chainingHints: this.cfg.get<boolean>("inlayHints.chainingHints")!, 99 chainingHints: this.get<boolean>("inlayHints.chainingHints"),
79 maxLength: this.cfg.get<null | number>("inlayHints.maxLength")!, 100 maxLength: this.get<null | number>("inlayHints.maxLength"),
80 }; 101 };
81 } 102 }
82 103
83 get checkOnSave() { 104 get checkOnSave() {
84 return { 105 return {
85 command: this.cfg.get<string>("checkOnSave.command")!, 106 command: this.get<string>("checkOnSave.command"),
86 }; 107 };
87 } 108 }
88} 109}