Stream: contributing

Topic: tree-sitter feedback & adjustments


view this post on Zulip jan kili (Mar 10 2025 at 17:26):

Here's a topic for me to spam @Eli Dowling with questions and suggestions!

view this post on Zulip jan kili (Mar 10 2025 at 17:27):

(and anyone else who's invested in syntax highlighting or semantic editing)

view this post on Zulip jan kili (Mar 10 2025 at 17:30):

It looks like plain defs are mis-categorized as parameters:

inherits = "dracula"

"parameter" = "red"
"ui.text" = "grey"
"variable" = "black"

Screenshot_20250310_112103.png
(dracula colors variable.parameter orange+italics)

view this post on Zulip jan kili (Mar 10 2025 at 17:31):

What should the distinctions be between

view this post on Zulip jan kili (Mar 10 2025 at 17:33):

Also, if you'd prefer I take a more "try to fix it myself" approach, I can learn the query syntax and shift to PRs.

view this post on Zulip Eli Dowling (Mar 10 2025 at 17:36):

Not a clue tbh. Early a fellow came in and made a pr making the queries more specific... and it didn't break my highlighting so I just shrugged and merged it :sweat_smile:

view this post on Zulip Eli Dowling (Mar 10 2025 at 17:36):

if you want to know the correct ones:
https://docs.helix-editor.com/themes.html#scopes

view this post on Zulip Eli Dowling (Mar 10 2025 at 17:37):

and these:
https://docs.helix-editor.com/guides/textobject.html

view this post on Zulip Eli Dowling (Mar 10 2025 at 17:38):

I think part of the problem is that neovim uses different names. So he may have just been working of that list

view this post on Zulip Eli Dowling (Mar 10 2025 at 17:39):

Totally feel free to go through and fix any that improve things on the helix side and then PR it in.

view this post on Zulip jan kili (Mar 10 2025 at 19:13):

Interesting, module doesn't appear in Helix's docs - did you get it from a different list?

view this post on Zulip jan kili (Mar 10 2025 at 19:31):

I guess a bigger question is - what's the intended relationship between

because it all seems arbitrary to me.

view this post on Zulip jan kili (Mar 10 2025 at 20:26):

JanCVanB said:

Interesting, module doesn't appear in Helix's docs - did you get it from a different list?

Same for these:

view this post on Zulip Anthony Bullard (Mar 10 2025 at 21:15):

It’s hard for me to judge these until the examples have brace delimited blocks

view this post on Zulip Anthony Bullard (Mar 10 2025 at 21:16):

Then I can tell how much I like a certain highlighting scheme

view this post on Zulip Anthony Bullard (Mar 10 2025 at 21:16):

Oh, and of course, see it in Catppuccin Mocha

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:17):

All that actually matters is what's defined in the theme within helix. Everything else is just a suggestion.

view this post on Zulip Anthony Bullard (Mar 10 2025 at 21:18):

ahemNeovim

view this post on Zulip jan kili (Mar 10 2025 at 21:22):

Eli Dowling said:

All that actually matters is what's defined in the theme within helix. Everything else is just a suggestion.

Sure, but I'm wondering what is this sitter's source of truth for what to name the exported keys - do you want to export a superset of anything that downstream themes want to consume, including some redundant names for the same things? Are Helix's conventions given any higher priority than Neovim's?

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:27):

Anthony Bullard said:

ahemNeovim

Well Jan is editing the helix highlights.
The neovim has its own highlights file and the same rule applies there too.

view this post on Zulip jan kili (Mar 10 2025 at 21:28):

Anthony Bullard said:

ahemNeovim

I'm trying to make a set of editor-agnostic themes that color .roc files in a way that matches our mental model of the syntax :grinning_face_with_smiling_eyes:

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:30):

Oh, you basically just can't do that. The helix and neovim queries work different
They are interpreted in reverse order for example.
The conventions for names of things are different. It's all a total mess tbh.
That's why we maintain two sets of query files.

view this post on Zulip jan kili (Mar 10 2025 at 21:32):

Yes, and I plan to generate & maintain a separate file for each editor x theme.

view this post on Zulip jan kili (Mar 10 2025 at 21:34):

Now I see your neovim dir - so queries/highlights.scm should use Helix's highlighting scopes as the source of truth?

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:35):

Ahhh I think I understand now.
Well I would follow the conventions of each platform and then just add any extensions you need.

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:36):

From memory the highlights have precedence so you can do type.this.that and as long as a theme has type it'll highlight it even if it doesn't have the more specific versions.
Double check that though

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:37):

Yes, the default queries are for helix. Because it closely follows the tree sitter spec... Neovim just kinda does whatever

view this post on Zulip jan kili (Mar 10 2025 at 21:37):

Do you know where those 13 non-Helix-sourced scopes above came from?

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:39):

If you look at the repo the very first full request is from the guy adding extra highlighting, I'd guess it's from that.

view this post on Zulip jan kili (Mar 10 2025 at 21:39):

Gotttcha. Thanks!

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:39):

I know he wanted to build a more precise theme that added more information. But I think he might have been working in neovim

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:40):

He is probably in Zulip I'd imagine

view this post on Zulip jan kili (Mar 10 2025 at 21:40):

I can start working to align that file 100% with Helix conventions.

view this post on Zulip jan kili (Mar 10 2025 at 21:43):

Karl said:

I started messing with the tree-sitter grammar because I was trying to figure out why thing weren't highlighting. One thing led to another and I spent a good chunk of yesterday changing things and I now have seven reasonably sized commits. I'd like to know if you'd like them in one large PR or a set of smaller ones.

A lot of things are uncontroversial (e.g. tagging doc comments, tagging builtins) but some are more questionable like tagging match captures as parameters so that tree-sitters local analysis highlights typos.

Here's a before and after using my theme:

Screenshot-2024-04-01-at-5.06.49-PM.png
Screenshot-2024-04-01-at-5.08.03-PM.png

Some things come from extending the highlight match tags (e.g. separate colorspace for typedefs, highlighting fn defs) so other themes would need to be tweaked for full support.

Aha!

view this post on Zulip Eli Dowling (Mar 10 2025 at 21:45):

Hey nicely done

view this post on Zulip jan kili (Mar 10 2025 at 22:12):

JanCVanB said:

I can start working to align that file 100% with Helix conventions.

If @Karl doesn't voice any concerns, @Eli Dowling does this sound right to you?

view this post on Zulip Karl (Mar 10 2025 at 22:15):

I think it makes more sense to fit in with someone's standards. I like that the extra fields allow for additional highlighting but I expect I'm the only one taking advantage of it.

view this post on Zulip Eli Dowling (Mar 10 2025 at 22:19):

Yeah align then as much as possible. But also feel free to keep or adapt any existing extensions to the spec for roc specific stuff

view this post on Zulip jan kili (Mar 10 2025 at 22:43):

Sweet, I'll try!

view this post on Zulip jan kili (Mar 10 2025 at 22:44):

This is my work-in-progress refactor of Helix Dracula, with some three-way analysis of discrepancies: https://gitlab.com/JanCVanB/rocwise-editor-themes/-/blob/main/helix/dracula.toml?ref_type=heads

view this post on Zulip jan kili (Mar 11 2025 at 01:40):

@Eli Dowling What does "keep most generic types at the bottom for helix" mean? https://github.com/faldor20/tree-sitter-roc/blob/master/queries/highlights.scm#L205

view this post on Zulip jan kili (Mar 11 2025 at 02:02):

I infer that higher in the file is higher priority?

view this post on Zulip Eli Dowling (Mar 11 2025 at 04:15):

Correct!

view this post on Zulip jan kili (Mar 11 2025 at 04:57):

Is that just a Helix thing, hence the comment?

view this post on Zulip Eli Dowling (Mar 11 2025 at 07:06):

Yeah, neovim evaluates it the other way around. Which is why you may notice the order is kind of inverted

view this post on Zulip Jasper Woudenberg (Mar 11 2025 at 07:34):

With regards to the evaluation order: I ran into this as well working to pull in tree-sitter for syntax-highlighting in my static site generation platform. Sharing here in case it's useful: it looks like Helix is working on flipping the order:
https://github.com/helix-editor/helix/issues/9436

The order Neovim/Zed use does appear to be the "correct" one according to tree-sitter. It's hard to find though, I believe I found mention in the code for highlighting project included in tree-sitter, also these release notes:
https://github.com/tree-sitter/tree-sitter/releases/tag/v0.21.0

view this post on Zulip jan kili (Mar 11 2025 at 08:43):

So far I've refactored the highlights to make it easier to see the discrepancies: https://github.com/JanCVanB/tree-sitter-roc/blob/helixify_highlight_names/queries/highlights.scm

I'll continue by resolving them!

view this post on Zulip jan kili (Mar 11 2025 at 19:47):

@Eli Dowling I see you chose to highlight tags with @constructor and @type.enum.variant - those make sense and seem to be colored by Helix themes. There is a @tag name that we could use instead of @constructor with similar coloring support in themes, but it's not clearly superior.

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:25):

I am happy to leave it up to you to make the call on whether you think it looks better as a tag or a constructor. when I did it I don't believe my theme had any support for tag so I made it a constructor as that was what other languages used for unions.

Mostly I would also try and follow the conventions of other functional programming languages.

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:26):

It's nice if a user coming to roc from Haskell can look at roc code and immediately see familiar colours for familiar constructs

view this post on Zulip jan kili (Mar 11 2025 at 20:30):

Good call! I'll look into how Haskell's tree-sitter implementation(s?) categorize things. Any other comparables you want, in addition to Elm?

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:31):

Elm, Haskell, Ocaml, Scala, elixir would probably cover like 95% of all production FP code right?

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:31):

Can't forget my beloved Ocaml :stuck_out_tongue_wink:.

view this post on Zulip jan kili (Mar 11 2025 at 20:33):

Unrelated, I see that almost half of the custom highlight names I listed above seem to be to facilitate coloring the same symbols/things differently if they're in typedefs - is that something you want to maintain?

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:34):

All are probably worth a glance. I'd be inclined to weight the ones that are most recently created/updated with a lot more precidence.
TS norms and names have changed a fair bit over time, so it's worth taking recency into account

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:35):

Also for the queries you should be looking at the queries in the helix repo rather than any queries inside the actual tree sitter grammars. Sometimes they are quite different

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:35):

But helix ones are more likely to be more up to date with helix conventions/actually tested

view this post on Zulip jan kili (Mar 11 2025 at 20:37):

Cool, I'll default to injecting an indication they're original, like
@punctuation.delimiter.typedef
to
@punctuation.delimiter.roc.typedef

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:38):

JanCVanB said:

Unrelated, I see that almost half of the custom highlight names I listed above seem to be to facilitate coloring the same symbols/things differently if they're in typedefs - is that something you want to maintain?

I really don't care about that at all.
I think it'd be good to have a distinction between tag types and other types.
But also there isn't any harm in being more specific if people want to use them.
But yes I think prefixing them helps a lot

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:38):

I really wouldn't stress about it though. Other than annoying @Karl :sweat_smile:

view this post on Zulip jan kili (Mar 11 2025 at 20:38):

Oops misread your previous - understood

view this post on Zulip jan kili (Mar 11 2025 at 20:40):

Yeah the only ones I'm eager to fully delete are those used instead of a standard one.

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:40):

Oh sorry, yeah that was confusing. For total clarity, I did mean all the different languages highlight queries.

view this post on Zulip Eli Dowling (Mar 11 2025 at 20:42):

I trust you to make the right choice as far as weighing between being specific and just providing options that nobody will ever actually use.

I'd only suggest leaning towards simple and standard for the sake of future maintenance. Remember people can override this if they really want crazy over the top everything in rainbow.

view this post on Zulip jan kili (Mar 13 2025 at 01:29):

I have more ideas, but I'll pause here! https://github.com/faldor20/tree-sitter-roc/pull/33 Feedback very welcome :smile:

view this post on Zulip jan kili (Mar 13 2025 at 01:29):

Heads up, it's a nearly-total refactor. I rebased a bunch, to keep the incremental commit chain fairly readable.

view this post on Zulip jan kili (Mar 13 2025 at 05:06):

Here's a preview of the nearly-ready Helix Dracula theme that plays nicely with the PR above :heart_eyes:
https://gitlab.com/JanCVanB/rocwise-editor-themes/-/blob/improve_helix_dracula/helix/dracula.toml?ref_type=heads
Screenshot_20250312_230533.png

view this post on Zulip jan kili (Mar 13 2025 at 05:08):

... and that's with ui.text still set to a super faded grey - we now have seemingly-complete coverage, because the only times I see it in code files now is with tree sitter errors

view this post on Zulip Eli Dowling (Mar 13 2025 at 05:55):

Cool! I'll take a look in the next couple of days. Mostly, so long as it still looks good with vanilla themes I'm happy :)

view this post on Zulip jan kili (Mar 13 2025 at 12:35):

Sweet! No urgency, as this isn't blocking me.

Good call - I'll test it with the most popular builtins and post screenshots in the PR.

view this post on Zulip jan kili (Mar 13 2025 at 23:36):

:check: Posted.

view this post on Zulip Eli Dowling (Mar 14 2025 at 22:37):

@JanCVanB Just added a comment.

view this post on Zulip Eli Dowling (Mar 19 2025 at 20:17):

@JanCVanB Sorry this took so long. I made some alterations.
very happy with it overall, there were just a few places where I wanted to align better to other langauages/helix recommendations
I made a pr to your branch:
https://github.com/JanCVanB/tree-sitter-roc/pull/1

view this post on Zulip jan kili (Mar 19 2025 at 20:33):

Woohoo! Thanks, I'll review that today.

view this post on Zulip jan kili (Mar 20 2025 at 18:25):

@Eli Dowling Merged! Ready for re-review on 33 :smile:

view this post on Zulip Eli Dowling (Mar 20 2025 at 19:17):

@JanCVanB you were happy with all those changes? Just letting you know I'm totally open to feedback or disagreement.

view this post on Zulip Eli Dowling (Mar 20 2025 at 19:20):

If you're happy at this point, I'm happy to and I'll merge :)

view this post on Zulip jan kili (Mar 20 2025 at 20:09):

I was indeed happy with all :)

view this post on Zulip jan kili (Mar 20 2025 at 20:11):

I'm confident that any room for improvement will be found by incoming PRs for the remaining TODOs

view this post on Zulip jan kili (Mar 20 2025 at 20:12):

After this refactor merges, other PRs can be much more parallel

view this post on Zulip jan kili (Mar 20 2025 at 20:30):

For example, you removing these is consistent with your choice to recategorize : as punctuation. There are multiple different answers to "so now how can I color : the same as the key before it in records", but we should leave that to follow-up discussions and not hold up this refactor.

view this post on Zulip Richard Feldman (Mar 20 2025 at 21:01):

Eli Dowling said:

Elm, Haskell, Ocaml, Scala, elixir would probably cover like 95% of all production FP code right?

if Clojure is in there then yes, but I suspect Clojure is over 5% of that by itself

view this post on Zulip Eli Dowling (Mar 20 2025 at 21:50):

See I'm always just a little leery of calling clojure FP... It's just, it feels distinct from those other languages in some ways. I recently saw an article in lobsters comparing an Ocaml and clojure implementation of the same thing and I feel like Ocaml one would be immediately understandable/ seem normal to any user of the other languages I listed. The clojure one... Not so much

Also comparing the token assignment of clojure to us probably doesn't reveal much given it's a lisp :sweat_smile:

view this post on Zulip Richard Feldman (Mar 20 2025 at 22:09):

big can of worms there haha

view this post on Zulip Richard Feldman (Mar 20 2025 at 22:11):

but yes, agreed that Clojure syntax highlighting won't have much to do with ours :big_smile:

view this post on Zulip Eli Dowling (Mar 20 2025 at 22:11):

That can of worms is why I want to learn clojure sometime... If other people are chowing down on the worms and just absolutely loving it, at some point you've gotta wonder.. maybe worms are worth trying.

view this post on Zulip Brendan Hansknecht (Mar 20 2025 at 22:46):

I would have guessed that clojure is more fp than scala

view this post on Zulip Brendan Hansknecht (Mar 20 2025 at 22:47):

Also, I wonder how much production code is in erlang. Just silently running the world.

view this post on Zulip Eli Dowling (Mar 21 2025 at 00:33):

Hahah mee too Brendan, me too...
It comes up anytime I feel I've been using something for a long time and I have the realisation that nothing has ever had a single failure.
I have the little, sniff sniff smells like bean... Wait, no it's BEAM

view this post on Zulip Undefined Behavior (Mar 21 2025 at 05:08):

Brendan Hansknecht said:

Also, I wonder how much production code is in erlang. Just silently running the world.

90% of internet traffic runs through Erlang. See: https://x.com/guieevc/status/1002494428748140544

cc @Brendan Hansknecht

view this post on Zulip Undefined Behavior (Mar 21 2025 at 05:15):

This is getting off-topic, but I'd asked this question because I was curious if, theoretically, a Roc Platform could exist that copied the behavior of the Erlang Runtime System and BEAM VM. Obviously, it's no joke to re-implement OTP/BEAM, but would a Roc Platform make it possible? (I'm new to Roc, pardon my ignorance)

view this post on Zulip Brendan Hansknecht (Mar 21 2025 at 06:21):

Theoretically you could use a roc platform to run roc directly on the BEAM VM. Roc would be a native library and the platform would be written in erlang or elixir

view this post on Zulip Brendan Hansknecht (Mar 21 2025 at 06:21):

Though you could also fully reimplement the BEAM VM in a roc platform instead


Last updated: Jul 06 2025 at 12:14 UTC