mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
ruff server
default to current working directory in environments without any root directories or workspaces (#10398)
## Summary Fixes #10324 This removes an overeager failure case where we would exit early if no root directory or workspace folders were provided on server initialization. We now fall-back to the current working directory as a workspace for that file. ## Test Plan N/A
This commit is contained in:
parent
b98d8ae42e
commit
93566f9321
1 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,5 @@
|
|||
//! Scheduling, I/O, and API endpoints.
|
||||
|
||||
use anyhow::anyhow;
|
||||
use lsp::Connection;
|
||||
use lsp_server as lsp;
|
||||
use lsp_types as types;
|
||||
|
@ -46,8 +45,12 @@ impl Server {
|
|||
.workspace_folders
|
||||
.map(|folders| folders.into_iter().map(|folder| folder.uri).collect())
|
||||
.or_else(|| init_params.root_uri.map(|u| vec![u]))
|
||||
.or_else(|| {
|
||||
tracing::debug!("No root URI or workspace(s) were provided during initialization. Using the current working directory as a default workspace...");
|
||||
Some(vec![types::Url::from_file_path(std::env::current_dir().ok()?).ok()?])
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
anyhow!("No workspace or root URI was given in the LSP initialization parameters. The server cannot start.")
|
||||
anyhow::anyhow!("Failed to get the current working directory while creating a default workspace.")
|
||||
})?;
|
||||
|
||||
let initialize_data = serde_json::json!({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue