Skip to content

Commit

Permalink
Find references for atoms (#1404)
Browse files Browse the repository at this point in the history
This change indexes atoms in the references table and 
adds support for finding atoms in the references provider.
  • Loading branch information
the-mikedavis authored Dec 21, 2023
1 parent a4047b7 commit 09d6e2d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
7 changes: 5 additions & 2 deletions apps/els_lsp/src/els_dt_references.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
| record
| include
| include_lib
| behaviour.
| behaviour
| atom.
-export_type([poi_category/0]).

%%==============================================================================
Expand Down Expand Up @@ -185,4 +186,6 @@ kind_to_category(Kind) when Kind =:= include ->
kind_to_category(Kind) when Kind =:= include_lib ->
include_lib;
kind_to_category(Kind) when Kind =:= behaviour ->
behaviour.
behaviour;
kind_to_category(Kind) when Kind =:= atom ->
atom.
4 changes: 3 additions & 1 deletion apps/els_lsp/src/els_indexing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ index_references(Id, Uri, POIs, Version) ->
%% Behaviour
behaviour,
%% Type
type_application
type_application,
%% Atom
atom
],
[
index_reference(Id, Uri, POI, Version)
Expand Down
3 changes: 2 additions & 1 deletion apps/els_lsp/src/els_references_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ find_references(Uri, #{kind := module}) ->
Refs = find_references_to_module(Uri),
[location(U, R) || #{uri := U, range := R} <- Refs];
find_references(_Uri, #{kind := Kind, id := Name}) when
Kind =:= behaviour
Kind =:= behaviour;
Kind =:= atom
->
find_references_for_id(Kind, Name);
find_references(_Uri, _POI) ->
Expand Down
2 changes: 2 additions & 0 deletions apps/els_lsp/src/els_text_search.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extract_pattern({include, Id}) ->
extract_pattern({include_lib, Id}) ->
include_id(Id);
extract_pattern({behaviour, Name}) ->
Name;
extract_pattern({atom, Name}) ->
Name.

-spec include_id(string()) -> string().
Expand Down
27 changes: 27 additions & 0 deletions apps/els_lsp/test/els_references_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
type_local/1,
type_remote/1,
type_included/1,
atom/1,
refresh_after_watched_file_deleted/1,
refresh_after_watched_file_changed/1,
refresh_after_watched_file_added/1,
Expand Down Expand Up @@ -555,6 +556,32 @@ type_included(Config) ->
assert_locations(Locations, ExpectedLocations),
ok.

-spec atom(config()) -> ok.
atom(Config) ->
Uri = ?config(code_navigation_uri, Config),
%% References for the `code_navigation_extra' atom
#{result := Locations} = els_client:references(Uri, 85, 5),
ExpectedLocations = [
#{
uri => Uri,
range => #{from => {85, 3}, to => {85, 24}}
},
#{
uri => Uri,
range => #{from => {86, 14}, to => {86, 35}}
},
#{
uri => Uri,
range => #{from => {132, 36}, to => {132, 57}}
},
#{
uri => Uri,
range => #{from => {134, 35}, to => {134, 56}}
}
],
assert_locations(Locations, ExpectedLocations),
ok.

-spec refresh_after_watched_file_deleted(config()) -> ok.
refresh_after_watched_file_deleted(Config) ->
%% Before
Expand Down

0 comments on commit 09d6e2d

Please sign in to comment.