forked from 1b-agent/opencadstudio-upstream
feat(commandline): autocomplete suggestions + inventory-based registry
Type-as-you-go suggestion popup above the input that filters known command names by substring (so `LEADER` surfaces both LEADER and MLEADER). Up / Down navigates the list, Enter dispatches the highlighted entry, clicking a row dispatches directly. Esc on a non-empty input clears the buffer instead of escalating to command-cancel. The name corpus comes from `inventory::submit!` blocks placed next to each `CadCommand` impl rather than a hand-maintained static list. Adding a new interactive command means dropping one `inventory::submit!` line in its own module file — the autocomplete picks it up at the next compile. 98 submissions seeded across 60 module files; `command::all_registered_command_names()` flattens them at runtime. One-shot dispatch arms in `app/commands.rs` (NEW, OPEN, SAVE, UNDO, …) don't have a `CadCommand` impl and are therefore absent from autocomplete by design. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
4124cb2689
commit
05ea31aa2a
67 files changed
+507
-2
No files matched your search
@@ -317,3 +317,29 @@ pub trait CadCommand: Send {
|
||||
/// Default: no-op.
|
||||
fn inject_picked_entity(&mut self, _entity: acadrust::EntityType) {}
|
||||
}
|
||||
|
||||
// ── Autocomplete registry ─────────────────────────────────────────────────
|
||||
//
|
||||
// Every `impl CadCommand for Foo` module submits the names it answers to
|
||||
// at compile time via `inventory::submit!`. The command-line autocomplete
|
||||
// then iterates the resulting collection at runtime — no central list to
|
||||
// keep in sync.
|
||||
//
|
||||
// Non-interactive one-shot dispatch arms (NEW, OPEN, SAVE, …) live in
|
||||
// `app/commands.rs` and don't have a `CadCommand` impl; they're absent
|
||||
// from autocomplete by design. Add an explicit `inventory::submit!` next
|
||||
// to their dispatch arm if you want them surfaced.
|
||||
|
||||
pub struct CommandRegistration {
|
||||
pub names: &'static [&'static str],
|
||||
}
|
||||
|
||||
inventory::collect!(CommandRegistration);
|
||||
|
||||
/// All registered command names, including aliases.
|
||||
pub fn all_registered_command_names() -> Vec<&'static str> {
|
||||
inventory::iter::<CommandRegistration>
|
||||
.into_iter()
|
||||
.flat_map(|r| r.names.iter().copied())
|
||||
.collect()
|
||||
}
|
||||
Reference in new issue
Block a user