mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(cli-rs): reserve no row for a slot claim before its first tree
A TypeScript plugin's slot claim showed a one-row placeholder until the JS host sent its first tree. A claim that draws nothing, such as the anomaly.internal plugin's app claims that only add key bindings, so lifted the session column a row per claim for a few frames as the plugin loaded, then dropped it back. TS draws a slot's claim in the frame that mounts it, so a slot mount whose key has shown nothing now reserves nothing; transcript parts keep their one row. A hidden root also reports no rows as the height its key had, so a remount does not reserve the rows of the placeholder it replaced.
This commit is contained in:
@@ -1373,7 +1373,7 @@ impl surface::Viewer for Viewer {
|
||||
let mut mounts = self.mounts.borrow_mut();
|
||||
let mount = mounts.get_mut(id)?;
|
||||
mount.shown = true;
|
||||
let height = self.heights.borrow().get(&id.key).copied().unwrap_or(1);
|
||||
let height = self.heights.borrow().get(&id.key).copied().unwrap_or(0);
|
||||
return Some(Viewed { node: Some(placeholder(height)), memo: Some(0), stand_in: true });
|
||||
}
|
||||
// The height it was laid out at, not the input's, which stands in the screen's before a solve (review carbon-7).
|
||||
@@ -1451,7 +1451,7 @@ impl surface::Viewer for Viewer {
|
||||
}
|
||||
if !mount.shown {
|
||||
mount.shown = true;
|
||||
let height = self.heights.borrow().get(&id.key).copied().unwrap_or(1);
|
||||
let height = self.heights.borrow().get(&id.key).copied().unwrap_or(u16::from(viewing.input.slot.is_none()));
|
||||
let _ = host;
|
||||
return Some(Viewed { node: Some(placeholder(height)), memo: Some(0), stand_in: true });
|
||||
}
|
||||
@@ -1731,7 +1731,9 @@ fn digest(part: &opencode_plugin_abi::claim::Part) -> u64 {
|
||||
hashing.0.finish()
|
||||
}
|
||||
|
||||
/// What a mount shows before the JS host's first tree: the rows its key had, or one (review F1).
|
||||
/// What a mount shows before the JS host's first tree: the rows its key had, else one for a transcript part (review F1)
|
||||
/// and none for a slot. TS draws a slot's claim in the frame that mounts it, and a claim that draws nothing there, such
|
||||
/// as one that only adds key bindings, would otherwise push the slot's neighbours by a row until its tree arrives.
|
||||
fn placeholder(height: u16) -> v2::Node {
|
||||
let layout = opencode_plugin_abi::Layout {
|
||||
height: Some(opencode_plugin_abi::Width::Cells(height)),
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//! plugin, as on the other carriers.
|
||||
//! - **Trees** are revisions of a mount ([`proto::Revision`]): a generation (the mount's), a base, a new revision and a
|
||||
//! layout epoch. A mount has at most one tree in flight: the host adopts or refuses it, says so, and the JS host
|
||||
//! sends the next. A surface shows a whole adopted revision, a placeholder that keeps the room its key had, or the
|
||||
//! fallback; never part of one.
|
||||
//! sends the next. A surface shows a whole adopted revision, a placeholder that keeps the room its key had (none for
|
||||
//! a slot's first mount), or the fallback; never part of one.
|
||||
//! - **Reads** are snapshots the host pushes for what the plugin watches, before the event that may read them.
|
||||
//! - **Hold:** a command that declares it holds the keys typed after it until its handler returned, or 50 ms.
|
||||
//! - **Supervision** ([`child`]): bounded queues, a hang rule on acknowledgements, a memory budget, cleanup of the
|
||||
|
||||
@@ -1055,7 +1055,8 @@ impl Surface {
|
||||
release: &mut release,
|
||||
kept: &kept,
|
||||
held: 0,
|
||||
laid: self.laid.get().then(|| self.root.rect().height as u16),
|
||||
// A hidden root takes no rows; its rect keeps the height of the last solve that showed it.
|
||||
laid: self.laid.get().then(|| if self.root.is_visible() { self.root.rect().height as u16 } else { 0 }),
|
||||
};
|
||||
let viewed = self.viewer.view(host, viewing);
|
||||
*self.viewed.borrow_mut() = input;
|
||||
|
||||
@@ -276,6 +276,54 @@ fn a_batch_of_a_closed_mount_moves_nothing_where_the_activations_would() {
|
||||
assert_eq!(focus("pf.new").as_deref(), Some("same"), "the new mount's own focus did not apply");
|
||||
}
|
||||
|
||||
// Expected (open-jump): a slot claim that draws nothing, here one that only adds a key binding as the `anomaly.internal`
|
||||
// plugin's `app` claim does, moves no row while the JS host loads it, on Home and on a session: TS draws it in the
|
||||
// frame that mounts it. The placeholder of a slot mount whose key had shown nothing took a row until the first tree
|
||||
// came, which lifted the prompt and its footer a row for each such claim for some frames, then dropped them back.
|
||||
#[test]
|
||||
fn a_slot_claim_that_draws_nothing_moves_no_row_while_it_loads() {
|
||||
let Some(config) = config() else { return };
|
||||
let footer = |screen: &str| screen.lines().position(|line| line.contains("ctrl+p commands"));
|
||||
for route in [Route::Home, support::session_route("ses_a")] {
|
||||
let root = opencode_util::temp::tempdir().unwrap();
|
||||
let plugin = root.path().join("config/plugins/keys");
|
||||
std::fs::create_dir_all(&plugin).unwrap();
|
||||
std::fs::write(plugin.join("tui.ts"), KEYS).unwrap();
|
||||
let server = support::Fake::new(|seen| support::base(seen, support::DIRECTORY));
|
||||
let deps = Deps { route: route.clone(), ..support::deps(Arc::new(server)) };
|
||||
let harness = support::mount(80, 24, deps);
|
||||
let settled = footer(&harness.wait_for("ctrl+p commands"));
|
||||
let external =
|
||||
External { config_dir: root.path().join("config"), cwd: root.path().to_path_buf(), dev: Vec::new() };
|
||||
external_with(&harness.tui, external, Some(config.clone()));
|
||||
let pipe = Pipe { harness, root };
|
||||
let (app, tui) = (&pipe.harness.app, &pipe.harness.tui);
|
||||
pipe.active("example.keys");
|
||||
let frames = std::cell::RefCell::new(Vec::new());
|
||||
let registered = || tui.keymap.commands().iter().any(|command| command.id == "keys.toggle");
|
||||
pipe.harness.wait("the claim drew", || {
|
||||
app.advance(Duration::from_millis(1));
|
||||
frames.borrow_mut().push(app.text());
|
||||
registered() && pipe.scripts().idle()
|
||||
});
|
||||
pipe.settle();
|
||||
frames.borrow_mut().push(app.text());
|
||||
for frame in frames.borrow().iter() {
|
||||
assert_eq!(footer(frame), settled, "{route:?}: a frame moved the prompt's footer:\n{frame}");
|
||||
assert!(!frame.lines().any(|line| line.trim() == "…"), "{route:?}: a placeholder row showed:\n{frame}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The probe of the open-jump row: an `app` slot claim that draws nothing and adds the command `keys.toggle`.
|
||||
const KEYS: &str = r#"export default { id: "example.keys", setup(api) {
|
||||
api.ui.slot({ append: "app", render: () => {
|
||||
api.keymap.layer(() => ({ commands: [{ id: "keys.toggle", title: "Toggle keys", run() {} }] }))
|
||||
return null
|
||||
} })
|
||||
} }
|
||||
"#;
|
||||
|
||||
/// The TUI with the raw carrier plugin `example.<name>` of `source`, active.
|
||||
fn raw(config: Config, name: &str, source: &str) -> Pipe {
|
||||
let root = opencode_util::temp::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user