forked from extern/nushell
parent
7f771babb7
commit
d08e254d16
@ -143,18 +143,24 @@ impl NuCompleter {
|
|||||||
let current_span = working_set.get_span_contents(flat.0).to_vec();
|
let current_span = working_set.get_span_contents(flat.0).to_vec();
|
||||||
let current_span_str = String::from_utf8_lossy(¤t_span);
|
let current_span_str = String::from_utf8_lossy(¤t_span);
|
||||||
|
|
||||||
|
let is_last_span = pos >= flat.0.start && pos < flat.0.end;
|
||||||
|
|
||||||
// Skip the last 'a' as span item
|
// Skip the last 'a' as span item
|
||||||
if flat_idx == flattened.len() - 1 {
|
if is_last_span {
|
||||||
let mut chars = current_span_str.chars();
|
let offset = pos - flat.0.start;
|
||||||
chars.next_back();
|
if offset == 0 {
|
||||||
let current_span_str = chars.as_str().to_owned();
|
spans.push(String::new())
|
||||||
spans.push(current_span_str.to_string());
|
} else {
|
||||||
|
let mut current_span_str = current_span_str.to_string();
|
||||||
|
current_span_str.remove(offset);
|
||||||
|
spans.push(current_span_str);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
spans.push(current_span_str.to_string());
|
spans.push(current_span_str.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete based on the last span
|
// Complete based on the last span
|
||||||
if pos >= flat.0.start && pos < flat.0.end {
|
if is_last_span {
|
||||||
// Context variables
|
// Context variables
|
||||||
let most_left_var =
|
let most_left_var =
|
||||||
most_left_variable(flat_idx, &working_set, flattened.clone());
|
most_left_variable(flat_idx, &working_set, flattened.clone());
|
||||||
|
@ -59,6 +59,29 @@ fn extern_completer() -> NuCompleter {
|
|||||||
NuCompleter::new(std::sync::Arc::new(engine), stack)
|
NuCompleter::new(std::sync::Arc::new(engine), stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fixture]
|
||||||
|
fn custom_completer() -> NuCompleter {
|
||||||
|
// Create a new engine
|
||||||
|
let (dir, _, mut engine, mut stack) = new_engine();
|
||||||
|
|
||||||
|
// Add record value as example
|
||||||
|
let record = r#"
|
||||||
|
let external_completer = {|spans|
|
||||||
|
$spans
|
||||||
|
}
|
||||||
|
|
||||||
|
$env.config.completions.external = {
|
||||||
|
enable: true
|
||||||
|
max_results: 100
|
||||||
|
completer: $external_completer
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
assert!(support::merge_input(record.as_bytes(), &mut engine, &mut stack, dir).is_ok());
|
||||||
|
|
||||||
|
// Instantiate a new completer
|
||||||
|
NuCompleter::new(std::sync::Arc::new(engine), stack)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn variables_dollar_sign_with_varialblecompletion() {
|
fn variables_dollar_sign_with_varialblecompletion() {
|
||||||
let (_, _, engine, stack) = new_engine();
|
let (_, _, engine, stack) = new_engine();
|
||||||
@ -938,6 +961,34 @@ fn extern_complete_flags(mut extern_completer: NuCompleter) {
|
|||||||
match_suggestions(expected, suggestions);
|
match_suggestions(expected, suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
|
||||||
|
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
||||||
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
||||||
|
match_suggestions(expected, suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {
|
||||||
|
let suggestions = custom_completer.complete("cmd foo bar", 8);
|
||||||
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "".into()];
|
||||||
|
match_suggestions(expected, suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn custom_completer_triggers_cursor_next_to_word(mut custom_completer: NuCompleter) {
|
||||||
|
let suggestions = custom_completer.complete("cmd foo bar", 11);
|
||||||
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into()];
|
||||||
|
match_suggestions(expected, suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn custom_completer_triggers_cursor_after_word(mut custom_completer: NuCompleter) {
|
||||||
|
let suggestions = custom_completer.complete("cmd foo bar ", 12);
|
||||||
|
let expected: Vec<String> = vec!["cmd".into(), "foo".into(), "bar".into(), "".into()];
|
||||||
|
match_suggestions(expected, suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
#[ignore = "was reverted, still needs fixing"]
|
#[ignore = "was reverted, still needs fixing"]
|
||||||
#[rstest]
|
#[rstest]
|
||||||
fn alias_offset_bug_7648() {
|
fn alias_offset_bug_7648() {
|
||||||
|
Loading…
Reference in New Issue
Block a user