Skip to content

Commit

Permalink
Handle && and ; in the completions
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Sep 12, 2024
1 parent 7501d47 commit 5a94080
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/zsh_autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ fn get_completion_items<'a>(
runners: &'a Vec<Box<dyn Runner>>,
lbuffer: &str,
) -> CompletionItems<'a> {
let lbuffer = lbuffer.split("&&").last().unwrap_or(lbuffer).trim();
let lbuffer = lbuffer.split(";").last().unwrap_or(lbuffer).trim();

let arg_count = lbuffer.split_whitespace().count();

// rt build<space><tab> aka 'rt build '
Expand Down Expand Up @@ -155,4 +158,50 @@ mod tests {
]
);
}

#[test]
fn test_combined_with_other_commands() {
let runner1 = Box::new(TestRunner::new(
"runner1".to_string(),
vec!["foo".to_string(), "bar".to_string()],
));

let runners: Vec<Box<dyn Runner>> = vec![runner1];

let result = get_completion_items(&runners, "ls && rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);

let result = get_completion_items(&runners, "ls && ls && rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);

let result = get_completion_items(&runners, "ls&&rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);

let result = get_completion_items(&runners, "ls;rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);

let result = get_completion_items(&runners, "ls; rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);

let result = get_completion_items(&runners, "ls ; rt fo");
let CompletionItems::Tasks(tasks) = result else {
panic!("Expected CompletionItems::Tasks");
};
assert_eq!(tasks.len(), 2);
}
}

0 comments on commit 5a94080

Please sign in to comment.