From 028e7f1ca25de3d139ced44d9a16a0b14af31aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20L=C3=B6scher?= Date: Fri, 9 Apr 2021 13:12:45 +0100 Subject: [PATCH] return references if no definitions are found --- apps/els_lsp/src/els_definition_provider.erl | 8 +++++++- apps/els_lsp/test/els_definition_SUITE.erl | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/els_lsp/src/els_definition_provider.erl b/apps/els_lsp/src/els_definition_provider.erl index ca6adcfa0..937cf3758 100644 --- a/apps/els_lsp/src/els_definition_provider.erl +++ b/apps/els_lsp/src/els_definition_provider.erl @@ -8,6 +8,7 @@ -include("els_lsp.hrl"). + -type state() :: any(). %%============================================================================== @@ -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, []) -> diff --git a/apps/els_lsp/test/els_definition_SUITE.erl b/apps/els_lsp/test/els_definition_SUITE.erl index 33e5fa04d..85fe6f921 100644 --- a/apps/els_lsp/test/els_definition_SUITE.erl +++ b/apps/els_lsp/test/els_definition_SUITE.erl @@ -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.