Skip to content

Commit

Permalink
fix: cancel current progress messages when changing/saving file
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
mhanberg committed Jun 27, 2023
1 parent e08da46 commit 29dff9d
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ defmodule NextLS do
},
%{assigns: %{ready: true}} = lsp
) do
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor),
task != lsp.assigns.runtime_task.pid do
Process.exit(task, :kill)
end

token = token()

progress_start(lsp, token, "Compiling...")
Expand Down Expand Up @@ -339,15 +344,7 @@ defmodule NextLS do
Process.demonitor(ref, [:flush])
{{token, msg}, refs} = Map.pop(refs, ref)

GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
params: %GenLSP.Structures.ProgressParams{
token: token,
value: %WorkDoneProgressEnd{
kind: "end",
message: msg
}
}
})
progress_end(lsp, token, msg)

lsp =
case resp do
Expand All @@ -371,7 +368,9 @@ defmodule NextLS do

def handle_info({:DOWN, ref, :process, _pid, _reason}, %{assigns: %{refresh_refs: refs}} = lsp)
when is_map_key(refs, ref) do
{_token, refs} = Map.pop(refs, ref)
{{token, _}, refs} = Map.pop(refs, ref)

progress_end(lsp, token)

{:noreply, assign(lsp, refresh_refs: refs)}
end
Expand Down Expand Up @@ -425,6 +424,18 @@ defmodule NextLS do
})
end

defp progress_end(lsp, token, msg \\ nil) do
GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
params: %GenLSP.Structures.ProgressParams{
token: token,
value: %WorkDoneProgressEnd{
kind: "end",
message: msg
}
}
})
end

defp token() do
8
|> :crypto.strong_rand_bytes()
Expand Down

0 comments on commit 29dff9d

Please sign in to comment.