Skip to content

Commit 1461bb7

Browse files
committed
config: Defer initial config loading after initialized notification
Configuration loading now happens after the client sends the `InitializedNotification` rather than during the `InitializeRequest` handler, following the LSP specification. This fixes the unhanded `workspace/configuration` error on VSCode.
1 parent 6a43925 commit 1461bb7

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/lifecycle.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ function handle_InitializeRequest(
5050
# leave Refs undefined
5151
end
5252

53-
if !isdefined(state, :root_path)
54-
if JETLS_DEV_MODE
55-
@info "`server.state.root_path` is not defined, skip config registration at startup."
56-
end
57-
else
58-
config_path = joinpath(state.root_path, ".JETLSConfig.toml")
59-
if isfile(config_path)
60-
# Null callback: Don't notify even if values different from defaults are loaded initially
61-
load_file_config!(Returns(nothing), server, config_path)
62-
end
63-
end
64-
65-
# In a case when client doesn't support the pull model configuration,
66-
# use `init_params.initializationOptions` as the fallback
67-
load_lsp_config!(server, init_params.initializationOptions, "[LSP] initialize"; on_init=true)
68-
6953
start_analysis_workers!(server)
7054

7155
if supports(server, :textDocument, :completion, :dynamicRegistration)
@@ -270,6 +254,24 @@ function handle_InitializedNotification(server::Server)
270254

271255
isdefined(state, :init_params) || error("Initialization process not completed") # to exit the server loop
272256

257+
# Load configurations: This needs to be done after the `InitializedNotification` is sent from the client
258+
# - Load .JETLSConfig.toml configuration
259+
if !isdefined(state, :root_path)
260+
if JETLS_DEV_MODE
261+
@info "`server.state.root_path` is not defined, skip config registration at startup."
262+
end
263+
else
264+
config_path = joinpath(state.root_path, ".JETLSConfig.toml")
265+
if isfile(config_path)
266+
# Null callback: Don't notify even if values different from defaults are loaded initially
267+
load_file_config!(Returns(nothing), server, config_path)
268+
end
269+
end
270+
# - Load LSP configuration
271+
# In a case when client doesn't support the pull model configuration,
272+
# use `init_params.initializationOptions` as the fallback
273+
load_lsp_config!(server, state.init_params.initializationOptions, "[LSP] initialize"; on_init=true)
274+
273275
registrations = Registration[]
274276

275277
if supports(server, :textDocument, :completion, :dynamicRegistration)

0 commit comments

Comments
 (0)