-
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
23d5834
7c668c0
54a9482
d59bcac
6374937
a9ffadb
81fbc69
d99f888
e4b042e
7ed12ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| 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 { | ||
| // This is implemented as the pull-based model, settings included with the notification are | ||
| // not considered. | ||
| fn run( | ||
| session: &mut Session, | ||
| client: &Client, | ||
| _params: types::DidChangeConfigurationParams, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On neovim, the invocation of this notification is manual, so you need to pass the settings as an argument through Had a go trying to see what vscode send with the It seems this varies from client to client. Let me know if I've misunderstood this comment :) |
||
| ) -> Result<()> { | ||
| tracing::debug!("Received workspace/didChangeConfiguration"); | ||
|
|
||
| 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(()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should call
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to updates tests to cover this? |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.