Skip to content

Commit

Permalink
Merge pull request #979 from gomoripeti/erlfmt_phase2
Browse files Browse the repository at this point in the history
Use erlfmt for parsing
  • Loading branch information
robertoaloi authored May 3, 2021
2 parents 016167e + 8887a0d commit fb4aada
Show file tree
Hide file tree
Showing 15 changed files with 1,299 additions and 413 deletions.
5 changes: 5 additions & 0 deletions apps/els_lsp/priv/code_navigation/src/hover_macro.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
f() ->
?LOCAL_MACRO,
?INCLUDED_MACRO_A.

-define(WEIRD_MACRO, A when A > 1).

g() ->
case foo of ?WEIRD_MACRO -> ok end.
9 changes: 1 addition & 8 deletions apps/els_lsp/src/els_bound_var_in_pattern_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ source() ->
-spec find_vars(uri()) -> [poi()].
find_vars(Uri) ->
{ok, #{text := Text}} = els_utils:lookup_document(Uri),
{ok, Forms} = parse_file(Text),
{ok, Forms} = els_parser:parse_text(Text),
lists:flatmap(fun find_vars_in_form/1, Forms).

-spec find_vars_in_form(erl_syntax:forms()) -> [poi()].
Expand Down Expand Up @@ -126,13 +126,6 @@ find_vars_in_pattern(Tree, Acc) ->
Acc
end.

-spec parse_file(binary()) -> {ok, erl_syntax:forms()}.
parse_file(Text) ->
IoDevice = els_io_string:new(Text),
{ok, Forms} = els_dodger:parse(IoDevice, {1, 1}),
ok = file:close(IoDevice),
{ok, Forms}.

-spec variable(tree()) -> poi().
variable(Tree) ->
Id = erl_syntax:variable_name(Tree),
Expand Down
9 changes: 7 additions & 2 deletions apps/els_lsp/src/els_docs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ docs(Uri, #{kind := Kind, id := {F, A}})
function_docs('local', M, F, A);
docs(Uri, #{kind := macro, id := Name} = POI) ->
case els_code_navigation:goto_definition(Uri, POI) of
{ok, _DefUri, #{data := [Value|_]}} ->
{ok, DefUri, #{data := #{value_range := ValueRange}}} ->
NameStr = atom_to_list(Name),
Line = lists:flatten(["?", NameStr, " = ", erl_prettypr:format(Value)]),

{ok, #{text := Text}} = els_utils:lookup_document(DefUri),
#{from := From, to := To} = ValueRange,
ValueText = els_utils:to_list(els_text:range(Text, From, To)),

Line = lists:flatten(["?", NameStr, " = ", ValueText]),
[{code_line, Line}];
_ ->
[]
Expand Down
786 changes: 786 additions & 0 deletions apps/els_lsp/src/els_erlfmt_ast.erl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/els_lsp/src/els_lsp.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ephemeral,
uuid,
getopt,
erlfmt,
els_core
]},
{env, []},
Expand Down
Loading

0 comments on commit fb4aada

Please sign in to comment.