Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Fill root_uri property on Initialize again (cherry-pick #25264) #25290

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct LanguageServer {
output_done_rx: Mutex<Option<barrier::Receiver>>,
server: Arc<Mutex<Option<Child>>>,
workspace_folders: Arc<Mutex<BTreeSet<Url>>>,
root_uri: Url,
}

/// Identifies a running language server.
Expand Down Expand Up @@ -369,6 +370,8 @@ impl LanguageServer {
let stdin = server.stdin.take().unwrap();
let stdout = server.stdout.take().unwrap();
let stderr = server.stderr.take().unwrap();
let root_uri = Url::from_file_path(&working_dir)
.map_err(|_| anyhow!("{} is not a valid URI", working_dir.display()))?;
let server = Self::new_internal(
server_id,
server_name,
Expand All @@ -379,6 +382,7 @@ impl LanguageServer {
Some(server),
code_action_kinds,
binary,
root_uri,
cx,
move |notification| {
log::info!(
Expand All @@ -404,6 +408,7 @@ impl LanguageServer {
server: Option<Child>,
code_action_kinds: Option<Vec<CodeActionKind>>,
binary: LanguageServerBinary,
root_uri: Url,
cx: AsyncApp,
on_unhandled_notification: F,
) -> Self
Expand Down Expand Up @@ -487,6 +492,7 @@ impl LanguageServer {
output_done_rx: Mutex::new(Some(output_done_rx)),
server: Arc::new(Mutex::new(server)),
workspace_folders: Default::default(),
root_uri,
}
}

Expand Down Expand Up @@ -615,7 +621,7 @@ impl LanguageServer {
InitializeParams {
process_id: None,
root_path: None,
root_uri: None,
root_uri: Some(self.root_uri.clone()),
initialization_options: None,
capabilities: ClientCapabilities {
general: Some(GeneralClientCapabilities {
Expand Down Expand Up @@ -1385,6 +1391,7 @@ impl FakeLanguageServer {

let server_name = LanguageServerName(name.clone().into());
let process_name = Arc::from(name.as_str());
let root = Self::root_path();
let mut server = LanguageServer::new_internal(
server_id,
server_name.clone(),
Expand All @@ -1395,6 +1402,7 @@ impl FakeLanguageServer {
None,
None,
binary.clone(),
root,
cx.clone(),
|_| {},
);
Expand All @@ -1412,6 +1420,7 @@ impl FakeLanguageServer {
None,
None,
binary,
Self::root_path(),
cx.clone(),
move |msg| {
notifications_tx
Expand Down Expand Up @@ -1446,6 +1455,15 @@ impl FakeLanguageServer {

(server, fake)
}
#[cfg(target_os = "windows")]
fn root_path() -> Url {
Url::from_file_path("C:/").unwrap()
}

#[cfg(not(target_os = "windows"))]
fn root_path() -> Url {
Url::from_file_path("/").unwrap()
}
}

#[cfg(any(test, feature = "test-support"))]
Expand Down
Loading