mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Avoid warning for old settings schema too aggresively (#19787)
## Summary This PR avoids warning the users too aggressively by checking the structure of the initialization and workspace options and avoids the warning if they conform to the old schema. ## Test Plan https://github.com/user-attachments/assets/9ade9dc4-90cb-4fd4-abd0-4bc4177df3db
This commit is contained in:
parent
b96929ee19
commit
ec5660d786
3 changed files with 53 additions and 22 deletions
|
@ -98,13 +98,31 @@ impl Server {
|
|||
let (main_loop_sender, main_loop_receiver) = crossbeam::channel::bounded(32);
|
||||
let client = Client::new(main_loop_sender.clone(), connection.sender.clone());
|
||||
|
||||
if !initialization_options.options.unknown.is_empty() {
|
||||
let options = serde_json::to_string_pretty(&initialization_options.options.unknown)
|
||||
.unwrap_or_else(|_| "<invalid JSON>".to_string());
|
||||
tracing::warn!("Received unknown options during initialization: {options}");
|
||||
client.show_warning_message(format_args!(
|
||||
"Received unknown options during initialization: {options}"
|
||||
));
|
||||
let unknown_options = &initialization_options.options.unknown;
|
||||
if !unknown_options.is_empty() {
|
||||
// HACK: Old versions of the ty VS Code extension used a custom schema for settings
|
||||
// which was changed in version 2025.35.0. This is to ensure that users don't receive
|
||||
// unnecessary warnings when using an older version of the extension. This should be
|
||||
// removed after a few releases.
|
||||
if !unknown_options.contains_key("settings")
|
||||
|| !unknown_options.contains_key("globalSettings")
|
||||
{
|
||||
tracing::warn!(
|
||||
"Received unknown options during initialization: {}",
|
||||
serde_json::to_string_pretty(unknown_options)
|
||||
.unwrap_or_else(|_| format!("{unknown_options:?}"))
|
||||
);
|
||||
|
||||
client.show_warning_message(format_args!(
|
||||
"Received unknown options during initialization: '{}'. \
|
||||
Refer to the logs for more details",
|
||||
unknown_options
|
||||
.keys()
|
||||
.map(String::as_str)
|
||||
.collect::<Vec<_>>()
|
||||
.join("', '")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Get workspace URLs without settings - settings will come from workspace/configuration
|
||||
|
|
|
@ -458,13 +458,30 @@ impl Session {
|
|||
.clone()
|
||||
.combine(options.clone());
|
||||
|
||||
if !options.unknown.is_empty() {
|
||||
let options = serde_json::to_string_pretty(&options.unknown)
|
||||
.unwrap_or_else(|_| "<invalid JSON>".to_string());
|
||||
tracing::warn!("Received unknown options for workspace `{url}`: {options}");
|
||||
client.show_warning_message(format!(
|
||||
"Received unknown options for workspace `{url}`: {options}",
|
||||
));
|
||||
let unknown_options = &options.unknown;
|
||||
if !unknown_options.is_empty() {
|
||||
// HACK: This is to ensure that users with an older version of the ty VS Code
|
||||
// extension don't get warnings about unknown options when they are using a newer
|
||||
// version of the language server. This should be removed after a few releases.
|
||||
if !unknown_options.contains_key("importStrategy")
|
||||
&& !unknown_options.contains_key("interpreter")
|
||||
{
|
||||
tracing::warn!(
|
||||
"Received unknown options for workspace `{url}`: {}",
|
||||
serde_json::to_string_pretty(unknown_options)
|
||||
.unwrap_or_else(|_| format!("{unknown_options:?}"))
|
||||
);
|
||||
|
||||
client.show_warning_message(format!(
|
||||
"Received unknown options for workspace `{url}`: '{}'. \
|
||||
Refer to the logs for more details.",
|
||||
unknown_options
|
||||
.keys()
|
||||
.map(String::as_str)
|
||||
.collect::<Vec<_>>()
|
||||
.join("', '")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
combined_global_options.combine_with(Some(global));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue