Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancel current progress messages when changing/saving file #61

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule NextLS do
@moduledoc false
use GenLSP

Check warning on line 3 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / Test (1.15.x/24.x)

Logger.warn/1 is deprecated. Use Logger.warning/2 instead

Check warning on line 3 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / Test (1.15.x/24.x)

Logger.warn/1 is deprecated. Use Logger.warning/2 instead

Check warning on line 3 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / Test (1.15.x/25.x)

Logger.warn/1 is deprecated. Use Logger.warning/2 instead

Check warning on line 3 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / Test (1.15.x/25.x)

Logger.warn/1 is deprecated. Use Logger.warning/2 instead

alias GenLSP.ErrorResponse

Expand Down Expand Up @@ -252,6 +252,11 @@
},
%{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 @@
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 @@

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 @@
})
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
Loading