lezer-parser / lezer

Dev utils and issues for the Lezer core packages
33 stars 1 forks source link

Does Lezer support (or plan to support) local variables? #7

Closed jason5122 closed 2 years ago

jason5122 commented 3 years ago

Hi, does Lezer support local variables like tree-sitter does? In tree-sitter, I can declare local scopes and have one variable appear with a consistent style across the scope. Here is an example below. Note that the underlined variables appear in either a method argument/for loop declaration and remain underlined throughout the scope.

Screen Shot 2020-12-09 at 6 14 19 PM

Thanks! I stumbled on your write-up on Lezer and since I already really love tree-sitter (moved to that recently; been stuck with tmLanguage/sublime-syntax for far too long), I really hope this project takes off :)

marijnh commented 3 years ago

No, it doesn't. Though from the tree-sitter docs, this seems to not really be a parser feature, but a highlighter one. Lezer node props could be used to annotate scope, variable definition, and variable reference nodes, and the highlighter could be extended to look at those (at the cost of doing some additional work).

I've been thinking about doing something like that for basic autocompletion and local jump-to-definition as well, though it seems that the result would still be rather crude (doesn't work for properties and across files) and probably not up to the expectations of people used to language-server-based completion.

marijnh commented 2 years ago

I looked into this and set up a working prototype, but decided that the performance impact was bigger than what I'm comfortable paying for the more detailed highlighting.

jason5122 commented 2 years ago

That's unfortunate, but it makes sense. Thanks for testing it out!