Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect appdirs when prioritizing module candidates #1418

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
32 changes: 22 additions & 10 deletions apps/els_core/src/els_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,30 @@ cmd_receive(Port) ->
-spec prioritize_uris([uri()]) -> [uri()].
prioritize_uris(Uris) ->
Root = els_config:get(root_uri),
Order = fun
(nomatch) ->
3;
(Cont) ->
case string:find(Cont, "/src/") of
nomatch -> 1;
_ -> 0
end
end,
Prio = [{Order(string:prefix(Uri, Root)), Uri} || Uri <- Uris],
AppsPaths = els_config:get(apps_paths),
Prio = [{score_uri(Uri, Root, AppsPaths), Uri} || Uri <- Uris],
[Uri || {_, Uri} <- lists:sort(Prio)].

-spec score_uri(uri(), uri(), [file:name()]) -> tuple().
score_uri(Uri, RootUri, AppsPaths) ->
Path = els_uri:path(Uri),
Prefix = string:prefix(Uri, RootUri),
%% prefer files under project root
S1 =
case Prefix of
nomatch -> 1;
_Rest -> 0
end,
%% among those, prefer files under some project app directory (e.g.
%% deprioritize dependencies and shadow copies)
S2 = length([
AP
|| S1 == 0,
AP <- AppsPaths,
string:prefix(Path, AP) /= nomatch
]),
{S1, -S2}.

%%==============================================================================
%% This section excerpted from the rebar3 sources, rebar_dir.erl
%% Pending resolution of https://github.com/erlang/rebar3/issues/2223
Expand Down