Add auto_cd in eval_external.rs, expand test case for cd to auto_cd, resolve rollback 1.0 conflict

This commit is contained in:
Zhenping Zhao 2024-12-20 16:16:16 -08:00
parent e623224abf
commit 1e6df57ba6
3 changed files with 8 additions and 26 deletions

View file

@ -176,6 +176,7 @@ pub fn complete_item(
) -> Vec<FileSuggestion> { ) -> Vec<FileSuggestion> {
let cleaned_partial = surround_remove(partial); let cleaned_partial = surround_remove(partial);
let isdir = cleaned_partial.ends_with(is_separator); let isdir = cleaned_partial.ends_with(is_separator);
#[cfg(windows)]
let cleaned_partial = let cleaned_partial =
if let Some(absolute_path) = expand_pwd(stack, engine_state, Path::new(&cleaned_partial)) { if let Some(absolute_path) = expand_pwd(stack, engine_state, Path::new(&cleaned_partial)) {
if let Some(abs_path_str) = absolute_path.as_path().to_str() { if let Some(abs_path_str) = absolute_path.as_path().to_str() {

View file

@ -356,6 +356,10 @@ fn filesystem_from_non_root_change_to_another_drive_non_root_then_using_relative
assert!(dirs.test.join("test_folder").exists()); assert!(dirs.test.join("test_folder").exists());
assert!(_actual.out.ends_with(r"\cd_test_22")); assert!(_actual.out.ends_with(r"\cd_test_22"));
assert!(_actual.err.is_empty()); assert!(_actual.err.is_empty());
assert!(dirs.test.join("test_folder").join("test_file_on_x.txt").exists()); assert!(dirs
.test
.join("test_folder")
.join("test_file_on_x.txt")
.exists());
}) })
} }

View file

@ -1,6 +1,6 @@
use std::{borrow::Cow, fs::File, sync::Arc}; use std::{borrow::Cow, fs::File, sync::Arc};
use nu_path::{expand_path_with, AbsolutePathBuf}; use nu_path::AbsolutePathBuf;
use nu_protocol::{ use nu_protocol::{
ast::{Bits, Block, Boolean, CellPath, Comparison, Math, Operator}, ast::{Bits, Block, Boolean, CellPath, Comparison, Math, Operator},
debugger::DebugContext, debugger::DebugContext,
@ -15,7 +15,7 @@ use nu_protocol::{
}; };
use nu_utils::IgnoreCaseExt; use nu_utils::IgnoreCaseExt;
use crate::{eval::is_automatic_env_var, eval_block_with_early_return}; use crate::{eval::is_automatic_env_var, eval_block_with_early_return, redirect_env};
/// Evaluate the compiled representation of a [`Block`]. /// Evaluate the compiled representation of a [`Block`].
pub fn eval_ir_block<D: DebugContext>( pub fn eval_ir_block<D: DebugContext>(
@ -1489,26 +1489,3 @@ fn eval_iterate(
eval_iterate(ctx, dst, stream, end_index) eval_iterate(ctx, dst, stream, end_index)
} }
} }
/// Redirect environment from the callee stack to the caller stack
fn redirect_env(engine_state: &EngineState, caller_stack: &mut Stack, callee_stack: &Stack) {
// TODO: make this more efficient
// Grab all environment variables from the callee
let caller_env_vars = caller_stack.get_env_var_names(engine_state);
// remove env vars that are present in the caller but not in the callee
// (the callee hid them)
for var in caller_env_vars.iter() {
if !callee_stack.has_env_var(engine_state, var) {
caller_stack.remove_env_var(engine_state, var);
}
}
// add new env vars from callee to caller
for (var, value) in callee_stack.get_stack_env_vars() {
caller_stack.add_env_var(var, value);
}
// set config to callee config, to capture any updates to that
caller_stack.config.clone_from(&callee_stack.config);
}