mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
ruff server
: Add support for documents not exist on disk (#11588)
Co-authored-by: T-256 <Tester@test.com> Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
685d11a909
commit
5b500fc4dc
20 changed files with 380 additions and 366 deletions
|
@ -1,7 +1,6 @@
|
|||
//! Scheduling, I/O, and API endpoints.
|
||||
|
||||
use std::num::NonZeroUsize;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use lsp_server as lsp;
|
||||
use lsp_types as types;
|
||||
|
@ -75,27 +74,27 @@ impl Server {
|
|||
.unwrap_or_else(|| serde_json::Value::Object(serde_json::Map::default())),
|
||||
);
|
||||
|
||||
let mut workspace_for_path = |path: PathBuf| {
|
||||
let mut workspace_for_url = |url: lsp_types::Url| {
|
||||
let Some(workspace_settings) = workspace_settings.as_mut() else {
|
||||
return (path, ClientSettings::default());
|
||||
return (url, ClientSettings::default());
|
||||
};
|
||||
let settings = workspace_settings.remove(&path).unwrap_or_else(|| {
|
||||
tracing::warn!("No workspace settings found for {}", path.display());
|
||||
let settings = workspace_settings.remove(&url).unwrap_or_else(|| {
|
||||
tracing::warn!("No workspace settings found for {}", url);
|
||||
ClientSettings::default()
|
||||
});
|
||||
(path, settings)
|
||||
(url, settings)
|
||||
};
|
||||
|
||||
let workspaces = init_params
|
||||
.workspace_folders
|
||||
.filter(|folders| !folders.is_empty())
|
||||
.map(|folders| folders.into_iter().map(|folder| {
|
||||
workspace_for_path(folder.uri.to_file_path().unwrap())
|
||||
workspace_for_url(folder.uri)
|
||||
}).collect())
|
||||
.or_else(|| {
|
||||
tracing::warn!("No workspace(s) were provided during initialization. Using the current working directory as a default workspace...");
|
||||
let uri = types::Url::from_file_path(std::env::current_dir().ok()?).ok()?;
|
||||
Some(vec![workspace_for_path(uri.to_file_path().unwrap())])
|
||||
Some(vec![workspace_for_url(uri)])
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Failed to get the current working directory while creating a default workspace.")
|
||||
|
@ -109,7 +108,7 @@ impl Server {
|
|||
position_encoding,
|
||||
global_settings,
|
||||
workspaces,
|
||||
),
|
||||
)?,
|
||||
client_capabilities,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue