diff --git a/crates/ruff_server/src/server.rs b/crates/ruff_server/src/server.rs index bf88192e45..a934471701 100644 --- a/crates/ruff_server/src/server.rs +++ b/crates/ruff_server/src/server.rs @@ -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!({