Fix PWD-aware command hints (#13024)

This PR fixes PWD-aware command hints by sending PWD to the Reedline
state in every REPL loop. This PR should be merged along with
https://github.com/nushell/reedline/pull/796.

Fixes https://github.com/nushell/nushell/issues/12951.
This commit is contained in:
YizhePKU 2024-07-08 00:43:22 +08:00 committed by GitHub
parent 83081f9852
commit 152fb5be39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -336,6 +336,13 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
.with_quick_completions(config.quick_completions)
.with_partial_completions(config.partial_completions)
.with_ansi_colors(config.use_ansi_coloring)
.with_cwd(Some(
engine_state
.cwd(None)
.unwrap_or_default()
.to_string_lossy()
.to_string(),
))
.with_cursor_config(cursor_config);
perf!("reedline builder", start_time, use_color);
@ -666,13 +673,14 @@ fn prepare_history_metadata(
line_editor: &mut Reedline,
) {
if !s.is_empty() && line_editor.has_last_command_context() {
#[allow(deprecated)]
let result = line_editor
.update_last_command_context(&|mut c| {
c.start_timestamp = Some(chrono::Utc::now());
c.hostname = hostname.map(str::to_string);
c.cwd = Some(StateWorkingSet::new(engine_state).get_cwd());
c.cwd = engine_state
.cwd(None)
.ok()
.map(|path| path.to_string_lossy().to_string());
c
})
.into_diagnostic();