Skip to content

Commit 54480e1

Browse files
committed
fix: handle change and save notifcations before runtime is ready
1 parent 01e8139 commit 54480e1

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lib/next_ls.ex

+23-26
Original file line numberDiff line numberDiff line change
@@ -970,35 +970,34 @@ defmodule NextLS do
970970
{:noreply, assign(lsp, elixir_bin_path: elixir_bin_path)}
971971
end
972972

973-
def handle_notification(%TextDocumentDidSave{}, %{assigns: %{ready: false}} = lsp) do
974-
{:noreply, lsp}
975-
end
976-
977973
# TODO: add some test cases for saving files in multiple workspaces
978974
def handle_notification(
979975
%TextDocumentDidSave{
980976
params: %GenLSP.Structures.DidSaveTextDocumentParams{text: text, text_document: %{uri: uri}}
981977
},
982-
%{assigns: %{ready: true}} = lsp
978+
lsp
983979
) do
984-
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor) do
985-
Process.exit(task, :kill)
986-
end
987-
988980
refresh_refs =
989-
dispatch(lsp.assigns.registry, :runtimes, fn entries ->
990-
for {pid, %{name: name, uri: wuri}} <- entries,
991-
String.starts_with?(uri, wuri),
992-
into: %{} do
993-
token = Progress.token()
994-
Progress.start(lsp, token, "Compiling #{name}...")
981+
if lsp.assigns.ready do
982+
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor) do
983+
Process.exit(task, :kill)
984+
end
995985

996-
ref = make_ref()
997-
Runtime.compile(pid, caller_ref: ref)
986+
# dispatching to all workspaces
987+
dispatch(lsp.assigns.registry, :runtimes, fn entries ->
988+
for {pid, %{name: name, uri: wuri}} <- entries,
989+
String.starts_with?(uri, wuri),
990+
into: %{} do
991+
token = Progress.token()
992+
Progress.start(lsp, token, "Compiling #{name}...")
998993

999-
{ref, {token, "Compiled #{name}!"}}
1000-
end
1001-
end)
994+
ref = make_ref()
995+
Runtime.compile(pid, caller_ref: ref)
996+
997+
{ref, {token, "Compiled #{name}!"}}
998+
end
999+
end)
1000+
end
10021001

10031002
lsp =
10041003
lsp
@@ -1008,16 +1007,14 @@ defmodule NextLS do
10081007
{:noreply, lsp}
10091008
end
10101009

1011-
def handle_notification(%TextDocumentDidChange{}, %{assigns: %{ready: false}} = lsp) do
1012-
{:noreply, lsp}
1013-
end
1014-
10151010
def handle_notification(
10161011
%TextDocumentDidChange{params: %{text_document: %{uri: uri}, content_changes: [%{text: text}]}},
10171012
lsp
10181013
) do
1019-
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor) do
1020-
Process.exit(task, :kill)
1014+
if lsp.assigns.ready do
1015+
for task <- Task.Supervisor.children(lsp.assigns.task_supervisor) do
1016+
Process.exit(task, :kill)
1017+
end
10211018
end
10221019

10231020
lsp = put_in(lsp.assigns.documents[uri], String.split(text, "\n"))

0 commit comments

Comments
 (0)