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

Use els_utils:lookup_document for lookup #930

Merged
merged 3 commits into from
Mar 4, 2021
Merged
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
9 changes: 7 additions & 2 deletions apps/els_core/src/els_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ lookup_document(Uri) ->
{ok, []} ->
Path = els_uri:path(Uri),
{ok, Uri} = els_indexing:index_file(Path),
{ok, [Document]} = els_dt_document:lookup(Uri),
{ok, Document}
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
{ok, Document};
Error ->
?LOG_INFO("Document lookup failed [error=~p] [uri=~p]", [Error, Uri]),
{error, Error}
end
end.

-spec macro_string_to_term(list()) -> any().
Expand Down
6 changes: 3 additions & 3 deletions apps/els_lsp/src/els_code_navigation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ find([Uri|Uris0], Kind, Data, AlreadyVisited) ->
find(Uris0, Kind, Data, AlreadyVisited);
false ->
AlreadyVisited2 = sets:add_element(Uri, AlreadyVisited),
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
case els_utils:lookup_document(Uri) of
{ok, Document} ->
find_in_document([Uri|Uris0], Document, Kind, Data, AlreadyVisited2);
{ok, []} ->
{error, _Error} ->
find(Uris0, Kind, Data, AlreadyVisited2)
end
end;
Expand Down
7 changes: 3 additions & 4 deletions apps/els_lsp/src/els_compiler_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ parse_escript(Uri) ->
[els_diagnostics:diagnostic()].
diagnostics(Path, List, Severity) ->
Uri = els_uri:uri(els_utils:to_binary(Path)),
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
case els_utils:lookup_document(Uri) of
{ok, Document} ->
lists:flatten([[ diagnostic( Path
, MessagePath
, range(Anno)
Expand All @@ -153,8 +153,7 @@ diagnostics(Path, List, Severity) ->
, Severity)
|| {Anno, Module, Desc} <- Info]
|| {MessagePath, Info} <- List]);
Error ->
?LOG_INFO("diagnostics doc lookup failed [Error=~p]", [Error]),
{error, _Error} ->
[]
end.

Expand Down
6 changes: 3 additions & 3 deletions apps/els_lsp/src/els_crossref_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ is_default() ->

-spec run(uri()) -> [els_diagnostics:diagnostic()].
run(Uri) ->
case els_dt_document:lookup(Uri) of
{ok, []} ->
case els_utils:lookup_document(Uri) of
{error, _Error} ->
[];
{ok, [Document|_]} ->
{ok, Document} ->
POIs = els_dt_document:pois(Document, [ application
, implicit_fun
, import_entry
Expand Down
14 changes: 6 additions & 8 deletions apps/els_lsp/src/els_diagnostics_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ included_uris(Document) ->
dependencies([], Acc, _AlreadyProcessed) ->
Acc;
dependencies([Uri|Uris], Acc, AlreadyProcessed) ->
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
case els_utils:lookup_document(Uri) of
{ok, Document} ->
Behaviours = els_dt_document:pois(Document, [behaviour]),
ParseTransforms = els_dt_document:pois(Document, [parse_transform]),
IncludedUris = included_uris(Document),
Expand All @@ -49,8 +49,7 @@ dependencies([Uri|Uris], Acc, AlreadyProcessed) ->
, Acc ++ [Id || #{id := Id} <- Behaviours ++ ParseTransforms]
++ [els_uri:module(FPTUri) || FPTUri <- FilteredPTUris]
, sets:add_element(Uri, AlreadyProcessed));
Error ->
?LOG_INFO("Lookup failed [Error=~p]", [Error]),
{error, _Error} ->
[]
end.

Expand All @@ -62,14 +61,13 @@ exclude_already_processed(Uris, AlreadyProcessed) ->
pt_deps(Module) ->
case els_utils:find_module(Module) of
{ok, Uri} ->
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
case els_utils:lookup_document(Uri) of
{ok, Document} ->
Applications = els_dt_document:pois(Document, [ application
, implicit_fun
]),
applications_to_uris(Applications);
Error ->
?LOG_INFO("Lookup failed [Error=~p]", [Error]),
{error, _Error} ->
[]
end;
{error, Error} ->
Expand Down
2 changes: 1 addition & 1 deletion apps/els_lsp/src/els_folding_range_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ is_enabled() ->
-spec handle_request(tuple(), state()) -> {folding_range_result(), state()}.
handle_request({document_foldingrange, Params}, State) ->
#{ <<"textDocument">> := #{<<"uri">> := Uri} } = Params,
{ok, [Document]} = els_dt_document:lookup(Uri),
{ok, Document} = els_utils:lookup_document(Uri),
POIs = els_dt_document:pois(Document, [folding_range]),
Response = case [folding_range(Range) || #{range := Range} <- POIs] of
[] -> null;
Expand Down
12 changes: 6 additions & 6 deletions apps/els_lsp/src/els_unused_includes_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ is_default() ->

-spec run(uri()) -> [els_diagnostics:diagnostic()].
run(Uri) ->
case els_dt_document:lookup(Uri) of
{ok, []} ->
case els_utils:lookup_document(Uri) of
{error, _Error} ->
[];
{ok, [Document|_]} ->
{ok, Document} ->
Includes = els_dt_document:pois(Document, [include, include_lib]),
UnusedIncludes = find_unused_includes(Document, Includes),
[ els_diagnostics:make_diagnostic(
Expand Down Expand Up @@ -87,8 +87,8 @@ expand_includes(Uri) ->
expand_includes([], Graph, _Visited) ->
Graph;
expand_includes([Uri|Uris], Graph, Visited) ->
case els_dt_document:lookup(Uri) of
{ok, [Document]} ->
case els_utils:lookup_document(Uri) of
{ok, Document} ->
IncludedUris = els_diagnostics_utils:included_uris(Document),
NonVisitedIncludedUris = [U || U <- IncludedUris
, not sets:is_element(U, Visited)],
Expand All @@ -103,7 +103,7 @@ expand_includes([Uri|Uris], Graph, Visited) ->
expand_includes( Uris ++ NonVisitedIncludedUris
, NewGraph
, sets:add_element(Uri, Visited));
{ok, []} ->
{error, _Error} ->
?LOG_WARNING("Failed lookup while expanding includes [uri=~p]", [Uri]),
[]
end.
Expand Down
6 changes: 3 additions & 3 deletions apps/els_lsp/src/els_unused_macros_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ is_default() ->
run(Uri) ->
case filename:extension(Uri) of
<<".erl">> ->
case els_dt_document:lookup(Uri) of
{ok, []} ->
case els_utils:lookup_document(Uri) of
{error, _Error} ->
[];
{ok, [Document|_]} ->
{ok, Document} ->
UnusedMacros = find_unused_macros(Document),
[make_diagnostic(POI) || POI <- UnusedMacros ]
end;
Expand Down