Skip to content

Commit

Permalink
Try to goto definition for each POI at pos until there's a match
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed Apr 6, 2021
1 parent 6376403 commit d6c5774
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions apps/els_lsp/src/els_definition_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
, is_enabled/0
]).

-include("els_lsp.hrl").

-type state() :: any().

%%==============================================================================
Expand All @@ -24,18 +26,16 @@ handle_request({definition, Params}, State) ->
, <<"textDocument">> := #{<<"uri">> := Uri}
} = Params,
{ok, Document} = els_utils:lookup_document(Uri),
case
els_dt_document:get_element_at_pos(Document, Line + 1, Character + 1)
of
[POI | _] ->
case els_code_navigation:goto_definition(Uri, POI) of
{ok, DefUri, #{range := Range}} ->
{ #{ uri => DefUri, range => els_protocol:range(Range) }
, State
};
_ ->
{null, State}
end;
[] ->
{null, State}
POIs = els_dt_document:get_element_at_pos(Document, Line + 1, Character + 1),
{goto_definition(Uri, POIs), State}.

-spec goto_definition(uri(), [poi()]) -> map() | null.
goto_definition(_Uri, []) ->
null;
goto_definition(Uri, [POI|Rest]) ->
case els_code_navigation:goto_definition(Uri, POI) of
{ok, DefUri, #{range := Range}} ->
#{uri => DefUri, range => els_protocol:range(Range)};
_ ->
goto_definition(Uri, Rest)
end.

0 comments on commit d6c5774

Please sign in to comment.