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

Avoid running get_words twice when opening new file #1513

Merged
merged 1 commit into from
May 4, 2024
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
4 changes: 2 additions & 2 deletions apps/els_lsp/src/els_dt_document.erl
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ find_candidates(Pattern, Kind) ->
get_words(Text) ->
case erl_scan:string(els_utils:to_list(Text)) of
{ok, Tokens, _EndLocation} ->
tokens_to_words(Tokens, sets:new());
tokens_to_words(Tokens, sets:new([{version, 2}]));
{error, ErrorInfo, ErrorLocation} ->
?LOG_WARNING("Errors while get_words [info=~p] [location=~p]", [
ErrorInfo, ErrorLocation
]),
sets:new()
sets:new([{version, 2}])
end.

-spec tokens_to_words([erl_scan:token()], sets:set()) -> sets:set().
Expand Down
18 changes: 12 additions & 6 deletions apps/els_lsp/src/els_indexing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ensure_deeply_indexed/1,
shallow_index/2,
shallow_index/3,
deep_index/1,
deep_index/2,
remove/1
]).

Expand Down Expand Up @@ -76,13 +76,13 @@ ensure_deeply_indexed(Uri) ->
{ok, #{pois := POIs} = Document} = els_utils:lookup_document(Uri),
case POIs of
ondemand ->
deep_index(Document);
deep_index(Document, _UpdateWords = true);
_ ->
Document
end.

-spec deep_index(els_dt_document:item()) -> els_dt_document:item().
deep_index(Document0) ->
-spec deep_index(els_dt_document:item(), boolean()) -> els_dt_document:item().
deep_index(Document0, UpdateWords) ->
#{
id := Id,
uri := Uri,
Expand All @@ -91,8 +91,14 @@ deep_index(Document0) ->
version := Version
} = Document0,
{ok, POIs} = els_parser:parse(Text),
Words = els_dt_document:get_words(Text),
Document = Document0#{pois => POIs, words => Words},
Document =
case UpdateWords of
true ->
Words = els_dt_document:get_words(Text),
Document0#{pois => POIs, words => Words};
false ->
Document0#{pois => POIs}
end,
case els_dt_document:versioned_insert(Document) of
ok ->
index_signatures(Id, Uri, Text, POIs, Version),
Expand Down
4 changes: 2 additions & 2 deletions apps/els_lsp/src/els_text_synchronization.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ did_open(Params) ->
} = Params,
Document = els_dt_document:new(Uri, Text, _Source = app, Version),
els_dt_document:insert(Document),
els_indexing:deep_index(Document),
els_indexing:deep_index(Document, _UpdateWords = false),
ok.

-spec did_save(map()) -> ok.
Expand Down Expand Up @@ -129,7 +129,7 @@ reload_from_disk(Uri) ->
background_index(#{uri := Uri} = Document) ->
Config = #{
task => fun(Doc, _State) ->
els_indexing:deep_index(Doc),
els_indexing:deep_index(Doc, _UpdateWords = true),
ok
end,
entries => [Document],
Expand Down
Loading