Skip to content

Commit

Permalink
Fix a few Windows tests (zed-industries#19773)
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore authored Oct 26, 2024
1 parent fc8a72c commit d7a2776
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
19 changes: 16 additions & 3 deletions crates/editor/src/test/editor_lsp_test_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
borrow::Cow,
ops::{Deref, DerefMut, Range},
path::Path,
sync::Arc,
};

Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -310,6 +313,16 @@ impl EditorLspTestContext {
pub fn notify<T: notification::Notification>(&self, params: T::Params) {
self.lsp.notify::<T>(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 {
Expand Down
15 changes: 11 additions & 4 deletions crates/fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions crates/lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,17 @@ 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,
stdout_reader,
None::<async_pipe::PipeReader>,
Arc::new(Mutex::new(None)),
None,
Path::new("/"),
Path::new("/"),
root,
root,
None,
cx.clone(),
|_| {},
Expand All @@ -1201,8 +1203,8 @@ impl FakeLanguageServer {
None::<async_pipe::PipeReader>,
Arc::new(Mutex::new(None)),
None,
Path::new("/"),
Path::new("/"),
root,
root,
None,
cx,
move |msg| {
Expand Down Expand Up @@ -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"))]
Expand Down

0 comments on commit d7a2776

Please sign in to comment.