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

Highlight field expression in types #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

guimarqu
Copy link
Contributor

Hey,

I'm using zed for a while and love to write Julia code with this editor.

However, when I write something like x::Module.T, the type Module.T is not highlighted and it's annoying.

So I took the evening off to understand how tree sitter and the highlight.
Here is a suggestion for fixing a part of the bug.

You see the difference before and after with the two following screenshots.

before
Capture d’écran 2024-12-20 à 23 22 23
after
Capture d’écran 2024-12-20 à 23 21 35

As you can see I could not make it recursive because I could not find a way to give the @type tag priority over the @variable.member tag. The most specific match seems to take precedence.

It's far from perfect but it improves the current behavior and I guess Module.SubModule.T is enough for 80% of users.
I'm opening it as a draft PR because somebody here might have the solution.

@guimarqu guimarqu changed the title Highlight field expression types Highlight field expression in types Dec 21, 2024
@guimarqu
Copy link
Contributor Author

It seems impossible to match a recursive expression tree-sitter-grammars/tree-sitter-lua#24.

@guimarqu guimarqu marked this pull request as ready for review December 21, 2024 14:47
@guimarqu
Copy link
Contributor Author

guimarqu commented Dec 21, 2024

I improved in covering all the cases I could think about.
To ensure my suggestion works, I make the difference between modules and types by giving the correct capture.

I also changed my theme to highlight in the following screenshots the differences between the current version and my PR :

  • red for variable.member
  • green for module
  • blue for type

current version (main branch) :
Capture d’écran 2024-12-21 à 21 24 51

PR :
Capture d’écran 2024-12-21 à 21 24 32

Here are my theme overrides :

"experimental.theme_overrides": {
    "syntax": {
      "type": {
        "color": "#0000AA",
        "font_weight": 700
      },
      "variable.member": {
        "color": "#AA0000",
        "font_weight": 700
      },
      "module": {
        "color": "#00AA00",
        "font_weight": 700
      }
    }
  }

@piechologist
Copy link
Collaborator

Thanks for your PR! I agree that should be improved.

Would you mind making this PR upstream at tree-sitter-julia? We track their reference queries which makes it easier to update the grammar and maintain our repo. Also, this would benefit other projects like neovim that use the grammar.

Let's keep this draft open to track the progress on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request external:tree-sitter Related to tree-sitter-julia
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants