diff options
author | imtsuki <[email protected]> | 2020-01-14 17:02:01 +0000 |
---|---|---|
committer | imtsuki <[email protected]> | 2020-01-14 17:18:52 +0000 |
commit | c390e92fdd25ced46c589bfbff94e4b0bc4d9c38 (patch) | |
tree | bd33983bd3d77c1442f7814d595cbf0506f421da /editors | |
parent | d8d8c20077702b8537086d49914d02654a46ebc5 (diff) |
Add inlay parameter name hints for function calls
Signed-off-by: imtsuki <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/package.json | 2 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 51 |
2 files changed, 42 insertions, 11 deletions
diff --git a/editors/code/package.json b/editors/code/package.json index 7c22d21d3..ed637d114 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -228,7 +228,7 @@ | |||
228 | "rust-analyzer.displayInlayHints": { | 228 | "rust-analyzer.displayInlayHints": { |
229 | "type": "boolean", | 229 | "type": "boolean", |
230 | "default": true, | 230 | "default": true, |
231 | "description": "Display additional type information in the editor" | 231 | "description": "Display additional type and parameter information in the editor" |
232 | }, | 232 | }, |
233 | "rust-analyzer.maxInlayHintLength": { | 233 | "rust-analyzer.maxInlayHintLength": { |
234 | "type": "number", | 234 | "type": "number", |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 078d18f0f..c4206cf5b 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -38,6 +38,12 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ | |||
38 | }, | 38 | }, |
39 | }); | 39 | }); |
40 | 40 | ||
41 | const parameterHintDecorationType = vscode.window.createTextEditorDecorationType({ | ||
42 | before: { | ||
43 | color: new vscode.ThemeColor('rust_analyzer.inlayHint'), | ||
44 | } | ||
45 | }) | ||
46 | |||
41 | class HintsUpdater { | 47 | class HintsUpdater { |
42 | private pending: Map<string, vscode.CancellationTokenSource> = new Map(); | 48 | private pending: Map<string, vscode.CancellationTokenSource> = new Map(); |
43 | private ctx: Ctx; | 49 | private ctx: Ctx; |
@@ -55,7 +61,10 @@ class HintsUpdater { | |||
55 | if (this.enabled) { | 61 | if (this.enabled) { |
56 | await this.refresh(); | 62 | await this.refresh(); |
57 | } else { | 63 | } else { |
58 | this.allEditors.forEach(it => this.setDecorations(it, [])); | 64 | this.allEditors.forEach(it => { |
65 | this.setTypeDecorations(it, []); | ||
66 | this.setParameterDecorations(it, []); | ||
67 | }); | ||
59 | } | 68 | } |
60 | } | 69 | } |
61 | 70 | ||
@@ -68,15 +77,27 @@ class HintsUpdater { | |||
68 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { | 77 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { |
69 | const newHints = await this.queryHints(editor.document.uri.toString()); | 78 | const newHints = await this.queryHints(editor.document.uri.toString()); |
70 | if (newHints == null) return; | 79 | if (newHints == null) return; |
71 | const newDecorations = newHints.map(hint => ({ | 80 | const newTypeDecorations = newHints.filter(hint => hint.kind === 'TypeHint') |
72 | range: hint.range, | 81 | .map(hint => ({ |
73 | renderOptions: { | 82 | range: hint.range, |
74 | after: { | 83 | renderOptions: { |
75 | contentText: `: ${hint.label}`, | 84 | after: { |
85 | contentText: `: ${hint.label}`, | ||
86 | }, | ||
76 | }, | 87 | }, |
77 | }, | 88 | })); |
78 | })); | 89 | this.setTypeDecorations(editor, newTypeDecorations); |
79 | this.setDecorations(editor, newDecorations); | 90 | |
91 | const newParameterDecorations = newHints.filter(hint => hint.kind === 'ParameterHint') | ||
92 | .map(hint => ({ | ||
93 | range: hint.range, | ||
94 | renderOptions: { | ||
95 | before: { | ||
96 | contentText: `${hint.label}: `, | ||
97 | }, | ||
98 | }, | ||
99 | })); | ||
100 | this.setParameterDecorations(editor, newParameterDecorations); | ||
80 | } | 101 | } |
81 | 102 | ||
82 | private get allEditors(): vscode.TextEditor[] { | 103 | private get allEditors(): vscode.TextEditor[] { |
@@ -85,7 +106,7 @@ class HintsUpdater { | |||
85 | ); | 106 | ); |
86 | } | 107 | } |
87 | 108 | ||
88 | private setDecorations( | 109 | private setTypeDecorations( |
89 | editor: vscode.TextEditor, | 110 | editor: vscode.TextEditor, |
90 | decorations: vscode.DecorationOptions[], | 111 | decorations: vscode.DecorationOptions[], |
91 | ) { | 112 | ) { |
@@ -95,6 +116,16 @@ class HintsUpdater { | |||
95 | ); | 116 | ); |
96 | } | 117 | } |
97 | 118 | ||
119 | private setParameterDecorations( | ||
120 | editor: vscode.TextEditor, | ||
121 | decorations: vscode.DecorationOptions[], | ||
122 | ) { | ||
123 | editor.setDecorations( | ||
124 | parameterHintDecorationType, | ||
125 | this.enabled ? decorations : [], | ||
126 | ); | ||
127 | } | ||
128 | |||
98 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 129 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
99 | let client = this.ctx.client; | 130 | let client = this.ctx.client; |
100 | if (!client) return null; | 131 | if (!client) return null; |