Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 51a48ef

Browse files
authored
Merge pull request #1112 from gomoripeti/hover_implicit_fun
Hover docs for fun expressions referring to local or remote functions
2 parents f831fe0 + 61c5225 commit 51a48ef

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

apps/els_lsp/priv/code_navigation/src/hover_docs_caller.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
-export([ local_call_no_args/0
44
, local_call_with_args/0
55
, remote_call_multiple_clauses/0
6+
, implicit_funs/0
67
]).
78

89
local_call_no_args() ->
@@ -14,6 +15,10 @@ local_call_with_args() ->
1415
remote_call_multiple_clauses() ->
1516
hover_docs:multiple_clauses(dummy_arg).
1617

18+
implicit_funs() ->
19+
{fun local_call/2,
20+
fun hover_docs:multiple_clauses/1}.
21+
1722
local_call() ->
1823
ok.
1924

apps/els_lsp/src/els_docs.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@
4141
%% API
4242
%%==============================================================================
4343
-spec docs(uri(), poi()) -> [els_markup_content:doc_entry()].
44-
docs(_Uri, #{kind := application, id := {M, F, A}}) ->
44+
docs(_Uri, #{kind := Kind, id := {M, F, A}})
45+
when Kind =:= application;
46+
Kind =:= implicit_fun ->
4547
function_docs('remote', M, F, A);
4648
docs(Uri, #{kind := Kind, id := {F, A}})
4749
when Kind =:= application;
50+
Kind =:= implicit_fun;
4851
Kind =:= export_entry ->
4952
M = els_uri:module(Uri),
5053
function_docs('local', M, F, A);

apps/els_lsp/test/els_hover_SUITE.erl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
-export([ local_call_no_args/1
1616
, local_call_with_args/1
1717
, remote_call_multiple_clauses/1
18+
, local_fun_expression/1
19+
, remote_fun_expression/1
1820
, no_poi/1
1921
, included_macro/1
2022
, local_macro/1
@@ -68,7 +70,7 @@ end_per_testcase(TestCase, Config) ->
6870
%%==============================================================================
6971
local_call_no_args(Config) ->
7072
Uri = ?config(hover_docs_caller_uri, Config),
71-
#{result := Result} = els_client:hover(Uri, 9, 7),
73+
#{result := Result} = els_client:hover(Uri, 10, 7),
7274
?assert(maps:is_key(contents, Result)),
7375
Contents = maps:get(contents, Result),
7476
Value = <<"## local_call/0">>,
@@ -80,7 +82,7 @@ local_call_no_args(Config) ->
8082

8183
local_call_with_args(Config) ->
8284
Uri = ?config(hover_docs_caller_uri, Config),
83-
#{result := Result} = els_client:hover(Uri, 12, 7),
85+
#{result := Result} = els_client:hover(Uri, 13, 7),
8486
?assert(maps:is_key(contents, Result)),
8587
Contents = maps:get(contents, Result),
8688
Value = <<"## local_call/2\n\n"
@@ -99,7 +101,42 @@ local_call_with_args(Config) ->
99101

100102
remote_call_multiple_clauses(Config) ->
101103
Uri = ?config(hover_docs_caller_uri, Config),
102-
#{result := Result} = els_client:hover(Uri, 15, 15),
104+
#{result := Result} = els_client:hover(Uri, 16, 15),
105+
?assert(maps:is_key(contents, Result)),
106+
Contents = maps:get(contents, Result),
107+
Value = <<"## hover_docs:multiple_clauses/1\n\n"
108+
"```erlang\n\n"
109+
" multiple_clauses(L) when is_list(L)\n\n"
110+
" multiple_clauses(#{data := Data}) \n\n"
111+
" multiple_clauses(X) \n\n```">>,
112+
Expected = #{ kind => <<"markdown">>
113+
, value => Value
114+
},
115+
?assertEqual(Expected, Contents),
116+
ok.
117+
118+
local_fun_expression(Config) ->
119+
Uri = ?config(hover_docs_caller_uri, Config),
120+
#{result := Result} = els_client:hover(Uri, 19, 5),
121+
?assert(maps:is_key(contents, Result)),
122+
Contents = maps:get(contents, Result),
123+
Value = <<"## local_call/2\n\n"
124+
"```erlang\n\n"
125+
" local_call(Arg1, Arg2) \n\n"
126+
"```\n\n"
127+
"```erlang\n"
128+
"-spec local_call(integer(), any()) -> tuple();\n"
129+
" (float(), any()) -> tuple().\n"
130+
"```">>,
131+
Expected = #{ kind => <<"markdown">>
132+
, value => Value
133+
},
134+
?assertEqual(Expected, Contents),
135+
ok.
136+
137+
remote_fun_expression(Config) ->
138+
Uri = ?config(hover_docs_caller_uri, Config),
139+
#{result := Result} = els_client:hover(Uri, 20, 10),
103140
?assert(maps:is_key(contents, Result)),
104141
Contents = maps:get(contents, Result),
105142
Value = <<"## hover_docs:multiple_clauses/1\n\n"

apps/els_lsp/test/els_references_SUITE.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ function_multiple_clauses(Config) ->
125125
UriCaller = ?config(hover_docs_caller_uri, Config),
126126
#{result := Locations} = els_client:references(Uri, 7, 1),
127127
ExpectedLocations = [ #{ uri => UriCaller
128-
, range => #{from => {15, 3}, to => {15, 30}}
128+
, range => #{from => {16, 3}, to => {16, 30}}
129+
}
130+
, #{ uri => UriCaller
131+
, range => #{from => {20, 4}, to => {20, 37}}
129132
}
130133
],
131134
assert_locations(Locations, ExpectedLocations),

0 commit comments

Comments
 (0)