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

Module names aren't highlighting #15

Closed
maco opened this issue Dec 15, 2021 · 17 comments
Closed

Module names aren't highlighting #15

maco opened this issue Dec 15, 2021 · 17 comments

Comments

@maco
Copy link

maco commented Dec 15, 2021

tree-sitter-elixir was pushed live on GitHub today 🎉 , but @the-mikedavis pointed out that module names aren't highlighting
Example: https://github.com/elixir-mint/mint/blob/1ea7731d921840ad75a47fa9415525c3d94b9980/mix.exs#L1-L2

Screen Shot 2021-12-15 at 3 15 32 PM

Example 2: https://github.com/elixir-mint/mint/blob/1ea7731d921840ad75a47fa9415525c3d94b9980/lib/mint/http1.ex#L108-L113
Screen Shot 2021-12-15 at 3 16 09 PM

CC @patrickt (who asked to be CC'd so he can push an updated grammar on GitHub's end when this is handled.)

@jonatanklosko
Copy link
Member

Hey! Modules are highlighted correctly for me when running tree-sitter highlighter locally:

image

This is probably related to the theme GitHub uses? The modules get the type highlight token, should we be using something else?

@the-mikedavis
Copy link
Member

the-mikedavis commented Dec 15, 2021

From what I can tell it looks like these highlights aren't ending up syntax-highlighted to any color:

(alias) @type
(call
target: (dot
left: (atom) @type))

which is curious because the java queries for example use @type as well: https://github.com/tree-sitter/tree-sitter-java/blob/ed3a87f750b1d1d533f15ab93fef3e1f5a46e234/queries/highlights.scm#L22-L23, and I assume java is tree-sitter highlighted in github, and I see class names highlighted as I would expect (e.g. here)

Maybe it's just a precedence issue? Or maybe github also needs a tags.scm to identify classes/modules?

@jonatanklosko
Copy link
Member

jonatanklosko commented Dec 15, 2021

Without @type the module name doesn't get any highlighting token, so there should be no conflict either way 🤔

The module name gets the pl-smi class instead of pl-en (or pl-v).

@the-mikedavis
Copy link
Member

Ah good find: seems like the problem isn't with the grammar/queries here but something in how GitHub is mapping the tree-sitter scopes to class names. I'm not sure how to get the ball rolling with GitHub support on this. Maybe we can re-use the contact mentioned in #2 (comment) (cc: @josevalim)?

@patrickt
Copy link
Contributor

Yeah, I don’t think @type is quite right here. I’m trying to figure this out (and will assemble some docs, hopefully).

@jonatanklosko
Copy link
Member

The tests for Java tree-sitter highlighting are in this file and it confuses me because tokens annotated as type are highlighted with three different colors. This would only make sense if for some reason tree-sitter is not used for highlighting Java files.

Looking at similar tests for JavaScript and Ruby, it looks like modules/classes use the constructor token, which doesn't seem suitable in our case.

@patrickt
Copy link
Contributor

@jonatanklosko Correct: I just found out that tree-sitter-java’s highlights aren’t hitting prod traffic, so a better comparison is Python or Ruby in their respective repositories. Apologies for the confusion.

@jonatanklosko
Copy link
Member

Is the mapping/theme a part of some open source project or is it something you maintain internally?

@patrickt
Copy link
Contributor

patrickt commented Dec 15, 2021

It’s closed-source. I’m dotting my i’s properly and checking to make sure I can give you the whole list without running awry of lawyers. But yes, @type maps to the pl-smi class, which doesn’t appear to be used. I would try constructor for the time being; I know it doesn’t exactly match the semantics of what modules mean in Elixir, but the Right Fix here is for us to change our backend to recognize a new tag, @module. This will take longer, though I’ll put the wheels in motion. In the meantime, I can deploy updated changes to highlights.scm basically instantly, so a quick fix might be suitable here if it’s bumming people out.

@patrickt
Copy link
Contributor

@jonatanklosko Actually, I think I can get that @module change in pretty fast. So change those @type to @module and I’ll coordinate on my backend.

@jonatanklosko
Copy link
Member

Fantastic!

@patrickt
Copy link
Contributor

patrickt commented Dec 15, 2021

Okay, the changes required to recognize @module in syntax highlighting in our backend are coming in and should be deployed in the next fifteen minutes or so. Once #16 lands, I’ll bump the submodule in our backend, and deploy again. Thanks all for your patience—this is our first community-maintained syntax highlighter, I believe, so thanks for being our guinea pigs! 😅

@jonatanklosko
Copy link
Member

Beautiful, thanks for all the help! I've just merged the change, so we should be good on this side :D

patrickt added a commit to tree-sitter/tree-sitter that referenced this issue Dec 15, 2021
Some languages have the notion of modules, and to represent those
we've started to use a `@module` tag, as discussed in
elixir-lang/tree-sitter-elixir#15.
Because historically we've used the constructor highlight color for
modules in JS/Ruby, it's defined to map to the same color.
@patrickt
Copy link
Contributor

This is working now:
image

@jonatanklosko
Copy link
Member

Awesome, thanks! :shipit:

The examples linked in the issue description are still the same, is that caching temporary?

@patrickt
Copy link
Contributor

@jonatanklosko Yeah, I think that’s memcached doing its thing. It’ll fall out of cache eventually, heh!

@jonatanklosko
Copy link
Member

Perfect :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants