aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r--editors/code/src/inlay_hints.ts75
1 files changed, 28 insertions, 47 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 9e6d6045f..7b481fc72 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -39,54 +39,35 @@ export function activateInlayHints(ctx: Ctx) {
39 maybeUpdater.onConfigChange(); 39 maybeUpdater.onConfigChange();
40} 40}
41 41
42 42const typeHints = createHintStyle("type");
43const typeHints = { 43const paramHints = createHintStyle("parameter");
44 decorationType: vscode.window.createTextEditorDecorationType({ 44const chainingHints = createHintStyle("chaining");
45 after: { 45
46 color: new vscode.ThemeColor('rust_analyzer.inlayHint'), 46function createHintStyle(hintKind: "type" | "parameter" | "chaining") {
47 fontStyle: "normal", 47 const [pos, render] = ({
48 } 48 type: ["after", (label: string) => `: ${label}`],
49 }), 49 parameter: ["before", (label: string) => `${label}: `],
50 50 chaining: ["after", (label: string) => `: ${label}`],
51 toDecoration(hint: ra.InlayHint.TypeHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { 51 } as const)[hintKind];
52 return { 52
53 range: conv.asRange(hint.range), 53 const fg = new vscode.ThemeColor(`rust_analyzer.inlayHints.foreground.${hintKind}Hints`);
54 renderOptions: { after: { contentText: `: ${hint.label}` } } 54 const bg = new vscode.ThemeColor(`rust_analyzer.inlayHints.background.${hintKind}Hints`);
55 }; 55 return {
56 } 56 decorationType: vscode.window.createTextEditorDecorationType({
57}; 57 [pos]: {
58 58 color: fg,
59const paramHints = { 59 backgroundColor: bg,
60 decorationType: vscode.window.createTextEditorDecorationType({ 60 fontStyle: "normal",
61 before: { 61 },
62 color: new vscode.ThemeColor('rust_analyzer.inlayHint'), 62 }),
63 fontStyle: "normal", 63 toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
64 } 64 return {
65 }), 65 range: conv.asRange(hint.range),
66 66 renderOptions: { [pos]: { contentText: render(hint.label) } }
67 toDecoration(hint: ra.InlayHint.ParamHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { 67 };
68 return {
69 range: conv.asRange(hint.range),
70 renderOptions: { before: { contentText: `${hint.label}: ` } }
71 };
72 }
73};
74
75const chainingHints = {
76 decorationType: vscode.window.createTextEditorDecorationType({
77 after: {
78 color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
79 fontStyle: "normal",
80 } 68 }
81 }), 69 };
82 70}
83 toDecoration(hint: ra.InlayHint.ChainingHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
84 return {
85 range: conv.asRange(hint.range),
86 renderOptions: { after: { contentText: ` ${hint.label}` } }
87 };
88 }
89};
90 71
91class HintsUpdater implements Disposable { 72class HintsUpdater implements Disposable {
92 private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile 73 private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile