diff --git a/crates/ruff_server/src/lint.rs b/crates/ruff_server/src/lint.rs index 9b9e8a06d2..36302d6e5f 100644 --- a/crates/ruff_server/src/lint.rs +++ b/crates/ruff_server/src/lint.rs @@ -81,13 +81,17 @@ pub(crate) fn check( return DiagnosticsMap::default(); } - detect_package_root( - document_path - .parent() - .expect("a path to a document should have a parent path"), - &settings.linter.namespace_packages, - ) - .map(PackageRoot::root) + if let Some(parent) = document_path.parent() { + detect_package_root(parent, &settings.linter.namespace_packages).map(PackageRoot::root) + } else { + // Untitled documents in Neovim are represented using `file:///` URIs which have no + // parent. See https://github.com/astral-sh/ruff/issues/15392. + tracing::info!( + "Cannot detect package root for document with no parent: {:?}", + document_path + ); + None + } } else { None }; diff --git a/crates/ruff_server/src/session/index.rs b/crates/ruff_server/src/session/index.rs index 4f75a35fe6..e46984dd0a 100644 --- a/crates/ruff_server/src/session/index.rs +++ b/crates/ruff_server/src/session/index.rs @@ -427,12 +427,15 @@ impl WorkspaceSettingsIndex { let workspace_url = workspace.url(); if workspace_url.scheme() != "file" { tracing::info!("Ignoring non-file workspace URL: {workspace_url}"); - show_warn_msg!("Ruff does not support non-file workspaces; Ignoring {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 Ok(workspace_path) = workspace_url.to_file_path() else { + tracing::warn!( + "Failed to convert workspace URL to file path; ignoring {workspace_url}" + ); + return Ok(()); + }; let client_settings = if let Some(workspace_settings) = workspace.settings() { ResolvedClientSettings::with_workspace(workspace_settings, global_settings)