Skip to content

Commit dca3b25

Browse files
authored
fix: cancel current progress messages when changing/saving file (#61)
Fixes #40
1 parent e08da46 commit dca3b25

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/next_ls.ex

+21-10
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ defmodule NextLS do
252252
},
253253
%{assigns: %{ready: true}} = lsp
254254
) do
255+
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor),
256+
task != lsp.assigns.runtime_task.pid do
257+
Process.exit(task, :kill)
258+
end
259+
255260
token = token()
256261

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

342-
GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
343-
params: %GenLSP.Structures.ProgressParams{
344-
token: token,
345-
value: %WorkDoneProgressEnd{
346-
kind: "end",
347-
message: msg
348-
}
349-
}
350-
})
347+
progress_end(lsp, token, msg)
351348

352349
lsp =
353350
case resp do
@@ -371,7 +368,9 @@ defmodule NextLS do
371368

372369
def handle_info({:DOWN, ref, :process, _pid, _reason}, %{assigns: %{refresh_refs: refs}} = lsp)
373370
when is_map_key(refs, ref) do
374-
{_token, refs} = Map.pop(refs, ref)
371+
{{token, _}, refs} = Map.pop(refs, ref)
372+
373+
progress_end(lsp, token)
375374

376375
{:noreply, assign(lsp, refresh_refs: refs)}
377376
end
@@ -425,6 +424,18 @@ defmodule NextLS do
425424
})
426425
end
427426

427+
defp progress_end(lsp, token, msg \\ nil) do
428+
GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
429+
params: %GenLSP.Structures.ProgressParams{
430+
token: token,
431+
value: %WorkDoneProgressEnd{
432+
kind: "end",
433+
message: msg
434+
}
435+
}
436+
})
437+
end
438+
428439
defp token() do
429440
8
430441
|> :crypto.strong_rand_bytes()

test/next_ls_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ defmodule NextLSTest do
158158
path: Path.join([cwd, "lib", file])
159159
})
160160

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

163163
assert_notification "textDocument/publishDiagnostics", %{
164164
"uri" => ^uri,

0 commit comments

Comments
 (0)