mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 06:20:09 +01:00
feat: all typo candidates for executables
This commit is contained in:
parent
0a799db5e5
commit
bf16675d4e
9 changed files with 173 additions and 19 deletions
|
|
@ -188,6 +188,7 @@ fn eval_suggest(suggest: &str) -> TokenStream2 {
|
|||
}
|
||||
|
||||
let mut replace_list = Vec::new();
|
||||
let mut exes_list = Vec::new();
|
||||
let mut opt_list = Vec::new();
|
||||
let mut cmd_list = Vec::new();
|
||||
|
||||
|
|
@ -197,10 +198,26 @@ fn eval_suggest(suggest: &str) -> TokenStream2 {
|
|||
replaces::command(&mut suggest, &mut replace_list);
|
||||
replaces::shell(&mut suggest, &mut cmd_list);
|
||||
replaces::typo(&mut suggest, &mut replace_list);
|
||||
replaces::exes(&mut suggest, &mut exes_list);
|
||||
replaces::shell_tag(&mut suggest, &mut replace_list, &cmd_list);
|
||||
|
||||
let suggests = if exes_list.is_empty() {
|
||||
quote! {
|
||||
candidates.push(format!{#suggest, #(#replace_list),*});
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#(#exes_list)*
|
||||
let suggest = format!{#suggest, #(#replace_list),*};
|
||||
for match_ in exes_matches {
|
||||
let suggest = suggest.replace("{{exes}}", &match_);
|
||||
candidates.push(suggest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
#(#opt_list)*
|
||||
candidates.push(format!{#suggest, #(#replace_list),*});
|
||||
#suggests
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,50 @@ pub fn typo(suggest: &mut String, replace_list: &mut Vec<TokenStream2>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn exes(suggest: &mut String, exes_list: &mut Vec<TokenStream2>) {
|
||||
if suggest.contains("{{exes") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{exes", "}}");
|
||||
|
||||
let index = if suggest.contains('[') {
|
||||
let split = suggest[args.to_owned()]
|
||||
.split(&['[', ']'])
|
||||
.collect::<Vec<&str>>();
|
||||
let command_index = split[1];
|
||||
if !command_index.contains(':') {
|
||||
let command_index = command_index.parse::<i32>().unwrap();
|
||||
|
||||
if command_index < 0 {
|
||||
quote! {split.len() as usize + #command_index}
|
||||
} else {
|
||||
quote! {#command_index as usize}
|
||||
}
|
||||
} else {
|
||||
unreachable!("Exes suggestion does not support range");
|
||||
|
||||
}
|
||||
} else {
|
||||
unreachable!("Exes suggestion must have a command index");
|
||||
};
|
||||
|
||||
let command = quote! {
|
||||
let exes_matches = {
|
||||
let split = split_command(&last_command);
|
||||
let res = best_matches_path(&split[#index], executables);
|
||||
if res.is_none() {
|
||||
vec![split[#index].clone()]
|
||||
} else {
|
||||
res.unwrap()
|
||||
}
|
||||
};
|
||||
};
|
||||
exes_list.push(command);
|
||||
|
||||
let tag = "{{{{exes}}}}";
|
||||
let placeholder = suggest[placeholder.clone()].to_owned();
|
||||
*suggest = suggest.replace(&placeholder, &tag);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shell(suggest: &mut String, cmd_list: &mut Vec<String>) {
|
||||
while suggest.contains("{{shell") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{shell", "}}");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue