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

Nested template strings aren’t (can't be?) highlighted properly #236

Open
guillaumebrunerie opened this issue Aug 10, 2022 · 0 comments
Open

Comments

@guillaumebrunerie
Copy link

The code below (Javascript) doesn’t get highlighted properly. We should have all stringN be highlighted with string color, but only string1 and string4 are.

const a = `string1 ${var1 + `string2${`string3` + var2}`}string4`;

What is supposed to be happening is that the whole string gets the string face, then the template substitution gets the embedded face, then the nested string gets (again) the string face, the nested substitution gets the embedded face, and so on.
The problem is that (as far as I understand) the priority of the queries is defined by the ordering in the queries file, but here we want both queries to have the same priority (more exactly we want shorter matches to have priority above longer matches). I'm not even sure if that's something that is supposed to work in upstream tree-sitter?

Anyway, I managed to fix it somehow (not tested very much) by ordering the matches by length (using cl-stable-sort) before applying the text properties, but I'm not sure if that's what we're supposed to do?
There could also be performance issues by sorting the matches at every keystroke (although I tried a bit on a 3500 lines file and couldn’t see any issue so far).

Any thoughts?

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

1 participant