-
Notifications
You must be signed in to change notification settings - Fork 2k
[ty] Implement workspace/didChangeConfiguration
#24712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pierrem964
wants to merge
10
commits into
astral-sh:main
Choose a base branch
from
pierrem964:pgm/workspace-did-change-configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
23d5834
Implement did_change_configuration
pierrem964 7c668c0
remove capability for now
pierrem964 54a9482
Fix clippy issues, register workspace/didChangeConfiguration as a cap…
pierrem964 d59bcac
Make function name more clear
pierrem964 6374937
Add more logs
pierrem964 a9ffadb
Fix typos
pierrem964 81fbc69
Do not reinitialize the project database, address review comments
pierrem964 d99f888
Merge branch 'astral-sh:main' into pgm/workspace-did-change-configura…
pierrem964 e4b042e
Use project.reload, revert session.rs updates
pierrem964 7ed12ec
run publish_diagnostics_if_needed within notification
pierrem964 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
crates/ty_server/src/server/api/notifications/did_change_configuration.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| use crate::server::Action; | ||
| use crate::server::Result; | ||
| use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler}; | ||
| use crate::session::client::Client; | ||
| use crate::session::{ClientOptions, Session}; | ||
| use lsp_types::notification as notif; | ||
| use lsp_types::{self as types, ConfigurationParams, Url}; | ||
|
|
||
| pub(crate) struct DidChangeConfiguration; | ||
|
|
||
| impl NotificationHandler for DidChangeConfiguration { | ||
| type NotificationType = notif::DidChangeConfiguration; | ||
| } | ||
|
|
||
| impl SyncNotificationHandler for DidChangeConfiguration { | ||
| fn run( | ||
| session: &mut Session, | ||
| client: &Client, | ||
| params: types::DidChangeConfigurationParams, | ||
| ) -> Result<()> { | ||
| tracing::debug!("Received workspace/didChangeConfiguration"); | ||
| // workspace/didChangeConfiguration is a pull based, meaning the request should be empty, and | ||
| // the server needs to pull the workspace configuration by requesting it from the | ||
| // client. | ||
| // See https://github.com/microsoft/vscode-languageserver-node/issues/380#issuecomment-414691493 | ||
| // See https://github.com/microsoft/language-server-protocol/issues/676 | ||
| assert!(params.settings.is_null()); | ||
|
|
||
| let workspace_urls: Vec<Url> = session | ||
| .workspaces() | ||
| .into_iter() | ||
| .map(|(_, workspace)| workspace.url().clone()) | ||
| .collect(); | ||
|
|
||
| let items: Vec<types::ConfigurationItem> = workspace_urls | ||
| .iter() | ||
| .map(|workspace| types::ConfigurationItem { | ||
| scope_uri: Some(workspace.clone()), | ||
| section: Some("ty".to_string()), | ||
| }) | ||
| .collect(); | ||
|
|
||
| tracing::debug!("Sending workspace/configuration requests to client"); | ||
| client.send_request::<lsp_types::request::WorkspaceConfiguration>( | ||
| session, | ||
| ConfigurationParams { items }, | ||
| |client, result: Vec<serde_json::value::Value>| { | ||
| // This shouldn't fail because, as per the spec, the client needs to provide a | ||
| // `null` value even if it cannot provide a configuration for a workspace. | ||
| assert_eq!( | ||
| result.len(), | ||
| workspace_urls.len(), | ||
| "Mismatch in number of workspace URLs ({}) and configuration results ({})", | ||
| workspace_urls.len(), | ||
| result.len() | ||
| ); | ||
|
|
||
| let workspaces_with_options: Vec<(Url, ClientOptions)> = workspace_urls | ||
| .into_iter() | ||
| .zip(result) | ||
| .map(|(url, value)| { | ||
| if value.is_null() { | ||
| tracing::debug!( | ||
| "No workspace options provided for {url}, using default options" | ||
| ); | ||
| return (url, ClientOptions::default()); | ||
| } | ||
| let options: ClientOptions = | ||
| serde_json::from_value(value).unwrap_or_else(|err| { | ||
| tracing::error!( | ||
| "Failed to deserialize workspace options for {url}: {err}. \ | ||
| Using default options" | ||
| ); | ||
| ClientOptions::default() | ||
| }); | ||
| (url, options) | ||
| }) | ||
| .collect(); | ||
|
|
||
| tracing::debug!( | ||
| "Received new configuration options {:?}", | ||
| workspaces_with_options, | ||
| ); | ||
|
|
||
| client.queue_action(Action::UpdateWorkspaceConfigs(workspaces_with_options)); | ||
| }, | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call
publish_diagnostics_if_neededhere for clients using the push diagnostics model.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to updates tests to cover this?