Send structured InitializationOptions
to the server
#121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #100
Update: I am no longer convinced this is the right approach for most user or workspace level settings. These aren't strictly required at initialization time, unlike the initial
logLevel
anddependencyLogLevels
, which are used inInitialize
for logging setup (which we want ASAP). Instead, we should "pull" user and workspace level settings using aConfiguration
request once afterInitialized
for user and workspace settings, and again after workspace open events and changed file events (the only thing to worry about is that aConfiguration
request is typically async, so in theory we could get other requests while waiting on the response, but right now in practice all messages are sequential anyways). If we ever wantedlogLevel
to eventually be dynamic, it should come throughinitializationOptions
AND also be "pull"ed alongside the other settings. See microsoft/language-server-protocol#567 which confirmed my beliefs about all this.The game plan would be:
initializationOptions
. It would just belogLevel
anddependencyLogLevels
for nowair.toml
in the CLI and LSP #122 is merged to add support for "refreshable" user and workspace level options (which we don't have any of yet, but probably will...), supporting them in:Initialized
notification handler, where we'd request them for the first time (possibly also adding a lock to prevent any other requests from running until we've requested them and set them)DidChangeWorkspaceFolders
, requesting them for opened workspaces, purging them for closed workspacesDidChangeConfiguration
, where we useDidChangeConfiguration
as a simple notification that "something" has changed in configuration, so we have to repull every scope we are interested in (this is now how you are supposed to useDidChangeConfiguration
apparently)logLevel
anddependencyLogLevels
in addition to sending them ininitializationOptions
to make them dynamic, if we can figure out how to update those in the logger without adding global state.The point of this PR is to send structured data through the
InitializeParams
"free field" ofinitializationOptions
. This is usable by LSPs as a way to send initialization options specific to that LSP through on startup.Currently, we send all 3 of
ClientGlobalSettings
,ClientUserSettings
andClientWorkspaceSettings
through here, but onlyClientGlobalSettings
is populated (with log level settings). The other 2 are placeholders for now, but I wanted to get the infrastructure right.The reason I am uncertain about user and workspace settings going through here is that:
initializationOptions
provides us no way to "refresh" the settings if they changeinitializationOptions
provides us no way to access settings for newly opened workspaces that we get notified about throughDidChangeWorkspaceFolders
. Ruff currently has this problem as well (and they have a TODO about it on their side)I am strongly considering instead having the air server send a
Configuration
LSP request to the Client immediately after we get anInitialized
LSP notification. We will have the initial set of workspace names from theInitialize
request, so we will be able to correctly "scope" our requests for"air."
configuration settings (one request at user level, and then one request per open workspace).The big benefit of that approach is that we can request and refresh
Configuration
at any time, including:Initialized
, with the initial set of workspacesDidChangeWorkspaceFolders
, with the newly opened workspaceDidChangeConfiguration
notification orDidChangeWatchedFiles
notification where we watchsettings.json
files. In both cases we'd probably just trigger a fullConfiguration
request for the relevant changed scope.https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration
I do not believe there are any other benefits of using
initializationOptions
overConfiguration
for this. Even in Zed I believe you will just do: