diff options
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r-- | editors/code/src/inlay_hints.ts | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 17d0dfa33..542d1f367 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -10,7 +10,11 @@ export function activateInlayHints(ctx: Ctx) { | |||
10 | const maybeUpdater = { | 10 | const maybeUpdater = { |
11 | updater: null as null | HintsUpdater, | 11 | updater: null as null | HintsUpdater, |
12 | onConfigChange() { | 12 | onConfigChange() { |
13 | if (!ctx.config.inlayHints.typeHints && !ctx.config.inlayHints.parameterHints) { | 13 | if ( |
14 | !ctx.config.inlayHints.typeHints && | ||
15 | !ctx.config.inlayHints.parameterHints && | ||
16 | !ctx.config.inlayHints.chainingHints | ||
17 | ) { | ||
14 | return this.dispose(); | 18 | return this.dispose(); |
15 | } | 19 | } |
16 | if (!this.updater) this.updater = new HintsUpdater(ctx); | 20 | if (!this.updater) this.updater = new HintsUpdater(ctx); |
@@ -63,6 +67,22 @@ const paramHints = { | |||
63 | } | 67 | } |
64 | }; | 68 | }; |
65 | 69 | ||
70 | const chainingHints = { | ||
71 | decorationType: vscode.window.createTextEditorDecorationType({ | ||
72 | after: { | ||
73 | color: new vscode.ThemeColor('rust_analyzer.inlayHint'), | ||
74 | fontStyle: "normal", | ||
75 | } | ||
76 | }), | ||
77 | |||
78 | toDecoration(hint: ra.InlayHint.ChainingHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { | ||
79 | return { | ||
80 | range: conv.asRange(hint.range), | ||
81 | renderOptions: { after: { contentText: ` ${hint.label}` } } | ||
82 | }; | ||
83 | } | ||
84 | }; | ||
85 | |||
66 | class HintsUpdater implements Disposable { | 86 | class HintsUpdater implements Disposable { |
67 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile | 87 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile |
68 | private readonly disposables: Disposable[] = []; | 88 | private readonly disposables: Disposable[] = []; |
@@ -95,7 +115,7 @@ class HintsUpdater implements Disposable { | |||
95 | 115 | ||
96 | dispose() { | 116 | dispose() { |
97 | this.sourceFiles.forEach(file => file.inlaysRequest?.cancel()); | 117 | this.sourceFiles.forEach(file => file.inlaysRequest?.cancel()); |
98 | this.ctx.visibleRustEditors.forEach(editor => this.renderDecorations(editor, { param: [], type: [] })); | 118 | this.ctx.visibleRustEditors.forEach(editor => this.renderDecorations(editor, { param: [], type: [], chaining: [] })); |
99 | this.disposables.forEach(d => d.dispose()); | 119 | this.disposables.forEach(d => d.dispose()); |
100 | } | 120 | } |
101 | 121 | ||
@@ -154,10 +174,11 @@ class HintsUpdater implements Disposable { | |||
154 | private renderDecorations(editor: RustEditor, decorations: InlaysDecorations) { | 174 | private renderDecorations(editor: RustEditor, decorations: InlaysDecorations) { |
155 | editor.setDecorations(typeHints.decorationType, decorations.type); | 175 | editor.setDecorations(typeHints.decorationType, decorations.type); |
156 | editor.setDecorations(paramHints.decorationType, decorations.param); | 176 | editor.setDecorations(paramHints.decorationType, decorations.param); |
177 | editor.setDecorations(chainingHints.decorationType, decorations.chaining); | ||
157 | } | 178 | } |
158 | 179 | ||
159 | private hintsToDecorations(hints: ra.InlayHint[]): InlaysDecorations { | 180 | private hintsToDecorations(hints: ra.InlayHint[]): InlaysDecorations { |
160 | const decorations: InlaysDecorations = { type: [], param: [] }; | 181 | const decorations: InlaysDecorations = { type: [], param: [], chaining: [] }; |
161 | const conv = this.ctx.client.protocol2CodeConverter; | 182 | const conv = this.ctx.client.protocol2CodeConverter; |
162 | 183 | ||
163 | for (const hint of hints) { | 184 | for (const hint of hints) { |
@@ -170,6 +191,10 @@ class HintsUpdater implements Disposable { | |||
170 | decorations.param.push(paramHints.toDecoration(hint, conv)); | 191 | decorations.param.push(paramHints.toDecoration(hint, conv)); |
171 | continue; | 192 | continue; |
172 | } | 193 | } |
194 | case ra.InlayHint.Kind.ChainingHint: { | ||
195 | decorations.chaining.push(chainingHints.toDecoration(hint, conv)); | ||
196 | continue; | ||
197 | } | ||
173 | } | 198 | } |
174 | } | 199 | } |
175 | return decorations; | 200 | return decorations; |
@@ -196,6 +221,7 @@ class HintsUpdater implements Disposable { | |||
196 | interface InlaysDecorations { | 221 | interface InlaysDecorations { |
197 | type: vscode.DecorationOptions[]; | 222 | type: vscode.DecorationOptions[]; |
198 | param: vscode.DecorationOptions[]; | 223 | param: vscode.DecorationOptions[]; |
224 | chaining: vscode.DecorationOptions[]; | ||
199 | } | 225 | } |
200 | 226 | ||
201 | interface RustSourceFile { | 227 | interface RustSourceFile { |