Sort dotnu completions
This commit is contained in:
parent
1919139836
commit
2d64a4eeb6
|
@ -6,7 +6,7 @@ use nu_protocol::{
|
||||||
use reedline::Suggestion;
|
use reedline::Suggestion;
|
||||||
use std::path::{is_separator, Path, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR};
|
use std::path::{is_separator, Path, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR};
|
||||||
|
|
||||||
use super::SemanticSuggestion;
|
use super::{completion_common::sort_suggestions, SemanticSuggestion, SortBy};
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct DotNuCompletion {}
|
pub struct DotNuCompletion {}
|
||||||
|
@ -131,6 +131,6 @@ impl Completer for DotNuCompletion {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
output
|
sort_suggestions(&prefix_str, output, SortBy::Ascending)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,12 +143,7 @@ fn dotnu_completions() {
|
||||||
// Instantiate a new completer
|
// Instantiate a new completer
|
||||||
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
|
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
|
||||||
|
|
||||||
// Test source completion
|
let expected = vec![
|
||||||
let completion_str = "source-env ".to_string();
|
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
|
||||||
|
|
||||||
match_suggestions(
|
|
||||||
vec![
|
|
||||||
"asdf.nu".into(),
|
"asdf.nu".into(),
|
||||||
"bar.nu".into(),
|
"bar.nu".into(),
|
||||||
"bat.nu".into(),
|
"bat.nu".into(),
|
||||||
|
@ -157,31 +152,25 @@ fn dotnu_completions() {
|
||||||
"foo.nu".into(),
|
"foo.nu".into(),
|
||||||
"spam.nu".into(),
|
"spam.nu".into(),
|
||||||
"xyzzy.nu".into(),
|
"xyzzy.nu".into(),
|
||||||
],
|
];
|
||||||
suggestions,
|
|
||||||
);
|
// Test source completion
|
||||||
|
let completion_str = "source-env ".to_string();
|
||||||
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
|
match_suggestions(expected.clone(), suggestions);
|
||||||
|
|
||||||
// Test use completion
|
// Test use completion
|
||||||
let completion_str = "use ".to_string();
|
let completion_str = "use ".to_string();
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
assert_eq!(2, suggestions.len());
|
match_suggestions(expected.clone(), suggestions);
|
||||||
assert_eq!("custom_completion.nu", suggestions.first().unwrap().value);
|
|
||||||
#[cfg(windows)]
|
|
||||||
assert_eq!("directory_completion\\", suggestions.get(1).unwrap().value);
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
assert_eq!("directory_completion/", suggestions.get(1).unwrap().value);
|
|
||||||
|
|
||||||
// Test overlay use completion
|
// Test overlay use completion
|
||||||
let completion_str = "overlay use ".to_string();
|
let completion_str = "overlay use ".to_string();
|
||||||
let suggestions = completer.complete(&completion_str, completion_str.len());
|
let suggestions = completer.complete(&completion_str, completion_str.len());
|
||||||
|
|
||||||
assert_eq!(2, suggestions.len());
|
match_suggestions(expected, suggestions);
|
||||||
assert_eq!("custom_completion.nu", suggestions.first().unwrap().value);
|
|
||||||
#[cfg(windows)]
|
|
||||||
assert_eq!("directory_completion\\", suggestions.get(1).unwrap().value);
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
assert_eq!("directory_completion/", suggestions.get(1).unwrap().value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user