mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Handle untitled files in Neovim
This commit is contained in:
parent
64effa4aea
commit
752ad4d579
2 changed files with 18 additions and 11 deletions
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue