mirror of https://github.com/astral-sh/ruff
Remove hack about unknown options warning
This commit is contained in:
parent
aaadf16b1b
commit
b44851f686
|
|
@ -3,7 +3,7 @@
|
|||
use self::schedule::spawn_main_loop;
|
||||
use crate::PositionEncoding;
|
||||
use crate::capabilities::{ResolvedClientCapabilities, server_capabilities};
|
||||
use crate::session::{InitializationOptions, Session};
|
||||
use crate::session::{InitializationOptions, Session, warn_about_unknown_options};
|
||||
use anyhow::Context;
|
||||
use lsp_server::Connection;
|
||||
use lsp_types::{ClientCapabilities, InitializeParams, MessageType, Url};
|
||||
|
|
@ -96,29 +96,7 @@ impl Server {
|
|||
|
||||
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("', '")
|
||||
));
|
||||
}
|
||||
warn_about_unknown_options(&client, None, unknown_options);
|
||||
}
|
||||
|
||||
// Get workspace URLs without settings - settings will come from workspace/configuration
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Data model, state management, and configuration resolution.
|
||||
|
||||
use std::collections::{BTreeMap, HashSet, VecDeque};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::panic::RefUnwindSafe;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -467,28 +467,7 @@ impl Session {
|
|||
|
||||
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("', '")
|
||||
));
|
||||
}
|
||||
warn_about_unknown_options(client, Some(&url), unknown_options);
|
||||
}
|
||||
|
||||
combined_global_options.combine_with(Some(global));
|
||||
|
|
@ -1595,3 +1574,29 @@ impl DocumentHandle {
|
|||
Ok(requires_clear_diagnostics)
|
||||
}
|
||||
}
|
||||
|
||||
/// Warns about unknown options received by the server.
|
||||
///
|
||||
/// If `workspace_url` is `Some`, it indicates that the unknown options were received during a
|
||||
/// workspace initialization, otherwise they were received during the server initialization.
|
||||
pub(super) fn warn_about_unknown_options(
|
||||
client: &Client,
|
||||
workspace_url: Option<&Url>,
|
||||
unknown_options: &HashMap<String, serde_json::Value>,
|
||||
) {
|
||||
let message = if let Some(workspace_url) = workspace_url {
|
||||
format!(
|
||||
"Received unknown options for workspace `{workspace_url}`: {}",
|
||||
serde_json::to_string_pretty(unknown_options)
|
||||
.unwrap_or_else(|_| format!("{unknown_options:?}"))
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"Received unknown options during initialization: {}",
|
||||
serde_json::to_string_pretty(unknown_options)
|
||||
.unwrap_or_else(|_| format!("{unknown_options:?}"))
|
||||
)
|
||||
};
|
||||
tracing::warn!("{message}");
|
||||
client.show_warning_message(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ fn unknown_initialization_options() -> Result<()> {
|
|||
insta::assert_json_snapshot!(show_message_params, @r#"
|
||||
{
|
||||
"type": 2,
|
||||
"message": "Received unknown options during initialization: 'bar'. Refer to the logs for more details"
|
||||
"message": "Received unknown options during initialization: {\n /"bar/": null\n}"
|
||||
}
|
||||
"#);
|
||||
|
||||
|
|
@ -427,7 +427,7 @@ fn unknown_options_in_workspace_configuration() -> Result<()> {
|
|||
insta::assert_json_snapshot!(show_message_params, @r#"
|
||||
{
|
||||
"type": 2,
|
||||
"message": "Received unknown options for workspace `file://<temp_dir>/foo`: 'bar'. Refer to the logs for more details."
|
||||
"message": "Received unknown options for workspace `file://<temp_dir>/foo`: {\n /"bar/": null\n}"
|
||||
}
|
||||
"#);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue