lezer-parser/lezer

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

jason5122 opened this issue · 3 comments

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 :)

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.

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.

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