From 8ae98c05c297565fdd07c3f13b9a8ffb7a9df2d2 Mon Sep 17 00:00:00 2001 From: doorgan Date: Fri, 4 Jul 2025 20:50:23 -0300 Subject: [PATCH] fix: use dynamic registrations and start project node asynchronously --- apps/expert/lib/expert.ex | 18 ++++++++++-------- apps/expert/lib/expert/state.ex | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/expert/lib/expert.ex b/apps/expert/lib/expert.ex index ab033f4a..55d58e8c 100644 --- a/apps/expert/lib/expert.ex +++ b/apps/expert/lib/expert.ex @@ -18,7 +18,6 @@ defmodule Expert do GenLSP.Notifications.TextDocumentDidOpen, GenLSP.Notifications.TextDocumentDidSave, GenLSP.Notifications.Exit, - GenLSP.Notifications.Initialized, GenLSP.Requests.Shutdown ] @@ -47,13 +46,6 @@ defmodule Expert do case State.initialize(state, request) do {:ok, response, state} -> - # TODO: this should be gated behind the dynamic registration in the initialization params - registrations = registrations() - - if nil != GenLSP.request(lsp, registrations) do - Logger.error("Failed to register capability") - end - lsp = assign(lsp, state: state) {:ok, response} = Forge.Protocol.Convert.to_lsp(response) @@ -119,6 +111,16 @@ defmodule Expert do end end + def handle_notification(%GenLSP.Notifications.Initialized{}, lsp) do + registrations = registrations() + + if nil != GenLSP.request(lsp, registrations) do + Logger.error("Failed to register capability") + end + + {:noreply, lsp} + end + def handle_notification(%mod{} = notification, lsp) when mod in @server_specific_messages do with {:ok, notification} <- Convert.to_native(notification), {:ok, state} <- apply_to_state(assigns(lsp).state, notification) do diff --git a/apps/expert/lib/expert/state.ex b/apps/expert/lib/expert/state.ex index c17a54b8..b9bd5f23 100644 --- a/apps/expert/lib/expert/state.ex +++ b/apps/expert/lib/expert/state.ex @@ -54,7 +54,8 @@ defmodule Expert.State do response = initialize_result() - Project.Supervisor.start(config.project) + Task.start_link(fn -> Project.Supervisor.start(config.project) end) + {:ok, response, new_state} end