diff --git a/crates/editor/src/test/editor_lsp_test_context.rs b/crates/editor/src/test/editor_lsp_test_context.rs index b93b8d3e7e003..23c5775abd05c 100644 --- a/crates/editor/src/test/editor_lsp_test_context.rs +++ b/crates/editor/src/test/editor_lsp_test_context.rs @@ -1,6 +1,7 @@ use std::{ borrow::Cow, ops::{Deref, DerefMut, Range}, + path::Path, sync::Arc, }; @@ -66,10 +67,12 @@ impl EditorLspTestContext { ); language_registry.add(Arc::new(language)); + let root = Self::root_path(); + app_state .fs .as_fake() - .insert_tree("/root", json!({ "dir": { file_name.clone(): "" }})) + .insert_tree(root, json!({ "dir": { file_name.clone(): "" }})) .await; let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); @@ -79,7 +82,7 @@ impl EditorLspTestContext { let mut cx = VisualTestContext::from_window(*window.deref(), cx); project .update(&mut cx, |project, cx| { - project.find_or_create_worktree("/root", true, cx) + project.find_or_create_worktree(root, true, cx) }) .await .unwrap(); @@ -108,7 +111,7 @@ impl EditorLspTestContext { }, lsp, workspace, - buffer_lsp_url: lsp::Url::from_file_path(format!("/root/dir/{file_name}")).unwrap(), + buffer_lsp_url: lsp::Url::from_file_path(root.join("dir").join(file_name)).unwrap(), } } @@ -310,6 +313,16 @@ impl EditorLspTestContext { pub fn notify(&self, params: T::Params) { self.lsp.notify::(params); } + + #[cfg(target_os = "windows")] + fn root_path() -> &'static Path { + Path::new("C:\\root") + } + + #[cfg(not(target_os = "windows"))] + fn root_path() -> &'static Path { + Path::new("/root") + } } impl Deref for EditorLspTestContext { diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index 7064448e16829..5ee2947448c90 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -865,14 +865,20 @@ impl FakeFsState { let mut entry_stack = Vec::new(); 'outer: loop { let mut path_components = path.components().peekable(); + let mut prefix = None; while let Some(component) = path_components.next() { match component { - Component::Prefix(_) => panic!("prefix paths aren't supported"), + Component::Prefix(prefix_component) => prefix = Some(prefix_component), Component::RootDir => { entry_stack.clear(); entry_stack.push(self.root.clone()); canonical_path.clear(); - canonical_path.push("/"); + match prefix { + Some(prefix_component) => { + canonical_path.push(prefix_component.as_os_str()); + } + None => canonical_path.push("/"), + } } Component::CurDir => {} Component::ParentDir => { @@ -1384,11 +1390,12 @@ impl Fs for FakeFs { let mut created_dirs = Vec::new(); let mut cur_path = PathBuf::new(); for component in path.components() { - let mut state = self.state.lock(); + let should_skip = matches!(component, Component::Prefix(..) | Component::RootDir); cur_path.push(component); - if cur_path == Path::new("/") { + if should_skip { continue; } + let mut state = self.state.lock(); let inode = state.next_inode; let mtime = state.next_mtime; diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index a105c983f9ec3..df2ab35fc4337 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -1177,6 +1177,8 @@ impl FakeLanguageServer { let (stdout_writer, stdout_reader) = async_pipe::pipe(); let (notifications_tx, notifications_rx) = channel::unbounded(); + let root = Self::root_path(); + let mut server = LanguageServer::new_internal( server_id, stdin_writer, @@ -1184,8 +1186,8 @@ impl FakeLanguageServer { None::, Arc::new(Mutex::new(None)), None, - Path::new("/"), - Path::new("/"), + root, + root, None, cx.clone(), |_| {}, @@ -1201,8 +1203,8 @@ impl FakeLanguageServer { None::, Arc::new(Mutex::new(None)), None, - Path::new("/"), - Path::new("/"), + root, + root, None, cx, move |msg| { @@ -1238,6 +1240,16 @@ impl FakeLanguageServer { (server, fake) } + + #[cfg(target_os = "windows")] + fn root_path() -> &'static Path { + Path::new("C:\\") + } + + #[cfg(not(target_os = "windows"))] + fn root_path() -> &'static Path { + Path::new("/") + } } #[cfg(any(test, feature = "test-support"))]