Skip to content

lsp: Wait for client to send initialized at boot#1909

Merged
charlieegan3 merged 1 commit intoopen-policy-agent:mainfrom
charlieegan3:wait-to-send-test-locations
Mar 9, 2026
Merged

lsp: Wait for client to send initialized at boot#1909
charlieegan3 merged 1 commit intoopen-policy-agent:mainfrom
charlieegan3:wait-to-send-test-locations

Conversation

@charlieegan3
Copy link
Copy Markdown
Contributor

Now the server will wait for the client to send the initialized (empty) message before starting work. Previously we got away with sending diagnostics but now we have a custom test location handler, we need to ensure that we wait for that to be registered before sending test location notifications.

So we have moved the load workspace contents to the post initialized state, and added a gate to block the test locations worker from running if the client does not support it.

@charlieegan3 charlieegan3 added the language server Issues related to Regal's language server label Mar 4, 2026
Now the server will wait for the client to send the initialized (empty)
message before starting work. Previously we got away with sending diagnostics
but now we have a custom test location handler, we need to ensure that we wait
for that to be registered before sending test location notifications.

So we have moved the load workspace contents to the post initialized state, and
added a gate to block the test locations worker from running if the client does
not support it.

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
@charlieegan3 charlieegan3 force-pushed the wait-to-send-test-locations branch from a9217d9 to 202dd59 Compare March 4, 2026 11:20
Copy link
Copy Markdown
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Code looks good to me. Are there any undesirable side-effects of doing this? Like slower init time? Is this what we should have done all the time?

@charlieegan3
Copy link
Copy Markdown
Contributor Author

I think this is what we should have done all the time and it is what others like gopls do. That said, it's not super clear, and is phrased more in terms of client responsibility than server.

The initialized notification is sent from the client to the server after the client received the result of the initialize request but before the client is sending any other request or notification to the server. The server can use the initialized notification, for example, to dynamically register capabilities. The initialized notification may only be sent once.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialized

@charlieegan3
Copy link
Copy Markdown
Contributor Author

It so happened that clients were able to accept diagnostics before the initialized message was sent back, so yes, this is a little slower.

@anderseknert
Copy link
Copy Markdown
Member

Thanks @charlieegan3 👍

@charlieegan3 charlieegan3 added this pull request to the merge queue Mar 9, 2026
Merged via the queue into open-policy-agent:main with commit 9900522 Mar 9, 2026
8 checks passed
@charlieegan3 charlieegan3 deleted the wait-to-send-test-locations branch March 9, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

language server Issues related to Regal's language server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants