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

Improve Gleam syntax highlighting #4

Open
JosephTLyons opened this issue Oct 18, 2024 · 4 comments
Open

Improve Gleam syntax highlighting #4

JosephTLyons opened this issue Oct 18, 2024 · 4 comments

Comments

@JosephTLyons
Copy link

JosephTLyons commented Oct 18, 2024

This issue was moved from the zed repository, originally filed by @ghivert:

Hi! I'm not sure where to talk about the subject, so I prefer open an issue. 🙂

Those days, I was trying to see if we can improve the syntax highlighting for Gleam.
Currently, in the syntax highlighting, we got all functions calls highlighted as records access when they're done in a fully qualified way.

import my_package
pub fn main() {
  my_package.function() // <-- On Zed, this is highlighted as record property, and not function.
}

What do you think to modify the Gleam syntax highlighting (i.e. highlights.scm) to highlight every functions used from records with proper functions highlighting? I tried to implement it here to figure out how it can be. (I'm absolutely not sure it's correctly implemented, I mainly wanted to prove myself it was possible.) I also joined two screenshots on how it feels directly in the editor.

I know tree sitter can not know if the field is a function or not (because we can have a constant, so calling it will result in an error), but the LSP could take care of this, and — in my opinion — having a proper function highlighting for fields called as functions will improve readability.

Function syntax highlighted

Capture d’écran 2024-08-26 à 15 29 38

Record syntax highlighted

Capture d’écran 2024-08-26 à 15 29 46
@JosephTLyons
Copy link
Author

@ghivert

@ghivert
Copy link

ghivert commented Oct 19, 2024

Link is broken, correct link.

To expand a bit, I think the syntax highlighting should help the reader to easily distinguish the context. When you encounter something like function_call() or namespace.function_call(), having them highlighted as function call would help, because that's the information you want to transmit to your reader. Thanks to tree sitter, we can even highlight pieces of code like data |> namespace.function_call correctly. We can sometimes have false positive: when writing data |> struct.field, field will be highlighted as a function call even if it's not a function, but the LSP will trigger a warning. I think it's safe to consider that most of the time, we're spending time to read code, and because of the nature of Gleam, the code will be correct (thanks to the compiler). As such, it would make sense to favour easing of reading.

I'm curious to hear your opinions here. Of course, I'd be happy to open a proper pull request if we agree on this. 🙂

@JosephTLyons
Copy link
Author

I updated the link and made it known the text came from you.

@ghivert
Copy link

ghivert commented Nov 6, 2024

Friendly reminder to know if some maintainers can take a look at it. 😄

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

No branches or pull requests

2 participants