Skip to content

Commit

Permalink
fix: cancel current progress messages when changing/saving file (#61)
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 dca3b25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 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
2 changes: 1 addition & 1 deletion test/next_ls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ defmodule NextLSTest do
path: Path.join([cwd, "lib", file])
})

char = if Version.match?(System.version(), ">= 1.15.0"), do: 11, else: 0
char = if Version.match?(System.version(), ">= 1.15.0"), do: 10, else: 0

assert_notification "textDocument/publishDiagnostics", %{
"uri" => ^uri,
Expand Down

0 comments on commit dca3b25

Please sign in to comment.