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 update #50

Merged
merged 8 commits into from
Dec 18, 2024
Merged

Conversation

hugopl
Copy link
Collaborator

@hugopl hugopl commented Dec 18, 2024

This updates the highlight queries with new recent features.

It also add a injections.scm, currently just for heredoc and comments, because yes... there's a comments tree-sitter parser, hehehe. I knew about this when I tried to submit the queries to nvim-tree-sitter.

heredoc injections works nicely if you do SQL queries in heredoc strings, as you can see on github itself:

sql = <<-SQL
select foo from bar;
SQL
sql = <<-NOTSQL
select foo from bar;
NOTSQL

The same can be done for regexes when #49 gets fixed.

@hugopl
Copy link
Collaborator Author

hugopl commented Dec 18, 2024

image
my nvim is now crystal colorful ❤️ , despite of the errors in macros 😅

If my time permits I'll try to write other queries for nvim like indent, fold, etc... and submit the patch to nvim-tree-sitter.

@devnote-dev
Copy link
Collaborator

Do these changes also highlight calls without parentheses? It has been a frequent request recently.

@nobodywasishere

This comment was marked as off-topic.

@@ -1,31 +1,29 @@
(identifier) @variable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this one? Is it conflicting with something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For helix at least, that would match every identifier as a variable, regardless of the rest of the file due to how it parses in comparison to neovim

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'd want more sophisticated matching of local variables anyways: https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the start of a locals.scm above that uses those actually

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I noticed it was matching too much due to being too generic.

So I removed in a attempt to avoid multiple matches for the same node.

@hugopl
Copy link
Collaborator Author

hugopl commented Dec 18, 2024

Helix uses @keyword.control.if while nvim uses @keyword.conditional... I should had put the list of captures of each editor on txt files and diff them instead of being lazy and try to find the differences by eye 😅

Ok to have the directory structure?

└── queries
    ├── helix
    ├── nvim
    └── zed

@nobodywasishere
Copy link
Member

@hugopl that works for me!

@hugopl
Copy link
Collaborator Author

hugopl commented Dec 18, 2024

PR Updated, I didn't added the indent queries because I wasn't able to make it work on nvim yet.

But folding is working, still need some adjustments left for future PRs. e.g. some nodes must be created on if (and rescue IIRC), so folding an if wont fold entire if/else/end block, but just the if.

image

@nobodywasishere
Copy link
Member

some nodes must be created on if (and rescue IIRC)

Can you create an issue for what's needed to accomplish this?

@hugopl
Copy link
Collaborator Author

hugopl commented Dec 18, 2024

some nodes must be created on if (and rescue IIRC)

Can you create an issue for what's needed to accomplish this?

Nevermind... the behavior I was expecting seems not to be the behavior I see on other grammars.

On:

if foo
  hey
else
  ho
end

when folding the if, I was expecting to have:

if foo...................
else
  ho
end

but what I get is what other languages seem to also do, fold the entire if/else/end.

if foo...................

So not an issue.

since it's approved, could someone merge it, plz? 😁

Copy link
Member

@nobodywasishere nobodywasishere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@nobodywasishere nobodywasishere merged commit 734ecdd into crystal-lang-tools:main Dec 18, 2024
3 checks passed
@hugopl
Copy link
Collaborator Author

hugopl commented Dec 18, 2024

Ooops, sorry for not seeing the comments. I always got confused by the github interface and keep missing things in the communication.

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

Successfully merging this pull request may close these issues.

4 participants