Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlay hint colorings #5337

Closed
Ciantic opened this issue Jul 12, 2020 · 7 comments
Closed

Inlay hint colorings #5337

Ciantic opened this issue Jul 12, 2020 · 7 comments
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium S-actionable Someone could pick this issue up and work on it right now

Comments

@Ciantic
Copy link

Ciantic commented Jul 12, 2020

Suggestion: Have configurable inlay hint colorings. At least two: if the inlay hint pushes the text, it may have different color. If the inlay hint is at the end of line, have a different color option.

I've noticed a pattern: when the inlay hints comes at the end of the line, I want them to be more grayed out. But when they push out the text further, I'd like them to be way more visible.

Here is a classic case of this: #4079

Notice how the image:

Bad indentation

Makes it looks like the indendation is wrong. This is because the inlay hints looks as if they are empty space, because they are so invisible.

Yet there is nothing wrong with the way inlay hints are in there, or with their indentation, it's just illusion because the color is so invisible.

If the inlay hints that push the text could be more visible it would make the indentation to look right IMO.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Jul 13, 2020

rust-analyzer server only provides the hint text and type, and the decorations are implemented on the client side.

On VSCode client side, we separate the hints into 3 different categories (type, param and chaining hints), each having a separate style config.
All the code related to the styling is located in the inlay_hints.ts file, here are the type hints decoration options:

https://github.com/rust-analyzer/rust-analyzer/blob/5ca7cd9/editors/code/src/inlay_hints.ts#L43-L57

From the VSCode API point of view, the decoration styling boils down to the options defined in https://vshaxe.github.io/vscode-extern/vscode/ThemableDecorationAttachmentRenderOptions.html (this is what's used in after: or before: in the decorations from the links above)
For the issue ticket, color property can be used.

In order to add the color, you need to add more options (with reasonable defaults for both light and dark themes) somewhere here: https://github.com/rust-analyzer/rust-analyzer/blob/5ca7cd9/editors/code/src/config.ts#L99-L107 and then use it in inlay_hints.ts.

@SomeoneToIgnore SomeoneToIgnore added the E-has-instructions Issue has some instructions and pointers to code to get started label Jul 13, 2020
@Veetaha
Copy link
Contributor

Veetaha commented Jul 13, 2020

It is way simpler than you think. This way the user can control the color of the hints in settings.json now:

    "workbench.colorCustomizations": {
        "[Default Dark+]": {
            "rust_analyzer.inlayHint": "#a70000",
        }
    },

Currently, this is the most granular way to do this, but it is simple to make it more configurable:
Add two more colors configs to this array:
https://github.com/rust-analyzer/rust-analyzer/blob/4b1c3724364ff538acdcb44bdd23d501ef54cff3/editors/code/package.json#L686-L694
Say rust_analyzer.inlayHint.parameterHints, rust_analyzer.inlayHint.typeHints and rust_analyzer.inlayHint.chainingHints (I recommend being consistent in naming with rust-analyzer.inlayHints.* settings, though this is currently already inconsistent :D).

Change the new vscode.ThemeColor('rust_analyzer.inlayHint') lines to use appropriate rust_analyzer.inlayHint.* id from package.json here:

https://github.com/rust-analyzer/rust-analyzer/blob/4b1c3724364ff538acdcb44bdd23d501ef54cff3/editors/code/src/inlay_hints.ts#L43-L89

Probably add some user docs for this feature

@Ciantic
Copy link
Author

Ciantic commented Jul 13, 2020

@Veetaha my gripe is with single color. I want multiple colors. Perhaps starting with giving typeHints, chainingHints, parameterHints a different color.

(Also I noticed something else, I would like to hide parameter name hints for single argument functions, or two argument functions with different types if they are on single line.)

@tmcguire
Copy link

tmcguire commented Aug 25, 2020

On a related note, I wish the background color of the inlay hint was configurable. With a background color, it would be much easier to distinguish inlay hints from the surrounding code.
Example from Android Studio's default configuration:
image

I guess the slightly smaller font also helps to distinguish.

@Veetaha
Copy link
Contributor

Veetaha commented Aug 26, 2020

Vscode doesn't provide an API to configure the font size of our inlay hints but changing the background color is doable (#5885), otherwise I suggest pushing the upstream issue forward: microsoft/language-server-protocol#956

bors bot added a commit that referenced this issue Aug 26, 2020
5885: Make inlay hints colors more configurable r=matklad a=Veetaha

**[BREAKING CHANGE]**

Tackles #5337 (comment) 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>
@flodiebold flodiebold added the S-actionable Someone could pick this issue up and work on it right now label Dec 22, 2020
@Veykril
Copy link
Member

Veykril commented Dec 14, 2021

Configuration for this was actually implemented in #5885, background coloring as said is relient on the client offering such a feature(and judging from the issue it will never happen unfortuantely) so I'll go ahead and close this.

@Veykril Veykril closed this as completed Dec 14, 2021
@boogiefromzk
Copy link

boogiefromzk commented Jun 27, 2023

For ones who wonder, edit settings.json adding (replace the theme with your preferred one):

    "workbench.colorCustomizations": {
        "[Default Light+]": {
            "editorInlayHint.background": "#ffffff",
            "editorInlayHint.foreground": "#aaaaaa"
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

8 participants