-
This will likely require us to refactor the current syntax highlighting system to accommodate other syntax highlighting methods. |
Beta Was this translation helpful? Give feedback.
Replies: 23 comments 4 replies
-
I'm not a big fan of the LSP highlighting spec. It requires a lot of back and forth traffic with the LSP to do highlighting in real time. VSCode should adapt tree-sitter already.. |
Beta Was this translation helpful? Give feedback.
-
I plan to make it optional in |
Beta Was this translation helpful? Give feedback.
-
tree-sitter is limited such that it does not have context of the language, like similar returns highlight or similar .await highlights. |
Beta Was this translation helpful? Give feedback.
-
Also, for Rust, |
Beta Was this translation helpful? Give feedback.
-
Does this mean this won't ever be a first class feature of helix? I'm not really fussed either way. I only ask because I'm working on a tool to convert themes between several text editors formats and this would factor into the implementation longer term. |
Beta Was this translation helpful? Give feedback.
-
While LSP is heavy, tree-sitter does not provide comparable highlighting. One solution could be to have LSP as an opt-in, with tree-sitter as the default. As petty as it sounds, the lack of semantic highlighting is one of the very few things that hold me from daily driving Helix. Being able to jump in and see the same theming quality as I'm used to is a must for me, and I imagine other prospective users as well. |
Beta Was this translation helpful? Give feedback.
-
@LouisGariepy IIRC in the release notes I remember there is |
Beta Was this translation helpful? Give feedback.
-
Could a maintainer point out the conditions for an acceptable solution then? If you simply don't want this feature in Helix (which is totally fair!), maybe you could close or mark as "wontfix" to avoid confusion. To be clear, I'm asking from the perspective of someone who'd like to contribute to this effort. I just don't want to waste my (and your) time with a feature that will never be merged. |
Beta Was this translation helpful? Give feedback.
-
I'd be interested to see a side by side comparison with the theme/languages you use if you don't mind? In my experience, it's the opposite. I quite often find tree sitter highlighting being better than the alternatives. |
Beta Was this translation helpful? Give feedback.
-
i miss mutable variables (in rust) with |
Beta Was this translation helpful? Give feedback.
-
That's doable with a custom |
Beta Was this translation helpful? Give feedback.
-
Is it though ? They're talking about highlighting the variable as mutable each time it's used, not just at the definition point. I honestly don't know if this is possible, if it is it seems like a quick win to add it to helix |
Beta Was this translation helpful? Give feedback.
-
Yeah, that's doable with a |
Beta Was this translation helpful? Give feedback.
-
Edit for future readers: Please read archseer's response to my comment, which gives a more correct explanation of what is and what is not possible to do with tree-sitter Vs LSP highlighting. My comment contains some inaccuracies, but I'll leave it as is for posterity. Alright! I jotted down some basic code to see the potential differences. I tried to emphasize differences due to "limitations", not stylistic ones. There might be more that I'm missing for complex code bases, this is just basic stuff. Here goes: Public items are distinct from private ones.Note that this holds for any item that can be made public, not just functions. Mutable variables and operators are distinct from immutable ones.Mutable functions/method calls are likewise distinct. Variables in format strings are recognized as such (distinct from the rest of the string).Doc comments are distinct from "regular" comments.Might be hard to see (stylistic choice), but the doc comments are lighter in color. Generic types are distinct from their trait bounds.Macro rules binding arguments are distinct from constant patterns.
Attribute syntax is recognized properly.Imports (
|
Beta Was this translation helpful? Give feedback.
-
Most of these are currently achievable by modifying the queries except for imports and accurate type highlighting. With #1252 however, I think that would be addressed as well. There are certainly limitations to tree-sitter, such as not being able to highlight markdown in doc comments, but maybe that's something that could be worked on in the future. Language-specific features such as trait methods probably do need LSP highlighting. |
Beta Was this translation helpful? Give feedback.
-
It looks like you deleted your last comment, but I think you have a misunderstanding of how tree-sitter works. From how I understand it, tree-sitter a parser generator with an AST geared towards syntax highlighting. However, you also need to write queries to capture AST nodes such that they can be highlighting in themes. You can check the tree-sitter playground to see some of what these ASTs look like. See: |
Beta Was this translation helpful? Give feedback.
-
@LouisGariepy Thanks for that rundown. I think you've demonstrated why it would be a useful feature. I do think that the main thing it gives us that tree sitter doesn't is type related highlighting. I'm pretty sure with enough time you could create tree-sitter queries for anything that is purely syntax focused. Here's an example of doc comments & string interpolation already working in Typescript in helix. I might be using a modified Everforest theme, I can't remember. |
Beta Was this translation helpful? Give feedback.
-
Yeah, tree-sitter grammars are parsers that build an in-memory AST of the file. Then the highlighting queries are like selectors that tag specific parts of the tree with span names, and themes can hook into these spans to highlight them as they wish.
This is as simple as adding a highlighting query that themes can hook into.
Can be done with a locals query.
Probably needs a change in the parser, but it could be injected into such strings and the embedded parts interpolated. It works in other languages.
This is something I've been waiting for tree-sitter/tree-sitter-rust#128
This is as simple as adding a highlighting query that themes can hook into.
Not sure yet since macros produce a token tree but probably possible.
Fixed in 301f5d7
These two are to do so yeah, it could be LSP specific.
Probably possible with locals. I wish LSP provided these highlights as an augmented layer on top of regular highlighting instead of completely overriding highlighting and churning out tons and tons of spans per keypress. Anyway, for this to be implemented, a vec of produced spans would have to sit somewhere on the document, that would then convert to a |
Beta Was this translation helpful? Give feedback.
-
I think in combination with stack graphs we wouldn't just get go to definition support but also a way to determine the item type since we can peek at the definition |
Beta Was this translation helpful? Give feedback.
-
A discussion on how LSP syntax highlighting can be gracefully implemented was discussed on Matrix: Tree-sitter will be the default highlighter, while range-based LSP syntax highlighting will be merged asynchronously. Additionally, we would compute the correct highlights for locals based on what the LSP syntax highlighter sends. |
Beta Was this translation helpful? Give feedback.
-
I made #6102 for this, if you're interested in the feature don't hesitate to try it out and report bugs :) (or the absence of them, which is always nice) |
Beta Was this translation helpful? Give feedback.
-
This is also an important feature for people coming from Visual Studio. For .NET languages, Visual Studio the identifiers of types are highlighted differently depending on their "kind"/"storage". E.g. class, struct, enum, interface. This greatly helps reading code, because the reader instantly sees the storage semantics of the identifiers used in code. Semantic highlighting would enable this set of features in helix 🚀 FWIW: in Visual Studio the semantic highlighting also lags behind the structural highlighting. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
A discussion on how LSP syntax highlighting can be gracefully implemented was discussed on Matrix:
Tree-sitter will be the default highlighter, while range-based LSP syntax highlighting will be merged asynchronously. Additionally, we would compute the correct highlights for locals based on what the LSP syntax highlighter sends.