Skip to content

Commit

Permalink
fix parser crash when file is closed and debounce timeout has already…
Browse files Browse the repository at this point in the history
… put a message to process queue
  • Loading branch information
lukaszsamson committed Mar 24, 2024
1 parent 06178f5 commit 2fd52cc
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions apps/language_server/lib/language_server/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,29 @@ defmodule ElixirLS.LanguageServer.Parser do
{:parse_file, uri},
%{files: files, debounce_refs: debounce_refs} = state
) do
file = Map.fetch!(files, uri)
version = file.source_file.version
state =
case files[uri] do
nil ->
# file got closed, no need to do anything
state
file ->
version = file.source_file.version

parent = self()
parent = self()

{pid, ref} =
spawn_monitor(fn ->
updated_file = do_parse(file)
send(parent, {:parse_file_done, uri, updated_file, nil})
end)
{pid, ref} =
spawn_monitor(fn ->
updated_file = do_parse(file)
send(parent, {:parse_file_done, uri, updated_file, nil})
end)

state = %{
state
| debounce_refs: Map.delete(debounce_refs, uri),
parse_pids: put_nested(state.parse_pids, {uri, version}, ref, {pid, nil}),
parse_uris: Map.put(state.parse_uris, ref, {uri, version})
}
%{
state
| debounce_refs: Map.delete(debounce_refs, uri),
parse_pids: put_nested(state.parse_pids, {uri, version}, ref, {pid, nil}),
parse_uris: Map.put(state.parse_uris, ref, {uri, version})
}
end

{:noreply, state}
end
Expand Down

0 comments on commit 2fd52cc

Please sign in to comment.