-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[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
11
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 all commits
Commits
Show all changes
11 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 d5a0a71
Merge branch 'astral-sh:main' into pgm/workspace-did-change-configura…
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
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
92 changes: 92 additions & 0 deletions
92
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,92 @@ | ||
| use crate::server::Action; | ||
| use crate::server::Result; | ||
| use crate::server::api::diagnostics::publish_diagnostics_if_needed; | ||
| 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, | ||
| ) -> 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)); | ||
| }, | ||
| ); | ||
|
|
||
| for key in session.text_document_handles() { | ||
| publish_diagnostics_if_needed(&key, session, client); | ||
| } | ||
|
|
||
| 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? |
||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
The
paramsdo contain the changed setting. Do you know if it includes all settings or do clients indeed only send the changed settings?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.
On neovim, the invocation of this notification is manual, so you need to pass the settings as an argument through
client:notify.Had a go trying to see what vscode send with the
didChangeConfigurationevent, it seems like nothing is sent at all.It seems this varies from client to client. Let me know if I've misunderstood this comment :)
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.
Testing it with VS Code would be good. Specifically also to test whether it sends the notification is only sent when changing
tyspecific settings or is sent when changing arbitrary VS Code settings.It would be so nice if it included the whole configuration. It feels silly that we have to request the configuration again :( I'd rather avoid that
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.
I removed all the selected items from:
https://github.com/astral-sh/ty-vscode/blob/da5152f543a9f659bceae71748ba535a5b2a536b/src/common/settings.ts#L122-L130
Running
tywith this PRs compiled executable I get the following behavior:Changing a ty setting (diagnostic mode), I get the log:
Changing a non-ty, vscode setting (Auto Save), I also get the log:
Unfortunately I don't think it includes the config =(, at least with vscode it seems necessary to repull everything.