aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-04-11 21:54:22 +0100
committerBenjamin Coenen <[email protected]>2020-04-11 22:45:09 +0100
commit93bfc2d05d36a47dc05a1799210327473d702dbc (patch)
treedee25e78b24b5d1b23d73ae1009bddbd060927cf /editors/code/src
parentd42346fed61f706d68fe888631a41ea5f2752d7f (diff)
parentfd06fe7b13045185ab4e630b0044aa9d8bbcdf8a (diff)
Improve autocompletion by looking on the type and name
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts39
-rw-r--r--editors/code/src/inlay_hints.ts10
2 files changed, 35 insertions, 14 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}
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 {
229} 229}
230 230
231interface RustSourceFile { 231interface RustSourceFile {
232 /* 232 /**
233 * Source of the token to cancel in-flight inlay hints request if any. 233 * Source of the token to cancel in-flight inlay hints request if any.
234 */ 234 */
235 inlaysRequest: null | vscode.CancellationTokenSource; 235 inlaysRequest: null | vscode.CancellationTokenSource;
236 /** 236 /**
237 * Last applied decorations. 237 * Last applied decorations.
238 */ 238 */
239 cachedDecorations: null | InlaysDecorations; 239 cachedDecorations: null | InlaysDecorations;
240 240
241 document: RustDocument; 241 document: RustDocument;