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:
Jane Lewis 2024-03-18 08:46:44 -07:00 committed by GitHub
parent b98d8ae42e
commit 93566f9321
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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!({