HiPhish / rainbow-delimiters.nvim

Rainbow delimiters for Neovim with Tree-sitter
https://gitlab.com/HiPhish/rainbow-delimiters.nvim
Apache License 2.0
490 stars 37 forks source link

feat(sql): add support for sql #22

Closed liljaylj closed 12 months ago

liljaylj commented 12 months ago

add support for sql

HiPhish commented 12 months ago

Does this actually work for you? I tried some simple queries and this one is giving me problems:

select *
from products
where (
    Product_Category = 'Fit'
    and  Product_number IN (1234, 1235, 1236, 1237, 1238)
)
or
    (Product_Category in ('Tight', 'Wide') and Product_number = 1324);

The first pair of parentheses is blue (level 2) and the second one is red (level 1), but both should be red (level 1).

Screenshot_20230809_155638

I think the problem is that in the tree all parentheses are on the same level, which means the pattern

(binary_expression
    "(" @opening
    ")" @closing) @container

matches multiple @opening and @closing captures. This might resolve on its own when neovim/neovim#17099 gets solved in Neovim. But I am just guessing here. What is your opinion, should I just merge it as is and hope for the best or should we wait and see? The question is which is the lesser evil, sometimes broken highlight pairs or no highlight pairs at all?

In either case please write a small test file here as well.

liljaylj commented 12 months ago

i see. may it be because parentheses are outside of binary_expression?

image

HiPhish commented 12 months ago

No, they are still part of some binary_expression, just not the one you are looking at. Press a in the TS Playground to toggle the anonymous nodes and you will see where in the tree the parentheses are. This would not be a problem if there was some parenthesized_expression node that wraps the pair like in some other languages, but here all the parentheses are children of the same @container node. This makes the @opening and @closing capture match multiple nodes each, which causes chaos.

liljaylj commented 12 months ago

@HiPhish , can you, please, look at the changes i made in last commit

HiPhish commented 12 months ago

Looks good. Especially the last pattern, I am quite surprised that it actually works.