Skip to content

Commit

Permalink
Merge pull request #978 from TheGeorge/references_on_goto_definition
Browse files Browse the repository at this point in the history
return references if no definitions are found
  • Loading branch information
robertoaloi authored Apr 23, 2021
2 parents c3ba39d + 028e7f1 commit 016167e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion apps/els_lsp/src/els_definition_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

-include("els_lsp.hrl").


-type state() :: any().

%%==============================================================================
Expand All @@ -27,7 +28,12 @@ handle_request({definition, Params}, State) ->
} = Params,
{ok, Document} = els_utils:lookup_document(Uri),
POIs = els_dt_document:get_element_at_pos(Document, Line + 1, Character + 1),
{goto_definition(Uri, POIs), State}.
case goto_definition(Uri, POIs) of
null ->
els_references_provider:handle_request({references, Params}, State);
GoTo ->
{GoTo, State}
end.

-spec goto_definition(uri(), [poi()]) -> map() | null.
goto_definition(_Uri, []) ->
Expand Down
7 changes: 6 additions & 1 deletion apps/els_lsp/test/els_definition_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,12 @@ type_application_undefined(Config) ->
Uri = ?config(code_navigation_uri, Config),
Def = els_client:definition(Uri, 55, 42),
#{result := Result} = Def,
?assertEqual(null, Result),
Expected = [
#{ range => #{'end' => #{character => 49, line => 54},
start => #{character => 33, line => 54}}
, uri => Uri}
],
?assertEqual(Expected, Result),
ok.

-spec type_application_user(config()) -> ok.
Expand Down

0 comments on commit 016167e

Please sign in to comment.