Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/els_core/src/els_text.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ line_starts(Text) ->
-spec pos([{integer(), any()}], {line_num(), column_num()}) ->
pos_integer().
pos(LineStarts, {LineNum, ColumnNum}) ->
{LinePos, _} = lists:nth(LineNum, LineStarts),
{LinePos, _} = lists:nth(min(length(LineStarts), LineNum), LineStarts),
LinePos + ColumnNum.
38 changes: 21 additions & 17 deletions apps/els_lsp/src/els_crossref_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,23 @@ make_diagnostic({missing, Kind}, #{id := Id} = POI) ->
make_diagnostic(true, _) ->
[].

-spec range(module | function, els_poi:poi()) -> els_poi:poi_range().
-spec range(module | function | no_export, els_poi:poi()) -> els_poi:poi_range().
range(module, #{data := #{mod_range := Range}}) ->
Range;
range(function, #{data := #{name_range := Range}}) ->
Range;
range(no_export, #{data := #{name_range := Range}}) ->
Range;
range(_, #{range := Range}) ->
Range.

-spec error_msg(module | function, els_poi:poi_id()) -> binary().
-spec error_msg(module | function | no_export, els_poi:poi_id()) -> binary().
error_msg(module, {M, _F, _A}) ->
els_utils:to_binary(io_lib:format("Cannot find module ~p", [M]));
error_msg(function, Id) ->
els_utils:to_binary(io_lib:format("Cannot find definition for function ~s", [id_str(Id)])).
els_utils:to_binary(io_lib:format("Cannot find definition for function ~s", [id_str(Id)]));
error_msg(no_export, Id) ->
els_utils:to_binary(io_lib:format("Cannot find export for function ~s", [id_str(Id)])).

-spec id_str(els_poi:poi_id()) -> string().
id_str(Id) ->
Expand All @@ -136,7 +140,7 @@ id_str(Id) ->
end.

-spec has_definition(els_poi:poi(), els_dt_document:item(), _) ->
true | {missing, function | module}.
true | {missing, module | function | no_export}.
has_definition(#{data := #{imported := true}}, _Document, _Opts) ->
%% Call to a bif
true;
Expand Down Expand Up @@ -186,21 +190,21 @@ has_definition(
end
end;
has_definition(#{id := {M, _F, _A} = MFA} = POI, _Document, _Opts) ->
case function_lookup(MFA) of
true ->
true;
false ->
case els_utils:find_module(M) of
{ok, Uri} ->
case els_code_navigation:goto_definition(Uri, POI) of
{ok, _Defs} ->
case els_utils:find_module(M) of
{ok, Uri} ->
case els_code_navigation:goto_definition(Uri, POI) of
{ok, _Defs} ->
case function_lookup(MFA) of
true ->
true;
{error, _Error} ->
{missing, function}
false ->
{missing, no_export}
end;
{error, _} ->
{missing, module}
end
{error, _Error} ->
{missing, function}
end;
{error, _} ->
{missing, module}
end;
has_definition(_POI, #{uri := _Uri}, _Opts) ->
true.
Expand Down
17 changes: 16 additions & 1 deletion apps/els_lsp/src/els_indexing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,25 @@ index_signature(M, Text, #{id := {F, A}, range := Range, data := #{args := Args}
args => Args
}).

-spec is_export_all([els_poi:poi()]) -> boolean().
is_export_all([]) ->
false;
is_export_all([#{kind := compile}, #{id := export_all} | _]) ->
true;
is_export_all([_ | T]) ->
is_export_all(T).

-spec index_functions(atom(), uri(), [els_poi:poi()], version()) -> ok.
index_functions(M, Uri, POIs, Version) ->
ok = els_dt_functions:versioned_delete_by_uri(Uri, Version),
[index_function(M, POI, Version) || #{kind := function} = POI <- POIs],
Fkind =
case is_export_all(POIs) of
true ->
function;
false ->
export_entry
end,
[index_function(M, POI, Version) || #{kind := Kind} = POI <- POIs, Kind =:= Fkind],
ok.

-spec index_function(atom(), els_poi:poi(), version()) -> ok.
Expand Down