Skip to content

Commit 3a19a57

Browse files
committed
do not overwrite pid entries during concurrent parse requests to the same file
1 parent 39dc9d5 commit 3a19a57

File tree

1 file changed

+19
-3
lines changed
  • apps/language_server/lib/language_server

1 file changed

+19
-3
lines changed

apps/language_server/lib/language_server/parser.ex

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ defmodule ElixirLS.LanguageServer.Parser do
225225
%{
226226
state
227227
| files: Map.put(files, uri, updated_file),
228-
parse_pids: Map.put(state.parse_pids, {uri, current_version}, {pid, ref, from}),
228+
parse_pids: put_nested(state.parse_pids, {uri, current_version}, ref, {pid, from}),
229229
parse_uris: Map.put(state.parse_uris, ref, {uri, current_version})
230230
}}
231231
end
@@ -254,7 +254,7 @@ defmodule ElixirLS.LanguageServer.Parser do
254254
state = %{
255255
state
256256
| debounce_refs: Map.delete(debounce_refs, uri),
257-
parse_pids: Map.put(state.parse_pids, {uri, version}, {pid, ref, nil}),
257+
parse_pids: put_nested(state.parse_pids, {uri, version}, ref, {pid, nil}),
258258
parse_uris: Map.put(state.parse_uris, ref, {uri, version})
259259
}
260260

@@ -307,7 +307,16 @@ defmodule ElixirLS.LanguageServer.Parser do
307307
%{parse_pids: parse_pids, parse_uris: parse_uris} = state
308308
) do
309309
{{uri, version}, updated_parse_uris} = Map.pop!(parse_uris, ref)
310-
{{^pid, ^ref, from}, updated_parse_pids} = Map.pop!(parse_pids, {uri, version})
310+
311+
{by_ref, updated_parse_pids} = Map.pop!(parse_pids, {uri, version})
312+
{{^pid, from}, updated_by_ref} = Map.pop!(by_ref, ref)
313+
314+
updated_parse_pids =
315+
if updated_by_ref == %{} do
316+
updated_by_ref
317+
else
318+
Map.put(updated_parse_pids, ref, updated_by_ref)
319+
end
311320

312321
if reason != :normal and from != nil do
313322
GenServer.reply(from, :error)
@@ -625,4 +634,11 @@ defmodule ElixirLS.LanguageServer.Parser do
625634
{:error, diagnostic} -> {nil, [diagnostic | warning_diagnostics]}
626635
end
627636
end
637+
638+
defp put_nested(map, key1, key2, value) do
639+
update_in(map, [key1], fn
640+
nil -> %{key2 => value}
641+
inner -> Map.put(inner, key2, value)
642+
end)
643+
end
628644
end

0 commit comments

Comments
 (0)