mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Ignore non-file workspace URL (#12725)
## Summary This PR updates the server to ignore non-file workspace URL. This is to avoid crashing the server if the URL scheme is not "file". We'd still raise an error if the URL to file path conversion fails. Also, as per the docs of [`to_file_path`](https://docs.rs/url/2.5.2/url/struct.Url.html#method.to_file_path): > Note: This does not actually check the URL’s scheme, and may give nonsensical results for other schemes. It is the user’s responsibility to check the URL’s scheme before calling this. resolves: #12660 ## Test Plan I'm not sure how to test this locally but the change is small enough to validate on its own.
This commit is contained in:
parent
50ff5c7544
commit
7fcfedd430
2 changed files with 22 additions and 9 deletions
|
@ -200,16 +200,21 @@ impl Index {
|
|||
workspace_settings: Option<ClientSettings>,
|
||||
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!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue