Skip to content

Commit 76d6cd5

Browse files
authored
fix: start projects after server is initialized (#294)
#18 introduced an issue where progress is trying to be reported before the server is initialized, which causes the client to report back an error and stops the server from starting up properly in VSCode. This fix ensures we start the projects only after the server is fully initialized, and so the progress from those projects is reproted at the right time.
1 parent b060d23 commit 76d6cd5

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

apps/expert/lib/expert.ex

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,7 @@ defmodule Expert do
7070

7171
ActiveProjects.set_projects(projects)
7272

73-
for project <- projects do
74-
Task.Supervisor.start_child(:expert_task_queue, fn ->
75-
log_info(lsp, project, "Starting project")
76-
77-
start_result = Expert.Project.Supervisor.ensure_node_started(project)
78-
79-
send(Expert, {:engine_initialized, project, start_result})
80-
end)
81-
end
73+
# Projects will be started when we receive the initialized notification
8274

8375
{:reply, response, assign(lsp, state: state)}
8476
else
@@ -197,6 +189,16 @@ defmodule Expert do
197189
Logger.error("Failed to register capability")
198190
end
199191

192+
for project <- ActiveProjects.projects() do
193+
Task.Supervisor.start_child(:expert_task_queue, fn ->
194+
log_info(lsp, project, "Starting project")
195+
196+
start_result = Expert.Project.Supervisor.ensure_node_started(project)
197+
198+
send(Expert, {:engine_initialized, project, start_result})
199+
end)
200+
end
201+
200202
{:noreply, lsp}
201203
end
202204

apps/expert/test/expert/expert_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ defmodule ExpertTest do
110110
}
111111
end
112112

113+
def initialized_notification do
114+
%{
115+
method: "initialized",
116+
jsonrpc: "2.0",
117+
params: %{}
118+
}
119+
end
120+
113121
def assert_project_alive?(project) do
114122
expected_uri = project.root_uri
115123
assert_receive {:project_alive, ^expected_uri}
@@ -136,6 +144,10 @@ defmodule ExpertTest do
136144
"capabilities" => %{"workspace" => %{"workspaceFolders" => %{"supported" => true}}}
137145
})
138146

147+
assert :ok = notify(client, initialized_notification())
148+
149+
assert_request(client, "client/registerCapability", fn _params -> nil end)
150+
139151
expected_message = "Started project node for #{Project.name(main_project)}"
140152

141153
assert_notification(
@@ -165,6 +177,10 @@ defmodule ExpertTest do
165177

166178
assert_result(1, _)
167179

180+
assert :ok = notify(client, initialized_notification())
181+
182+
assert_request(client, "client/registerCapability", fn _params -> nil end)
183+
168184
expected_message = "Started project node for #{Project.name(main_project)}"
169185

170186
assert_notification(
@@ -218,6 +234,11 @@ defmodule ExpertTest do
218234
)
219235

220236
assert_result(1, _)
237+
238+
assert :ok = notify(client, initialized_notification())
239+
240+
assert_request(client, "client/registerCapability", fn _params -> nil end)
241+
221242
expected_message = "Started project node for #{Project.name(main_project)}"
222243

223244
assert_notification(
@@ -291,6 +312,10 @@ defmodule ExpertTest do
291312

292313
assert_result(1, _)
293314

315+
assert :ok = notify(client, initialized_notification())
316+
317+
assert_request(client, "client/registerCapability", fn _params -> nil end)
318+
294319
expected_message = "Started project node for #{Project.name(main_project)}"
295320

296321
assert_notification(
@@ -484,6 +509,10 @@ defmodule ExpertTest do
484509

485510
assert_result(1, _)
486511

512+
assert :ok = notify(client, initialized_notification())
513+
514+
assert_request(client, "client/registerCapability", fn _params -> nil end)
515+
487516
expected_message = "Started project node for #{Project.name(nested_root_project)}"
488517

489518
assert_notification(

0 commit comments

Comments
 (0)