From f778242a37aedd0f0f9aefe055b5d0f4d99f6765 Mon Sep 17 00:00:00 2001 From: veetaha Date: Sat, 11 Apr 2020 15:36:16 +0300 Subject: vscode: fix indent --- editors/code/src/inlay_hints.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 6a8bd942e..da74f03d2 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -229,13 +229,13 @@ interface InlaysDecorations { } interface RustSourceFile { - /* - * Source of the token to cancel in-flight inlay hints request if any. - */ + /** + * Source of the token to cancel in-flight inlay hints request if any. + */ inlaysRequest: null | vscode.CancellationTokenSource; /** - * Last applied decorations. - */ + * Last applied decorations. + */ cachedDecorations: null | InlaysDecorations; document: RustDocument; -- cgit v1.2.3 From 12e23bd60b9c3dde24bb9fa597ad88705abd2b76 Mon Sep 17 00:00:00 2001 From: veetaha Date: Sat, 11 Apr 2020 15:23:07 +0300 Subject: vscode: fix typing bug in config --- editors/code/src/config.ts | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'editors/code') 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 { return vscode.workspace.getConfiguration(this.rootSection); } - get serverPath() { return this.cfg.get("serverPath")!; } - get channel() { return this.cfg.get("updates.channel")!; } - get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload")!; } - get traceExtension() { return this.cfg.get("trace.extension")!; } + /** + * Beware that postfix `!` operator erases both `null` and `undefined`. + * This is why the following doesn't work as expected: + * + * ```ts + * const nullableNum = vscode + * .workspace + * .getConfiguration + * .getConfiguration("rust-analyer") + * .get(path)!; + * + * // What happens is that type of `nullableNum` is `number` but not `null | number`: + * const fullFledgedNum: number = nullableNum; + * ``` + * So this getter handles this quirk by not requiring the caller to use postfix `!` + */ + private get(path: string): T { + return this.cfg.get(path)!; + } + + get serverPath() { return this.get("serverPath"); } + get channel() { return this.get("updates.channel"); } + get askBeforeDownload() { return this.get("updates.askBeforeDownload"); } + get traceExtension() { return this.get("trace.extension"); } + get inlayHints() { return { - typeHints: this.cfg.get("inlayHints.typeHints")!, - parameterHints: this.cfg.get("inlayHints.parameterHints")!, - chainingHints: this.cfg.get("inlayHints.chainingHints")!, - maxLength: this.cfg.get("inlayHints.maxLength")!, + typeHints: this.get("inlayHints.typeHints"), + parameterHints: this.get("inlayHints.parameterHints"), + chainingHints: this.get("inlayHints.chainingHints"), + maxLength: this.get("inlayHints.maxLength"), }; } get checkOnSave() { return { - command: this.cfg.get("checkOnSave.command")!, + command: this.get("checkOnSave.command"), }; } } -- cgit v1.2.3