18
18
source /0
19
19
]).
20
20
21
+ -type missing_reason () :: module | function | export .
22
+
21
23
% %==============================================================================
22
24
% % Includes
23
25
% %==============================================================================
@@ -114,19 +116,23 @@ make_diagnostic({missing, Kind}, #{id := Id} = POI) ->
114
116
make_diagnostic (true , _ ) ->
115
117
[].
116
118
117
- -spec range (module | function , els_poi :poi ()) -> els_poi :poi_range ().
119
+ -spec range (missing_reason () , els_poi :poi ()) -> els_poi :poi_range ().
118
120
range (module , #{data := #{mod_range := Range }}) ->
119
121
Range ;
120
122
range (function , #{data := #{name_range := Range }}) ->
121
123
Range ;
124
+ range (export , #{data := #{name_range := Range }}) ->
125
+ Range ;
122
126
range (_ , #{range := Range }) ->
123
127
Range .
124
128
125
- -spec error_msg (module | function , els_poi :poi_id ()) -> binary ().
129
+ -spec error_msg (missing_reason () , els_poi :poi_id ()) -> binary ().
126
130
error_msg (module , {M , _F , _A }) ->
127
131
els_utils :to_binary (io_lib :format (" Cannot find module ~p " , [M ]));
128
132
error_msg (function , Id ) ->
129
- els_utils :to_binary (io_lib :format (" Cannot find definition for function ~s " , [id_str (Id )])).
133
+ els_utils :to_binary (io_lib :format (" Cannot find definition for function ~s " , [id_str (Id )]));
134
+ error_msg (export , Id ) ->
135
+ els_utils :to_binary (io_lib :format (" Function ~s is not exported." , [id_str (Id )])).
130
136
131
137
-spec id_str (els_poi :poi_id ()) -> string ().
132
138
id_str (Id ) ->
@@ -136,7 +142,7 @@ id_str(Id) ->
136
142
end .
137
143
138
144
-spec has_definition (els_poi :poi (), els_dt_document :item (), _ ) ->
139
- true | {missing , function | module }.
145
+ true | {missing , missing_reason () }.
140
146
has_definition (#{data := #{imported := true }}, _Document , _Opts ) ->
141
147
% % Call to a bif
142
148
true ;
@@ -177,7 +183,9 @@ has_definition(
177
183
case function_lookup (MFA ) of
178
184
true ->
179
185
true ;
180
- false ->
186
+ {missing , export } ->
187
+ true ;
188
+ {missing , function } ->
181
189
case els_code_navigation :goto_definition (Uri , POI ) of
182
190
{ok , _Defs } ->
183
191
true ;
@@ -189,12 +197,14 @@ has_definition(#{id := {M, _F, _A} = MFA} = POI, _Document, _Opts) ->
189
197
case function_lookup (MFA ) of
190
198
true ->
191
199
true ;
192
- false ->
200
+ {missing , export } ->
201
+ {missing , export };
202
+ {missing , function } ->
193
203
case els_utils :find_module (M ) of
194
204
{ok , Uri } ->
195
205
case els_code_navigation :goto_definition (Uri , POI ) of
196
206
{ok , _Defs } ->
197
- true ;
207
+ function_lookup ( MFA ) ;
198
208
{error , _Error } ->
199
209
{missing , function }
200
210
end ;
@@ -205,13 +215,15 @@ has_definition(#{id := {M, _F, _A} = MFA} = POI, _Document, _Opts) ->
205
215
has_definition (_POI , #{uri := _Uri }, _Opts ) ->
206
216
true .
207
217
208
- -spec function_lookup (mfa ()) -> boolean () .
218
+ -spec function_lookup (mfa ()) -> true | { missing , missing_reason ()} .
209
219
function_lookup (MFA ) ->
210
- case els_db :lookup (els_dt_functions : name (), MFA ) of
220
+ case els_dt_functions :lookup (MFA ) of
211
221
{ok , []} ->
212
- false ;
213
- {ok , _ } ->
214
- true
222
+ {missing , function };
223
+ {ok , [#{is_exported := true }]} ->
224
+ true ;
225
+ {ok , [#{is_exported := false }]} ->
226
+ {missing , export }
215
227
end .
216
228
217
229
-spec lager_definition (atom (), integer ()) -> boolean ().
0 commit comments