zed icon indicating copy to clipboard operation
zed copied to clipboard

Semantic highlighting

Open JosephTLyons opened this issue 3 years ago • 5 comments

I'm dyslexic, so I actually have a hard time reading code without my mind getting jumbled up. One feature that I've found that has helped me tremendously is JetBrains' Semantic Highlighting. I want to be reiterate the JetBrains part of that because other editors also have features called "Semantic Highlighting," but not all of those seem to be the same feature.

What JetBrains' Semantic Highlighting does is highlight all variables in a function with different colors. Here is a minimal example.

Sublime Text 4: Screen Shot 2021-09-24 at 12 21 18 AM

PyCharm: Screen Shot 2021-09-24 at 12 21 58 AM

You'll notice that suit_value and suit_string are highlighted differently. You can easily trace them out individually over the function because of this. This example is rather minimal, but in larger, more complex functions, the feature becomes more obvious and invaluable. If you don't have issues with dyslexia, this may be a bit jarring to you, but this is has become essential to my development; I almost see it as an accessibility feature and I'd imagine others do as well. As for the implementation, I'm not quite sure how they do it. I know the color changes depending on the variable name length, so maybe they hash the name out into something that is used to generate a color.

I caught wind that VS Code was implementing an API for Semantic Highlighting some time ago, but their version is about highlighting language keywords differently and doesn't seem to have anything to do with local variables. I don't believe Atom ever had this built in, but I found a package or two back in the day that tried to add the functionality, but I recall there being some issue with it.

JosephTLyons avatar Jun 23 '22 22:06 JosephTLyons

One amazing capability rust-analyzer provides is a "secret" unresolved reference diagnostics. When VSCode is additionally configured with

"editor.semanticTokenColorCustomizations": {
        "enabled": true,
        "rules": {
            // All-themes colors
            "unresolvedReference": {
                "foreground": "#c93f3f",
                "fontStyle": "bold"
            },
        },
    },

it's able to provide cargo-less, realtime, diagnostics:

image

SomeoneToIgnore avatar Oct 19 '22 19:10 SomeoneToIgnore

I'm dyslexic, so I actually have a hard time reading code without my mind getting jumbled up. One feature that I've found that has helped me tremendously is JetBrains' Semantic Highlighting. I want to be reiterate the JetBrains part of that because other editors also have features called "Semantic Highlighting," but not all of those seem to be the same feature.

What JetBrains' Semantic Highlighting does is highlight all variables in a function with different colors. Here is a minimal example.

Sublime Text 4: Screen Shot 2021-09-24 at 12 21 18 AM

PyCharm: Screen Shot 2021-09-24 at 12 21 58 AM

You'll notice that suit_value and suit_string are highlighted differently. You can easily trace them out individually over the function because of this. This example is rather minimal, but in larger, more complex functions, the feature becomes more obvious and invaluable. If you don't have issues with dyslexia, this may be a bit jarring to you, but this is has become essential to my development; I almost see it as an accessibility feature and I'd imagine others do as well. As for the implementation, I'm not quite sure how they do it. I know the color changes depending on the variable name length, so maybe they hash the name out into something that is used to generate a color.

I caught wind that VS Code was implementing an API for Semantic Highlighting some time ago, but their version is about highlighting language keywords differently and doesn't seem to have anything to do with local variables. I don't believe Atom ever had this built in, but I found a package or two back in the day that tried to add the functionality, but I recall there being some issue with it.

Btw. Sublime does support this, given the right color scheme I believe. But unrelated.

TerminalFi avatar Oct 19 '22 23:10 TerminalFi

bump, literally me

shrimpwtf avatar Oct 23 '23 17:10 shrimpwtf

You are asking for semantic highlighting but actually requesting hashed highlighting (or whatever it's called). Two variables with different names would not be highlighted differently by semantic highlighting since those are semantically the same - local variables.

rchl avatar Jan 25 '24 05:01 rchl

I also really enjoy VS Code's semanticTokenColorCustomizations. You can also use it to format function parameters and const variables differently than other variables:

"editor.semanticTokenColorCustomizations": {
    "rules": {
      "parameter": { "italic": true, "foreground": "#E9B381" },
      "variable.readonly": "#B1B4F3"
    }
  },

Would be great if this was supported by Zed.

graup avatar Jan 26 '24 17:01 graup

vscode also have a plugin for "hashed highlighting" : vscode-color-identifiers-mode

This extension and the original semanticolor are sadly a bit hackish.

I for one would really like to have a simple extension API hook for post-highlighting (something like (token, context, color, ...) -> finalColor that could be hooked to give a hashed color preferably in the tone of the current theme).

paradoxxxzero avatar May 29 '24 08:05 paradoxxxzero