Use erlfmt for parsing#979
Conversation
6b39b65 to
86f3833
Compare
|
In commit 608fa18 I needed to apply a workaround for hover macro definitions because the magic tuples from erlfmt_ast started to surface https://github.com/erlang-ls/erlang_ls/pull/979/files#diff-cc9d509044808779837f7175898eeab88501b2666fcf925adfc43abc1104d1d5R483-R484 |
| @@ -0,0 +1,1290 @@ | |||
| %% Copyright (c) Facebook, Inc. and its affiliates. | |||
There was a problem hiding this comment.
Why forking it, instead of adding it as a dependency?
There was a problem hiding this comment.
Ah, saw the branch now. What's the plan long term for this?
There was a problem hiding this comment.
I hope that branch will eventually be merged and erlfmt_ast be a part of erlfmt and we can remove this temporary copy from erlang_ls
|
@gomoripeti I don't have a strong opinion on this. What we can do is to try out the new parser by merging this PR. We can then see how the "early adopters" (who point to |
Should conflict with anything
…unction (upstream) Formerly standalone ones (in macro definitions) were converted to magic tuples.
In order to silence compiler warning warn_missing_spec_all
|
Hi Roberto, sorry, I had little time to move this forward. I did the squash (kept erlfmt_ast changes separate so its easier to adapt erlfmt upstream changes) |
b79ada8 to
0daf0fd
Compare
- handle argumentless macro as type/opaque name - fix spec/callback location - support record_types in type context - support bitstring_type in type context - convert record field types in a type context - convert spec fun name - silence dialyzer about erl_syntax:function_type
Since OTP 24 (commit erlang/otp@f30514e#diff-9f3b412e8fbd809c6473fcd5bee30f63931c7349010640d76316cfcde504e733) `erl_syntax:set_pos` started to require a proper `erl_anno:anno()` instead of any term. `erlfmt_ast` used to just copy the `erlfmt_scan:anno()` map from the input to `syntaxTree()`, but that does not work any more. Now it is converted to an `erl_anno:anno()` to make dialyzer happy. (There is a bit of cheating with `end_location` in the hope that it will be a valid key in `erl_anno` soon.)
Use erlfmt instead of els_dodger for parsing. Uses modified version of erlfmt_ast from PR WhatsApp/erlfmt#237 to convert from erlfmt parse tree to erl_syntax:syntaxTree. Expected benefits are more precise locations and parsing exotic macros.
Only store the range of the value in `define` POIs and take the text from the
original document. Formerly els_dodger used to create a text tree for definition
values it couldn't parse. However erlfmt can parse more cases and erlfmt_ast
currently converts some of them to "magic tuples". This change is a workaround
to avoid showing magic tuples.
An example
```
-define(M, A when A > 1).
```
would show
```
?M = {'*when*', A, A > 1}
```
Results from multiple diagnostics can arrive in arbitrary order.
31f5fcd to
8887a0d
Compare
|
Tested indexing all of OTP. All files are processed without any crash. The new implementation is somewhat slower, indexing on select OTP applications (in seconds) erlfmt I would say this is ready to be merged from my side. |
|
Thanks for the analysis @gomoripeti ! Interesting results. Do you think we should proceed anyway? Performance degradation is minimal, but still... |
|
I will give it a bit more thinking/analyses. I will gather some concrete benefit examples, to be able to judge if its worth it. Few things that pop in my mind right now:
|
|
I tried to do a bit more profiling. While not full, I think
I tried to look at the diff in POIs
the OTP test suites are good with edge cases that the old parser couldn't parse, but I think are rare in real, common code
All in all, I think it's worth to include this change as it eliminates the need for some heuristics and assumptions |
|
Sounds great. I guess we can follow up with @michalmuskala @alanz and the rest of the crew to see if we can get rid of the fork for |
Description
Use erlfmt instead of els_dodger for parsing. Uses modified version of erlfmt_ast from PR WhatsApp/erlfmt#237 to convert from erlfmt parse tree to erl_syntax:syntaxTree. Expected benefits:
TODO