mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Merge #5885
5885: Make inlay hints colors more configurable r=matklad a=Veetaha **[BREAKING CHANGE]** Tackles https://github.com/rust-analyzer/rust-analyzer/issues/5337#issuecomment-680018601 and generally related to #5337. Added `foreground/background` color configurations with optional more specific overrides `foreground.(type|parameter|chaining)Hints`. One problem I see is that the config keys are long and don't fit into the on-hover hints in the `settings.json` file entirely... <details> <summary>Demo</summary> ![demo](https://user-images.githubusercontent.com/36276403/91238334-77fc3b00-e745-11ea-836b-2822015ece98.gif) </details> Co-authored-by: Veetaha <veetaha2@gmail.com>
This commit is contained in:
commit
d58a3a277a
@ -367,6 +367,30 @@ include::./generated_assists.adoc[]
|
||||
|
||||
== Editor Features
|
||||
=== VS Code
|
||||
|
||||
==== Color configurations
|
||||
|
||||
It is possible to change the foreground/background color of inlay hints. Just add this to your
|
||||
`settings.json`:
|
||||
|
||||
[source,jsonc]
|
||||
----
|
||||
{
|
||||
"workbench.colorCustomizations": {
|
||||
// Name of the theme you are currently using
|
||||
"[Default Dark+]": {
|
||||
"rust_analyzer.inlayHints.foreground": "#868686f0",
|
||||
"rust_analyzer.inlayHints.background": "#3d3d3d48",
|
||||
|
||||
// Overrides for specific kinds of inlay hints
|
||||
"rust_analyzer.inlayHints.foreground.typeHints": "#fdb6fdf0",
|
||||
"rust_analyzer.inlayHints.foreground.paramHints": "#fdb6fdf0",
|
||||
"rust_analyzer.inlayHints.background.chainingHints": "#6b0c0c81"
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
==== Special `when` clause context for keybindings.
|
||||
You may use `inRustProject` context to configure keybindings for rust projects only. For example:
|
||||
[source,json]
|
||||
|
@ -712,14 +712,77 @@
|
||||
],
|
||||
"colors": [
|
||||
{
|
||||
"id": "rust_analyzer.inlayHint",
|
||||
"description": "Color for inlay hints",
|
||||
"id": "rust_analyzer.inlayHints.foreground",
|
||||
"description": "Foreground color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.foreground.* configurations)",
|
||||
"defaults": {
|
||||
"dark": "#A0A0A0F0",
|
||||
"light": "#747474",
|
||||
"highContrast": "#BEBEBE"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.background",
|
||||
"description": "Background color of inlay hints (is overriden by more specific rust_analyzer.inlayHints.background.* configurations)",
|
||||
"defaults": {
|
||||
"dark": "#11223300",
|
||||
"light": "#11223300",
|
||||
"highContrast": "#11223300"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.foreground.typeHints",
|
||||
"description": "Foreground color of inlay type hints for variables (overrides rust_analyzer.inlayHints.foreground)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.foreground",
|
||||
"light": "rust_analyzer.inlayHints.foreground",
|
||||
"highContrast": "rust_analyzer.inlayHints.foreground"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.foreground.chainingHints",
|
||||
"description": "Foreground color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.foreground)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.foreground",
|
||||
"light": "rust_analyzer.inlayHints.foreground",
|
||||
"highContrast": "rust_analyzer.inlayHints.foreground"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.foreground.parameterHints",
|
||||
"description": "Foreground color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.foreground)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.foreground",
|
||||
"light": "rust_analyzer.inlayHints.foreground",
|
||||
"highContrast": "rust_analyzer.inlayHints.foreground"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.background.typeHints",
|
||||
"description": "Background color of inlay type hints for variables (overrides rust_analyzer.inlayHints.background)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.background",
|
||||
"light": "rust_analyzer.inlayHints.background",
|
||||
"highContrast": "rust_analyzer.inlayHints.background"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.background.chainingHints",
|
||||
"description": "Background color of inlay type hints for method chains (overrides rust_analyzer.inlayHints.background)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.background",
|
||||
"light": "rust_analyzer.inlayHints.background",
|
||||
"highContrast": "rust_analyzer.inlayHints.background"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.inlayHints.background.parameterHints",
|
||||
"description": "Background color of function parameter name inlay hints at the call site (overrides rust_analyzer.inlayHints.background)",
|
||||
"defaults": {
|
||||
"dark": "rust_analyzer.inlayHints.background",
|
||||
"light": "rust_analyzer.inlayHints.background",
|
||||
"highContrast": "rust_analyzer.inlayHints.background"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "rust_analyzer.syntaxTreeBorder",
|
||||
"description": "Color of the border displayed in the Rust source code for the selected syntax node (see \"Show Syntax Tree\" command)",
|
||||
|
@ -39,54 +39,35 @@ export function activateInlayHints(ctx: Ctx) {
|
||||
maybeUpdater.onConfigChange();
|
||||
}
|
||||
|
||||
const typeHints = createHintStyle("type");
|
||||
const paramHints = createHintStyle("parameter");
|
||||
const chainingHints = createHintStyle("chaining");
|
||||
|
||||
const typeHints = {
|
||||
decorationType: vscode.window.createTextEditorDecorationType({
|
||||
after: {
|
||||
color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
|
||||
fontStyle: "normal",
|
||||
function createHintStyle(hintKind: "type" | "parameter" | "chaining") {
|
||||
const [pos, render] = ({
|
||||
type: ["after", (label: string) => `: ${label}`],
|
||||
parameter: ["before", (label: string) => `${label}: `],
|
||||
chaining: ["after", (label: string) => `: ${label}`],
|
||||
} as const)[hintKind];
|
||||
|
||||
const fg = new vscode.ThemeColor(`rust_analyzer.inlayHints.foreground.${hintKind}Hints`);
|
||||
const bg = new vscode.ThemeColor(`rust_analyzer.inlayHints.background.${hintKind}Hints`);
|
||||
return {
|
||||
decorationType: vscode.window.createTextEditorDecorationType({
|
||||
[pos]: {
|
||||
color: fg,
|
||||
backgroundColor: bg,
|
||||
fontStyle: "normal",
|
||||
},
|
||||
}),
|
||||
toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
|
||||
return {
|
||||
range: conv.asRange(hint.range),
|
||||
renderOptions: { [pos]: { contentText: render(hint.label) } }
|
||||
};
|
||||
}
|
||||
}),
|
||||
|
||||
toDecoration(hint: ra.InlayHint.TypeHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
|
||||
return {
|
||||
range: conv.asRange(hint.range),
|
||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const paramHints = {
|
||||
decorationType: vscode.window.createTextEditorDecorationType({
|
||||
before: {
|
||||
color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
|
||||
fontStyle: "normal",
|
||||
}
|
||||
}),
|
||||
|
||||
toDecoration(hint: ra.InlayHint.ParamHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
|
||||
return {
|
||||
range: conv.asRange(hint.range),
|
||||
renderOptions: { before: { contentText: `${hint.label}: ` } }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const chainingHints = {
|
||||
decorationType: vscode.window.createTextEditorDecorationType({
|
||||
after: {
|
||||
color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
|
||||
fontStyle: "normal",
|
||||
}
|
||||
}),
|
||||
|
||||
toDecoration(hint: ra.InlayHint.ChainingHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions {
|
||||
return {
|
||||
range: conv.asRange(hint.range),
|
||||
renderOptions: { after: { contentText: ` ${hint.label}` } }
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
class HintsUpdater implements Disposable {
|
||||
private sourceFiles = new Map<string, RustSourceFile>(); // map Uri -> RustSourceFile
|
||||
|
Loading…
Reference in New Issue
Block a user