Don't resuggest accepted completions (#5369)

To avoid resuggesting the same completion, add a space after commands or flags that have been accepted via `Enter`. Don't do that for filepaths or external completions

* Add append_whitespace choice for suggestion

Signed-off-by: gipsyh <gipsyh.icu@gmail.com>

* Fixed `test <path>` appending space.

* Update reedline

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Yuheng Su 2022-05-02 17:35:37 +08:00 committed by GitHub
parent 1ca3063ac3
commit bb27b9f371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 1 deletions

2
Cargo.lock generated
View File

@ -3716,7 +3716,7 @@ dependencies = [
[[package]]
name = "reedline"
version = "0.4.0"
source = "git+https://github.com/nushell/reedline?branch=main#2947a94fefac63e8fba2076327bae373f8d09b9d"
source = "git+https://github.com/nushell/reedline?branch=main#29f30a8f7926ad5cded3be564b6c26679c10e1c5"
dependencies = [
"chrono",
"crossterm",

View File

@ -98,6 +98,7 @@ impl CommandCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: true,
});
let results_aliases = working_set
@ -111,6 +112,7 @@ impl CommandCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: true,
});
let mut results = results.chain(results_aliases).collect::<Vec<_>>();
@ -129,6 +131,7 @@ impl CommandCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: true,
});
for external in results_external {
@ -138,6 +141,7 @@ impl CommandCompletion {
description: None,
extra: None,
span: external.span,
append_whitespace: true,
})
} else {
results.push(external)
@ -267,6 +271,7 @@ impl Completer for CommandCompletion {
start: x.0.start - offset,
end: x.0.end - offset,
},
append_whitespace: false,
})
.chain(subcommands.into_iter())
.chain(commands.into_iter())

View File

@ -44,6 +44,7 @@ impl CustomCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: false,
});
}
@ -57,6 +58,7 @@ impl CustomCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: false,
};
// Iterate the cols looking for `value` and `description`

View File

@ -53,6 +53,7 @@ impl Completer for DirectoryCompletion {
start: x.0.start - offset,
end: x.0.end - offset,
},
append_whitespace: false,
});
}

View File

@ -110,6 +110,7 @@ impl Completer for DotNuCompletion {
start: x.0.start - offset,
end: x.0.end - offset,
},
append_whitespace: true,
})
})
.collect();

View File

@ -49,6 +49,7 @@ impl Completer for FileCompletion {
start: x.0.start - offset,
end: x.0.end - offset,
},
append_whitespace: false,
})
.collect();

View File

@ -51,6 +51,7 @@ impl Completer for FlagCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: true,
});
}
}
@ -72,6 +73,7 @@ impl Completer for FlagCompletion {
start: span.start - offset,
end: span.end - offset,
},
append_whitespace: true,
});
}
}

View File

@ -84,6 +84,7 @@ impl Completer for VariableCompletion {
description: None,
extra: None,
span: current_span,
append_whitespace: false,
});
}
}
@ -137,6 +138,7 @@ impl Completer for VariableCompletion {
description: None,
extra: None,
span: current_span,
append_whitespace: false,
});
}
}
@ -150,6 +152,7 @@ impl Completer for VariableCompletion {
description: None,
extra: None,
span: current_span,
append_whitespace: false,
});
}
}
@ -164,6 +167,7 @@ impl Completer for VariableCompletion {
description: None,
extra: None,
span: current_span,
append_whitespace: false,
});
}
}
@ -198,6 +202,7 @@ fn nested_suggestions(
description: None,
extra: None,
span: current_span,
append_whitespace: false,
});
}

View File

@ -92,6 +92,7 @@ impl NuHelpCompleter {
start: pos,
end: pos + line.len(),
},
append_whitespace: false,
}
})
.collect()

View File

@ -155,6 +155,7 @@ fn convert_to_suggestions(
description,
extra,
span,
append_whitespace: false,
}]
}
Value::List { vals, .. } => vals
@ -169,6 +170,7 @@ fn convert_to_suggestions(
start: 0,
end: line.len(),
},
append_whitespace: false,
}],
}
}