Closed ghivert closed 2 months ago
If I recall correctly, this is an ambiguity that can only be resolved with a more powerful parser. The reason being that foo.bar
could be accessing the field bar
on record foo
or it could be referencing function bar
on module foo
. The only way to disambiguate is to track what the local variables are, and if foo
is one, then we can reasonably assume that foo.bar
is property access, and otherwise assume that foo.bar
is a remote function invocation.
In fact, we do do this (disambiguation example), but it's reliant on tree-sitter's tagging mechanism which isn't widely supported (e.g. likely not by Zed, but you can look into it).
OK, got it. But I was wondering, isn't the fact that it has parentheses indicating a function call enough to classify it as a function?
Record fields can also be functions. There's no way to tell if something is a record or a module without performing type analysis.
Yup, I understand this, my question was more about the fact that in the expression dict.insert()
(explicitly with the parens) insert
could be considered as a function and not a property, no? Visually, it would make sense for the syntax highlighting to display it in the same colour as functions. 🙂 I totally get that in an expression like key |> dict.get
, get
can't really be highlighted as function though.
Anyway, it's more about curiosity than anything else, the code is already readable ha ha, thanks for taking time to answer
The property/function distinction doesn't make much sense as properties can be functions. They're not mutually exclusive groups as one is a type and one is a structural matter.
Hmm, I see what you mean. Thanks a lot for the explanation. Let’s wait for semantic highlighting then 😁
Hi ! I'm trying tree-sitter parser with Zed, and I'm wondering why some functions are not matched as functions.
And because a picture is worth thousand words, here's an illustration.
Here,
compute_index
is correctly seen as a function, butcache.cache_search_results
anddict.insert
are seen as properties, while semantically, they are functions.Is there any way to change the parser to match those cases as functions?