diff options
Diffstat (limited to 'azalea-brigadier/src')
| -rwxr-xr-x | azalea-brigadier/src/lib.rs | 1 | ||||
| -rw-r--r-- | azalea-brigadier/src/suggestion/mod.rs | 1 | ||||
| -rw-r--r-- | azalea-brigadier/src/suggestion/suggestions.rs | 21 |
3 files changed, 18 insertions, 5 deletions
diff --git a/azalea-brigadier/src/lib.rs b/azalea-brigadier/src/lib.rs index a294eb19..c2ac7e14 100755 --- a/azalea-brigadier/src/lib.rs +++ b/azalea-brigadier/src/lib.rs @@ -8,3 +8,4 @@ pub mod modifier; pub mod parse_results; pub mod string_reader; pub mod tree; +pub mod suggestion; diff --git a/azalea-brigadier/src/suggestion/mod.rs b/azalea-brigadier/src/suggestion/mod.rs index ab3a5964..4c9a9547 100644 --- a/azalea-brigadier/src/suggestion/mod.rs +++ b/azalea-brigadier/src/suggestion/mod.rs @@ -1,6 +1,7 @@ mod suggestions; use crate::{context::StringRange, message::Message}; +pub use suggestions::*; #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Suggestion { diff --git a/azalea-brigadier/src/suggestion/suggestions.rs b/azalea-brigadier/src/suggestion/suggestions.rs index 6c325039..1fe361f1 100644 --- a/azalea-brigadier/src/suggestion/suggestions.rs +++ b/azalea-brigadier/src/suggestion/suggestions.rs @@ -13,18 +13,18 @@ impl Suggestions { if input.is_empty() { return Suggestions::default(); } else if input.len() == 1 { - return input[0]; + return input[0].clone(); }; - let texts = HashSet::new(); + let mut texts = HashSet::new(); for suggestions in input { - texts.extend(suggestions.suggestions); + texts.extend(suggestions.suggestions.clone()); } - Suggestions::create(command, texts) + Suggestions::create(command, &texts) } - pub fn create(command: &str, suggestions: &[Suggestions]) { + pub fn create(command: &str, suggestions: &HashSet<Suggestion>) -> Self { if suggestions.is_empty() { return Suggestions::default(); }; @@ -34,5 +34,16 @@ impl Suggestions { start = suggestion.range.start().min(start); end = suggestion.range.end().max(end); } + let range = StringRange::new(start, end); + let mut texts = HashSet::new(); + for suggestion in suggestions { + texts.insert(suggestion.expand(command, &range)); + } + let mut sorted: Vec<Suggestion> = texts.into_iter().collect(); + sorted.sort_by(|a, b| a.text.cmp(&b.text)); + Suggestions { + range, + suggestions: sorted, + } } } |
