M1.13: watch open buffers' folders, bufferFocused, truncated tree row
- The parent directory of every open buffer is pinned in the project
watcher (workspace::sync_buffer_dirs after every command): it counts
against the cap but is never evicted while a buffer in it is open, so
reloads and fileChangedOnDisk arrive for never-expanded folders.
- file.open on an already-open buffer emits the new bufferFocused {id};
the editor activates that tab and it outranks pending adoptions.
- The project tree shows a "Listing truncated" note row
(project.tree.truncated) after a partly listed directory.
- Tests: engine (pinning, eviction, focus), control channel
(bufferFocused), Vitest (tab switch, race, truncated row).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7b7273a947
commit
8a71f7bd08
19 changed files with 312 additions and 30 deletions
|
|
@ -403,6 +403,92 @@ fn watched_directories_are_capped_least_recently_listed_first() {
|
|||
assert!(watched.iter().any(|d| d == Path::new("d0006")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_in_never_listed_folders_report_changes_on_disk() {
|
||||
let (dir, mut engine, _) =
|
||||
open_project(&[("src/deep/clean.php", b"one"), ("lib/dirty.php", b"one")]);
|
||||
let (clean, _) = open_file(&mut engine, "src/deep/clean.php");
|
||||
let (dirty, _) = open_file(&mut engine, "lib/dirty.php");
|
||||
let workspace = engine.state().project.as_ref().unwrap();
|
||||
assert_eq!(
|
||||
workspace.pinned_dirs(),
|
||||
vec![
|
||||
Path::new("lib").to_path_buf(),
|
||||
Path::new("src/deep").to_path_buf()
|
||||
]
|
||||
);
|
||||
run(
|
||||
&mut engine,
|
||||
"buffer.edit",
|
||||
json!({"id": dirty, "baseVersion": 1, "edits": [{"from": 0, "to": 0, "insert": "mine "}]}),
|
||||
);
|
||||
fs::write(dir.path().join("src/deep/clean.php"), "two, longer").unwrap();
|
||||
fs::write(dir.path().join("lib/dirty.php"), "theirs, longer").unwrap();
|
||||
let mut events = wait_for(
|
||||
&mut engine,
|
||||
|e| matches!(e, Event::BufferChanged { id, .. } if *id == clean),
|
||||
);
|
||||
if !events
|
||||
.iter()
|
||||
.any(|e| matches!(e, Event::FileChangedOnDisk { id, .. } if *id == dirty))
|
||||
{
|
||||
events = wait_for(
|
||||
&mut engine,
|
||||
|e| matches!(e, Event::FileChangedOnDisk { id, .. } if *id == dirty),
|
||||
);
|
||||
}
|
||||
assert!(!events.is_empty());
|
||||
assert_eq!(
|
||||
run(&mut engine, "buffer.get", json!({"id": clean})).value["text"],
|
||||
"two, longer"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parent_dirs_of_open_buffers_are_never_evicted_and_age_out_after_close() {
|
||||
let (dir, mut engine, _) = open_project(&[("pinned/a.php", b"a")]);
|
||||
let limit = engine.state().project.as_ref().unwrap().watch_limit();
|
||||
assert!(limit > 0, "the watcher should start on a temp dir");
|
||||
let (id, _) = open_file(&mut engine, "pinned/a.php");
|
||||
let count = limit + 5;
|
||||
for n in 0..count {
|
||||
fs::create_dir(dir.path().join(format!("d{n:04}"))).unwrap();
|
||||
run(
|
||||
&mut engine,
|
||||
"project.children",
|
||||
json!({"dir": format!("d{n:04}")}),
|
||||
);
|
||||
}
|
||||
let watched = engine.state().project.as_ref().unwrap().watched_dirs();
|
||||
assert_eq!(watched.len(), limit);
|
||||
assert!(watched.iter().any(|d| d == Path::new("pinned")));
|
||||
assert!(!watched.iter().any(|d| d == Path::new("d0000")));
|
||||
|
||||
run(&mut engine, "buffer.close", json!({"id": id}));
|
||||
let workspace = engine.state().project.as_ref().unwrap();
|
||||
assert!(workspace.pinned_dirs().is_empty());
|
||||
run(&mut engine, "project.children", json!({"dir": "d0000"}));
|
||||
let watched = engine.state().project.as_ref().unwrap().watched_dirs();
|
||||
assert_eq!(watched.len(), limit);
|
||||
assert!(!watched.iter().any(|d| d == Path::new("pinned")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_an_open_file_again_focuses_its_buffer() {
|
||||
let (_dir, mut engine, _) = open_project(&[("a.php", b"a"), ("src/b.php", b"b")]);
|
||||
let first = run(&mut engine, "file.open", json!({"path": "src/b.php"}));
|
||||
let id = first.value["id"].as_u64().unwrap();
|
||||
assert!(first.events.contains(&Event::BufferOpened {
|
||||
id,
|
||||
path: "src/b.php".into()
|
||||
}));
|
||||
open_file(&mut engine, "a.php");
|
||||
let again = run(&mut engine, "file.open", json!({"path": "src/b.php"}));
|
||||
assert_eq!(again.value["id"], id);
|
||||
assert_eq!(again.events, vec![Event::BufferFocused { id }]);
|
||||
assert_eq!(engine.state().buffers.len(), 2);
|
||||
}
|
||||
|
||||
/// A command that reads the state and then panics on an index.
|
||||
struct PanicsMidway;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue