Skip to content
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
27 changes: 15 additions & 12 deletions apps/expert/lib/expert/engine_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ defmodule Expert.EngineNode do
GenLSP.info(lsp, "Finding or building engine for project #{project_name}")

with_progress(project, "Building engine for #{project_name}", fn ->
port =
Port.open(
{:spawn_executable, launcher},
opts
)

wait_for_engine(port)
fn ->
Process.flag(:trap_exit, true)

{:spawn_executable, launcher}
|> Port.open(opts)
|> wait_for_engine()
end
|> Task.async()
|> Task.await(:infinity)
end)

{:error, :no_elixir, message} ->
Expand All @@ -230,20 +232,21 @@ defmodule Expert.EngineNode do
end
end

defp wait_for_engine(port) do
defp wait_for_engine(port, last_line \\ "") do
receive do
{^port, {:data, ~c"engine_path:" ++ engine_path}} ->
engine_path = engine_path |> to_string() |> String.trim()
Logger.info("Engine build available at: #{engine_path}")

{:ok, ebin_paths(engine_path)}

{^port, _data} ->
wait_for_engine(port)
{^port, {:data, data}} ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also help if we log the build output here.

Logger.debug("Building engine: #{to_string(data)}")
wait_for_engine(port, data)

{:EXIT, ^port, reason} ->
Logger.error("Engine build script exited with reason: #{inspect(reason)}")
{:error, reason}
Logger.error("Engine build script exited with reason: #{inspect(reason)} #{last_line}")
{:error, reason, last_line}
end
end

Expand Down
2 changes: 1 addition & 1 deletion apps/expert/lib/expert/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule Expert.State do
response = initialize_result()

Task.Supervisor.start_child(:expert_task_queue, fn ->
Project.Supervisor.start(config.project)
{:ok, _pid} = Project.Supervisor.start(config.project)
send(Expert, :engine_initialized)
end)

Expand Down
Loading