Skip to content

Commit

Permalink
[#22] Add poi for macros, fix end locations
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoaloi committed Jul 22, 2019
1 parent 684bf39 commit 994125b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/erlang_ls_parser.erl
Expand Up @@ -66,19 +66,23 @@ postorder_update(F, Tree) ->
-spec get_range(syntax_tree(), pos(), {atom(), any()}) -> range().
get_range(_Tree, {Line, Column}, {behaviour, Behaviour}) ->
From = {Line, Column - 1},
To = {Line, length("behaviour") + length(atom_to_list(Behaviour)) + 1},
To = {Line, Column + length("behaviour") + length(atom_to_list(Behaviour))},
#{ from => From, to => To };
get_range(_Tree, {_Line, _Column}, {exports_entry, {_F, _A}}) ->
%% TODO: The location information for the arity qualifiers are lost during
%% parsing in `epp_dodger`. This requires fixing.
#{ from => {0, 0}, to => {0, 0} };
get_range(_Tree, {Line, Column}, {include, Include}) ->
From = {Line, Column - 1},
To = {Line, length("include") + length(Include) + 1},
To = {Line, Column + length("include") + length(Include)},
#{ from => From, to => To };
get_range(_Tree, {Line, Column}, {include_lib, Include}) ->
From = {Line, Column - 1},
To = {Line, length("include_lib") + length(Include) + 1},
To = {Line, Column + length("include_lib") + length(Include)},
#{ from => From, to => To };
get_range(_Tree, {Line, Column}, {macro, Macro}) ->
From = {Line, Column},
To = {Line, Column + length(atom_to_list(Macro))},
#{ from => From, to => To }.

-spec find_by_pos(syntax_tree(), pos()) -> [poi()].
Expand Down Expand Up @@ -122,18 +126,21 @@ analyze(Tree, attribute) ->
{export, Exports} ->
[poi(Tree, {exports_entry, {F, A}}) || {F, A} <- Exports];
preprocessor ->
Name = erl_syntax:atom_name(erl_syntax:attribute_name(Tree)),
Name = erl_syntax:atom_value(erl_syntax:attribute_name(Tree)),
case {Name, erl_syntax:attribute_arguments(Tree)} of
{"include", [String]} ->
{include, [String]} ->
[poi(Tree, {include, erl_syntax:string_literal(String)})];
{"include_lib", [String]} ->
{include_lib, [String]} ->
[poi(Tree, {include_lib, erl_syntax:string_literal(String)})];
_ ->
[]
end;
_ ->
[]
end;
analyze(Tree, macro) ->
Macro = erl_syntax:variable_name(erl_syntax:macro_name(Tree)),
[poi(Tree, {macro, Macro})];
analyze(_Tree, _) ->
[].

Expand Down

0 comments on commit 994125b

Please sign in to comment.