diff options
-rw-r--r-- | docs/user/manual.adoc | 24 | ||||
-rw-r--r-- | editors/code/package.json | 67 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 75 |
3 files changed, 117 insertions, 49 deletions
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 8c966288b..b15c9ee7f 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -367,6 +367,30 @@ include::./generated_assists.adoc[] | |||
367 | 367 | ||
368 | == Editor Features | 368 | == Editor Features |
369 | === VS Code | 369 | === VS Code |
370 | |||
371 | ==== Color configurations | ||
372 | |||
373 | It is possible to change the foreground/background color of inlay hints. Just add this to your | ||
374 | `settings.json`: | ||
375 | |||
376 | [source,jsonc] | ||
377 | ---- | ||
378 | { | ||
379 | "workbench.colorCustomizations": { | ||
380 | // Name of the theme you are currently using | ||
381 | "[Default Dark+]": { | ||
382 | "rust_analyzer.inlayHints.foreground": "#868686f0", | ||
383 | "rust_analyzer.inlayHints.background": "#3d3d3d48", | ||
384 | |||
385 | // Overrides for specific kinds of inlay hints | ||
386 | "rust_analyzer.inlayHints.foreground.typeHints": "#fdb6fdf0", | ||
387 | "rust_analyzer.inlayHints.foreground.paramHints": "#fdb6fdf0", | ||
388 | "rust_analyzer.inlayHints.background.chainingHints": "#6b0c0c81" | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | ---- | ||
393 | |||
370 | ==== Special `when` clause context for keybindings. | 394 | ==== Special `when` clause context for keybindings. |
371 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: | 395 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: |
372 | [source,json] | 396 | [source,json] |
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 | 42 | const typeHints = createHintStyle("type"); | |
43 | const typeHints = { | 43 | const paramHints = createHintStyle("parameter"); |
44 | decorationType: vscode.window.createTextEditorDecorationType({ | 44 | const chainingHints = createHintStyle("chaining"); |
45 | after: { | 45 | |
46 | color: new vscode.ThemeColor('rust_analyzer.inlayHint'), | 46 | function 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, | |
59 | const 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 | |||
75 | const 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 | ||
91 | class HintsUpdater implements Disposable { | 72 | class HintsUpdater implements Disposable { |
92 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile | 73 | private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile |