diff --git a/crates/ruff_server/src/message.rs b/crates/ruff_server/src/message.rs index 79d7c63ec347a..ef692e3561488 100644 --- a/crates/ruff_server/src/message.rs +++ b/crates/ruff_server/src/message.rs @@ -37,10 +37,18 @@ pub(super) fn try_show_message( Ok(()) } -/// Sends an error to the client with a formatted message. The error is sent in a -/// `window/showMessage` notification. +/// Sends a request to display an error to the client with a formatted message. The error is sent +/// in a `window/showMessage` notification. macro_rules! show_err_msg { ($msg:expr$(, $($arg:tt),*)?) => { crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::ERROR) }; } + +/// Sends a request to display a warning to the client with a formatted message. The warning is +/// sent in a `window/showMessage` notification. +macro_rules! show_warn_msg { + ($msg:expr$(, $($arg:tt),*)?) => { + crate::message::show_message(::core::format_args!($msg, $($($arg),*)?).to_string(), lsp_types::MessageType::WARNING) + }; +} diff --git a/crates/ruff_server/src/session/index.rs b/crates/ruff_server/src/session/index.rs index feace554a5445..cca313d817605 100644 --- a/crates/ruff_server/src/session/index.rs +++ b/crates/ruff_server/src/session/index.rs @@ -200,16 +200,21 @@ impl Index { workspace_settings: Option, global_settings: &ClientSettings, ) -> crate::Result<()> { + if workspace_url.scheme() != "file" { + tracing::warn!("Ignoring non-file workspace: {workspace_url}"); + show_warn_msg!("Ruff does not support non-file workspaces; Ignoring {workspace_url}"); + return Ok(()); + } + let workspace_path = workspace_url.to_file_path().map_err(|()| { + anyhow!("Failed to convert workspace URL to file path: {workspace_url}") + })?; + let client_settings = if let Some(workspace_settings) = workspace_settings { ResolvedClientSettings::with_workspace(&workspace_settings, global_settings) } else { ResolvedClientSettings::global(global_settings) }; - let workspace_path = workspace_url - .to_file_path() - .map_err(|()| anyhow!("workspace URL was not a file path!"))?; - let workspace_settings_index = ruff_settings::RuffSettingsIndex::new( &workspace_path, client_settings.editor_settings(), @@ -227,9 +232,9 @@ impl Index { } pub(super) fn close_workspace_folder(&mut self, workspace_url: &Url) -> crate::Result<()> { - let workspace_path = workspace_url - .to_file_path() - .map_err(|()| anyhow!("workspace URL was not a file path!"))?; + let workspace_path = workspace_url.to_file_path().map_err(|()| { + anyhow!("Failed to convert workspace URL to file path: {workspace_url}") + })?; self.settings.remove(&workspace_path).ok_or_else(|| { anyhow!(