aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json67
-rw-r--r--editors/code/src/inlay_hints.ts75
2 files changed, 93 insertions, 49 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index f079f73b8..93d94ed12 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -712,8 +712,8 @@
712 ], 712 ],
713 "colors": [ 713 "colors": [
714 { 714 {
715 "id": "rust_analyzer.inlayHint", 715 "id": "rust_analyzer.inlayHints.foreground",
716 "description": "Color for inlay hints", 716 "description": "Foreground color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.foreground.* configurations)",
717 "defaults": { 717 "defaults": {
718 "dark": "#A0A0A0F0", 718 "dark": "#A0A0A0F0",
719 "light": "#747474", 719 "light": "#747474",
@@ -721,6 +721,69 @@
721 } 721 }
722 }, 722 },
723 { 723 {
724 "id": "rust_analyzer.inlayHints.background",
725 "description": "Background color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.background.* configurations)",
726 "defaults": {
727 "dark": "#11223300",
728 "light": "#11223300",
729 "highContrast": "#11223300"
730 }
731 },
732 {
733 "id": "rust_analyzer.inlayHints.foreground.typeHints",
734 "description": "Foreground color of inlay type hints for variables (overrides rust_analyzer.inlayHints.foreground)",
735 "defaults": {
736 "dark": "rust_analyzer.inlayHints.foreground",
737 "light": "rust_analyzer.inlayHints.foreground",
738 "highContrast": "rust_analyzer.inlayHints.foreground"
739 }
740 },
741 {
742 "id": "rust_analyzer.inlayHints.foreground.chainingHints",
743 "description": "Foreground color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.foreground)",
744 "defaults": {
745 "dark": "rust_analyzer.inlayHints.foreground",
746 "light": "rust_analyzer.inlayHints.foreground",
747 "highContrast": "rust_analyzer.inlayHints.foreground"
748 }
749 },
750 {
751 "id": "rust_analyzer.inlayHints.foreground.parameterHints",
752 "description": "Foreground color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.foreground)",
753 "defaults": {
754 "dark": "rust_analyzer.inlayHints.foreground",
755 "light": "rust_analyzer.inlayHints.foreground",
756 "highContrast": "rust_analyzer.inlayHints.foreground"
757 }
758 },
759 {
760 "id": "rust_analyzer.inlayHints.background.typeHints",
761 "description": "Background color of inlay type hints for variables (overrides rust_analyzer.inlayHints.background)",
762 "defaults": {
763 "dark": "rust_analyzer.inlayHints.background",
764 "light": "rust_analyzer.inlayHints.background",
765 "highContrast": "rust_analyzer.inlayHints.background"
766 }
767 },
768 {
769 "id": "rust_analyzer.inlayHints.background.chainingHints",
770 "description": "Background color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.background)",
771 "defaults": {
772 "dark": "rust_analyzer.inlayHints.background",
773 "light": "rust_analyzer.inlayHints.background",
774 "highContrast": "rust_analyzer.inlayHints.background"
775 }
776 },
777 {
778 "id": "rust_analyzer.inlayHints.background.parameterHints",
779 "description": "Background color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.background)",
780 "defaults": {
781 "dark": "rust_analyzer.inlayHints.background",
782 "light": "rust_analyzer.inlayHints.background",
783 "highContrast": "rust_analyzer.inlayHints.background"
784 }
785 },
786 {
724 "id": "rust_analyzer.syntaxTreeBorder", 787 "id": "rust_analyzer.syntaxTreeBorder",
725 "description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)", 788 "description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)",
726 "defaults": { 789 "defaults": {
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