Custom prompt args (numeric) (#4470)

[Cherry picked from /pull/3565]

Adds $1, $2, $3, $ARGUMENTS param parsing for custom prompts.
This commit is contained in:
dedrisian-oai
2025-09-29 16:14:37 -07:00
committed by GitHub
parent c81baaabda
commit 80ccec6530
5 changed files with 421 additions and 39 deletions

View File

@@ -53,12 +53,8 @@ impl CommandPopup {
self.prompts = prompts;
}
pub(crate) fn prompt_name(&self, idx: usize) -> Option<&str> {
self.prompts.get(idx).map(|p| p.name.as_str())
}
pub(crate) fn prompt_content(&self, idx: usize) -> Option<&str> {
self.prompts.get(idx).map(|p| p.content.as_str())
pub(crate) fn prompt(&self, idx: usize) -> Option<&CustomPrompt> {
self.prompts.get(idx)
}
/// Update the filter string based on the current composer text. The text
@@ -218,7 +214,6 @@ impl WidgetRef for CommandPopup {
#[cfg(test)]
mod tests {
use super::*;
use std::string::ToString;
#[test]
fn filter_includes_init_when_typing_prefix() {
@@ -292,7 +287,7 @@ mod tests {
let mut prompt_names: Vec<String> = items
.into_iter()
.filter_map(|it| match it {
CommandItem::UserPrompt(i) => popup.prompt_name(i).map(ToString::to_string),
CommandItem::UserPrompt(i) => popup.prompt(i).map(|p| p.name.clone()),
_ => None,
})
.collect();
@@ -312,7 +307,7 @@ mod tests {
}]);
let items = popup.filtered_items();
let has_collision_prompt = items.into_iter().any(|it| match it {
CommandItem::UserPrompt(i) => popup.prompt_name(i) == Some("init"),
CommandItem::UserPrompt(i) => popup.prompt(i).is_some_and(|p| p.name == "init"),
_ => false,
});
assert!(