mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 00:30:11 +00:00
fix(commands): don't use possible tokens, directly use branches.keys() since its ordered now
This commit is contained in:
parent
eec9f64026
commit
b477ade3fe
2 changed files with 3 additions and 8 deletions
|
|
@ -21,7 +21,6 @@ lazy_static::lazy_static! {
|
||||||
pub static ref COMMAND_TREE: TreeBranch = {
|
pub static ref COMMAND_TREE: TreeBranch = {
|
||||||
let mut tree = TreeBranch {
|
let mut tree = TreeBranch {
|
||||||
current_command_key: None,
|
current_command_key: None,
|
||||||
possible_tokens: vec![],
|
|
||||||
branches: OrderMap::new(),
|
branches: OrderMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -101,12 +100,13 @@ fn parse_command(input: String) -> CommandResult {
|
||||||
let mut flags: HashMap<String, Option<String>> = HashMap::new();
|
let mut flags: HashMap<String, Option<String>> = HashMap::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("{:?}", local_tree.possible_tokens);
|
println!("possible: {:?}", local_tree.branches.keys());
|
||||||
let next = next_token(
|
let next = next_token(
|
||||||
local_tree.possible_tokens.clone(),
|
local_tree.branches.keys().cloned().collect(),
|
||||||
input.clone(),
|
input.clone(),
|
||||||
current_pos,
|
current_pos,
|
||||||
);
|
);
|
||||||
|
println!("next: {:?}", next);
|
||||||
match next {
|
match next {
|
||||||
Ok((found_token, arg, new_pos)) => {
|
Ok((found_token, arg, new_pos)) => {
|
||||||
current_pos = new_pos;
|
current_pos = new_pos;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ use ordermap::OrderMap;
|
||||||
use smol_str::SmolStr;
|
use smol_str::SmolStr;
|
||||||
|
|
||||||
use crate::{commands::Command, Token};
|
use crate::{commands::Command, Token};
|
||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TreeBranch {
|
pub struct TreeBranch {
|
||||||
pub current_command_key: Option<SmolStr>,
|
pub current_command_key: Option<SmolStr>,
|
||||||
/// branches.keys(), but sorted by specificity
|
|
||||||
pub possible_tokens: Vec<Token>,
|
|
||||||
pub branches: OrderMap<Token, TreeBranch>,
|
pub branches: OrderMap<Token, TreeBranch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -20,7 +17,6 @@ impl TreeBranch {
|
||||||
// recursively get or create a sub-branch for each token
|
// recursively get or create a sub-branch for each token
|
||||||
current_branch = current_branch.branches.entry(token).or_insert(TreeBranch {
|
current_branch = current_branch.branches.entry(token).or_insert(TreeBranch {
|
||||||
current_command_key: None,
|
current_command_key: None,
|
||||||
possible_tokens: vec![],
|
|
||||||
branches: OrderMap::new(),
|
branches: OrderMap::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +25,6 @@ impl TreeBranch {
|
||||||
Token::Empty,
|
Token::Empty,
|
||||||
TreeBranch {
|
TreeBranch {
|
||||||
current_command_key: Some(command.cb),
|
current_command_key: Some(command.cb),
|
||||||
possible_tokens: vec![],
|
|
||||||
branches: OrderMap::new(),
|
branches: OrderMap::new(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue