mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
better test, avoid duplicated events
This commit is contained in:
parent
0a08650852
commit
be14ab217c
3 changed files with 30 additions and 22 deletions
|
@ -55,7 +55,12 @@ pub enum TaskResult {
|
||||||
|
|
||||||
impl fmt::Debug for TaskResult {
|
impl fmt::Debug for TaskResult {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str("TaskResult { ... }")
|
match self {
|
||||||
|
TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"),
|
||||||
|
TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c),
|
||||||
|
TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c),
|
||||||
|
TaskResult::NoOp => f.write_str("TaskResult::NoOp"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,16 +100,18 @@ impl Watcher {
|
||||||
log::warn!("could not watch \"{}\": {}", entry.path().display(), e)
|
log::warn!("could not watch \"{}\": {}", entry.path().display(), e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if emit_for_contents && entry.depth() > 0 {
|
if emit_for_contents && entry.depth() > 0 {
|
||||||
// emit as create because we haven't seen it yet
|
// emit only for files otherwise we will cause watch_recursive to be called again with a dir that we are already watching
|
||||||
if let Err(e) =
|
// emit as create because we haven't seen it yet
|
||||||
self.sender
|
if let Err(e) =
|
||||||
.send(io::Task::HandleChange(WatcherChange::Create(
|
self.sender
|
||||||
entry.path().to_path_buf(),
|
.send(io::Task::HandleChange(WatcherChange::Create(
|
||||||
)))
|
entry.path().to_path_buf(),
|
||||||
{
|
)))
|
||||||
log::warn!("watcher error: {}", e)
|
{
|
||||||
|
log::warn!("watcher error: {}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use std::{collections::HashSet, fs};
|
use std::{collections::HashSet, fs};
|
||||||
|
|
||||||
// use flexi_logger::Logger;
|
use flexi_logger::Logger;
|
||||||
use ra_vfs::{Vfs, VfsChange};
|
use ra_vfs::{Vfs, VfsChange};
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
|
fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
|
||||||
for _ in 0..num_tasks {
|
for _ in 0..num_tasks {
|
||||||
let task = vfs.task_receiver().recv().unwrap();
|
let task = vfs.task_receiver().recv().unwrap();
|
||||||
|
log::debug!("{:?}", task);
|
||||||
vfs.handle_task(task);
|
vfs.handle_task(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +26,7 @@ macro_rules! assert_match {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vfs_works() -> std::io::Result<()> {
|
fn test_vfs_works() -> std::io::Result<()> {
|
||||||
// Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
|
Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
|
||||||
|
|
||||||
let files = [
|
let files = [
|
||||||
("a/foo.rs", "hello"),
|
("a/foo.rs", "hello"),
|
||||||
|
@ -114,21 +115,21 @@ fn test_vfs_works() -> std::io::Result<()> {
|
||||||
assert_eq!(path, "spam.rs")
|
assert_eq!(path, "spam.rs")
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::create_dir_all(dir.path().join("a/c")).unwrap();
|
fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap();
|
||||||
fs::write(dir.path().join("a/c/new.rs"), "new hello").unwrap();
|
fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap();
|
||||||
process_tasks(&mut vfs, 4);
|
process_tasks(&mut vfs, 4);
|
||||||
assert_match!(
|
assert_match!(
|
||||||
vfs.commit_changes().as_slice(),
|
vfs.commit_changes().as_slice(),
|
||||||
[VfsChange::AddFile { text, path, .. }],
|
[VfsChange::AddFile { text, path, .. }],
|
||||||
{
|
{
|
||||||
assert_eq!(text.as_str(), "new hello");
|
assert_eq!(text.as_str(), "new hello");
|
||||||
assert_eq!(path, "c/new.rs");
|
assert_eq!(path, "sub1/sub2/new.rs");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::rename(
|
fs::rename(
|
||||||
&dir.path().join("a/c/new.rs"),
|
&dir.path().join("a/sub1/sub2/new.rs"),
|
||||||
&dir.path().join("a/c/new1.rs"),
|
&dir.path().join("a/sub1/sub2/new1.rs"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
process_tasks(&mut vfs, 4);
|
process_tasks(&mut vfs, 4);
|
||||||
|
@ -142,18 +143,18 @@ fn test_vfs_works() -> std::io::Result<()> {
|
||||||
..
|
..
|
||||||
}],
|
}],
|
||||||
{
|
{
|
||||||
assert_eq!(removed_path, "c/new.rs");
|
assert_eq!(removed_path, "sub1/sub2/new.rs");
|
||||||
assert_eq!(added_path, "c/new1.rs");
|
assert_eq!(added_path, "sub1/sub2/new1.rs");
|
||||||
assert_eq!(text.as_str(), "new hello");
|
assert_eq!(text.as_str(), "new hello");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::remove_file(&dir.path().join("a/c/new1.rs")).unwrap();
|
fs::remove_file(&dir.path().join("a/sub1/sub2/new1.rs")).unwrap();
|
||||||
process_tasks(&mut vfs, 2);
|
process_tasks(&mut vfs, 2);
|
||||||
assert_match!(
|
assert_match!(
|
||||||
vfs.commit_changes().as_slice(),
|
vfs.commit_changes().as_slice(),
|
||||||
[VfsChange::RemoveFile { path, .. }],
|
[VfsChange::RemoveFile { path, .. }],
|
||||||
assert_eq!(path, "c/new1.rs")
|
assert_eq!(path, "sub1/sub2/new1.rs")
|
||||||
);
|
);
|
||||||
|
|
||||||
fs::create_dir_all(dir.path().join("a/target")).unwrap();
|
fs::create_dir_all(dir.path().join("a/target")).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue