From e10538bd8d84b79ceb95f9d6fb2b05a30e4e18e1 Mon Sep 17 00:00:00 2001 From: Bahex <17417311+Bahex@users.noreply.github.com> Date: Sun, 4 May 2025 10:25:55 +0300 Subject: [PATCH] refactor(cell-path): update `Value::follow_cell_path` - remove `insensitive` parameter, case sensitivity is determined by the cell-path itself - update call sites --- .../src/completions/cell_path_completions.rs | 2 +- .../src/extra/strings/format/command.rs | 2 +- crates/nu-command/src/filters/get.rs | 13 +++---- crates/nu-command/src/filters/group_by.rs | 2 +- crates/nu-command/src/filters/insert.rs | 4 +-- crates/nu-command/src/filters/select.rs | 6 ++-- crates/nu-command/src/filters/update.rs | 4 +-- crates/nu-command/src/filters/upsert.rs | 4 +-- crates/nu-command/src/platform/input/list.rs | 2 +- crates/nu-command/src/sort_utils.rs | 4 +-- crates/nu-engine/src/eval.rs | 2 +- crates/nu-engine/src/eval_ir.rs | 4 +-- crates/nu-lsp/src/goto.rs | 2 +- crates/nu-lsp/src/hover.rs | 2 +- .../nu-protocol/src/pipeline/pipeline_data.rs | 7 ++-- crates/nu-protocol/src/value/mod.rs | 34 ++++++++----------- crates/nu_plugin_inc/src/inc.rs | 2 +- 17 files changed, 42 insertions(+), 54 deletions(-) diff --git a/crates/nu-cli/src/completions/cell_path_completions.rs b/crates/nu-cli/src/completions/cell_path_completions.rs index 34376b8ddb..420f0f0bba 100644 --- a/crates/nu-cli/src/completions/cell_path_completions.rs +++ b/crates/nu-cli/src/completions/cell_path_completions.rs @@ -104,7 +104,7 @@ pub(crate) fn eval_cell_path( eval_constant(working_set, head) }?; head_value - .follow_cell_path(path_members, false) + .follow_cell_path(path_members) .map(Cow::into_owned) } diff --git a/crates/nu-cmd-extra/src/extra/strings/format/command.rs b/crates/nu-cmd-extra/src/extra/strings/format/command.rs index 57ca8402f2..905298b547 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/command.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/command.rs @@ -256,7 +256,7 @@ fn format_record( .collect(); let expanded_string = data_as_value - .follow_cell_path(&path_members, false)? + .follow_cell_path(&path_members)? .to_expanded_string(", ", config); output.push_str(expanded_string.as_str()) } diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index d681849448..44148302e7 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -181,7 +181,7 @@ fn action( } if rest.is_empty() { - follow_cell_path_into_stream(input, signals, cell_path.members, span, !sensitive) + follow_cell_path_into_stream(input, signals, cell_path.members, span) } else { let mut output = vec![]; @@ -190,11 +190,7 @@ fn action( let input = input.into_value(span)?; for path in paths { - output.push( - input - .follow_cell_path(&path.members, !sensitive)? - .into_owned(), - ); + output.push(input.follow_cell_path(&path.members)?.into_owned()); } Ok(output.into_iter().into_pipeline_data(span, signals)) @@ -213,7 +209,6 @@ pub fn follow_cell_path_into_stream( signals: Signals, cell_path: Vec, head: Span, - insensitive: bool, ) -> Result { // when given an integer/indexing, we fallback to // the default nushell indexing behaviour @@ -228,7 +223,7 @@ pub fn follow_cell_path_into_stream( let span = value.span(); value - .follow_cell_path(&cell_path, insensitive) + .follow_cell_path(&cell_path) .map(Cow::into_owned) .unwrap_or_else(|error| Value::error(error, span)) }) @@ -238,7 +233,7 @@ pub fn follow_cell_path_into_stream( } _ => data - .follow_cell_path(&cell_path, head, insensitive) + .follow_cell_path(&cell_path, head) .map(|x| x.into_pipeline_data()), } } diff --git a/crates/nu-command/src/filters/group_by.rs b/crates/nu-command/src/filters/group_by.rs index a8da1cedf3..7d732e25f3 100644 --- a/crates/nu-command/src/filters/group_by.rs +++ b/crates/nu-command/src/filters/group_by.rs @@ -322,7 +322,7 @@ fn group_cell_path( let mut groups = IndexMap::<_, Vec<_>>::new(); for value in values.into_iter() { - let key = value.follow_cell_path(&column_name.members, false)?; + let key = value.follow_cell_path(&column_name.members)?; if key.is_nothing() { continue; // likely the result of a failed optional access, ignore this value diff --git a/crates/nu-command/src/filters/insert.rs b/crates/nu-command/src/filters/insert.rs index e2801bf6ee..93d6d9da52 100644 --- a/crates/nu-command/src/filters/insert.rs +++ b/crates/nu-command/src/filters/insert.rs @@ -301,7 +301,7 @@ fn insert_value_by_closure( ) -> Result<(), ShellError> { let value_at_path = if first_path_member_int { value - .follow_cell_path(cell_path, false) + .follow_cell_path(cell_path) .map(Cow::into_owned) .unwrap_or(Value::nothing(span)) } else { @@ -321,7 +321,7 @@ fn insert_single_value_by_closure( ) -> Result<(), ShellError> { let value_at_path = if first_path_member_int { value - .follow_cell_path(cell_path, false) + .follow_cell_path(cell_path) .map(Cow::into_owned) .unwrap_or(Value::nothing(span)) } else { diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 2c10dba856..1baf4081be 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -236,7 +236,7 @@ fn select( if !columns.is_empty() { let mut record = Record::new(); for path in &columns { - match input_val.follow_cell_path(&path.members, false) { + match input_val.follow_cell_path(&path.members) { Ok(fetcher) => { record.push(path.to_column_name(), fetcher.into_owned()); } @@ -259,7 +259,7 @@ fn select( let mut record = Record::new(); for cell_path in columns { - let result = v.follow_cell_path(&cell_path.members, false)?; + let result = v.follow_cell_path(&cell_path.members)?; record.push(cell_path.to_column_name(), result.into_owned()); } @@ -276,7 +276,7 @@ fn select( if !columns.is_empty() { let mut record = Record::new(); for path in &columns { - match x.follow_cell_path(&path.members, false) { + match x.follow_cell_path(&path.members) { Ok(value) => { record.push(path.to_column_name(), value.into_owned()); } diff --git a/crates/nu-command/src/filters/update.rs b/crates/nu-command/src/filters/update.rs index 3fe63ce676..b05c1dcf42 100644 --- a/crates/nu-command/src/filters/update.rs +++ b/crates/nu-command/src/filters/update.rs @@ -243,7 +243,7 @@ fn update_value_by_closure( cell_path: &[PathMember], first_path_member_int: bool, ) -> Result<(), ShellError> { - let value_at_path = value.follow_cell_path(cell_path, false)?; + let value_at_path = value.follow_cell_path(cell_path)?; let arg = if first_path_member_int { value_at_path.as_ref() @@ -266,7 +266,7 @@ fn update_single_value_by_closure( cell_path: &[PathMember], first_path_member_int: bool, ) -> Result<(), ShellError> { - let value_at_path = value.follow_cell_path(cell_path, false)?; + let value_at_path = value.follow_cell_path(cell_path)?; let arg = if first_path_member_int { value_at_path.as_ref() diff --git a/crates/nu-command/src/filters/upsert.rs b/crates/nu-command/src/filters/upsert.rs index 750263f402..d1575596a6 100644 --- a/crates/nu-command/src/filters/upsert.rs +++ b/crates/nu-command/src/filters/upsert.rs @@ -321,7 +321,7 @@ fn upsert_value_by_closure( cell_path: &[PathMember], first_path_member_int: bool, ) -> Result<(), ShellError> { - let value_at_path = value.follow_cell_path(cell_path, false); + let value_at_path = value.follow_cell_path(cell_path); let arg = if first_path_member_int { value_at_path @@ -352,7 +352,7 @@ fn upsert_single_value_by_closure( cell_path: &[PathMember], first_path_member_int: bool, ) -> Result<(), ShellError> { - let value_at_path = value.follow_cell_path(cell_path, false); + let value_at_path = value.follow_cell_path(cell_path); let arg = if first_path_member_int { value_at_path diff --git a/crates/nu-command/src/platform/input/list.rs b/crates/nu-command/src/platform/input/list.rs index df605f4a27..a6cb2fe68e 100644 --- a/crates/nu-command/src/platform/input/list.rs +++ b/crates/nu-command/src/platform/input/list.rs @@ -89,7 +89,7 @@ impl Command for InputList { .into_iter() .map(move |val| { let display_value = if let Some(ref cellpath) = display_path { - val.follow_cell_path(&cellpath.members, false)? + val.follow_cell_path(&cellpath.members)? .to_expanded_string(", ", &config) } else { val.to_expanded_string(", ", &config) diff --git a/crates/nu-command/src/sort_utils.rs b/crates/nu-command/src/sort_utils.rs index 0511e7cddf..9ad90e6eaa 100644 --- a/crates/nu-command/src/sort_utils.rs +++ b/crates/nu-command/src/sort_utils.rs @@ -239,8 +239,8 @@ pub fn compare_cell_path( insensitive: bool, natural: bool, ) -> Result { - let left = left.follow_cell_path(&cell_path.members, false)?; - let right = right.follow_cell_path(&cell_path.members, false)?; + let left = left.follow_cell_path(&cell_path.members)?; + let right = right.follow_cell_path(&cell_path.members)?; compare_values(&left, &right, insensitive, natural) } diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index c39dd0cf30..9b74626a01 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -268,7 +268,7 @@ pub fn eval_expression_with_input( // FIXME: protect this collect with ctrl-c input = eval_subexpression::(engine_state, stack, block, input)? .into_value(*span)? - .follow_cell_path(&full_cell_path.tail, false)? + .follow_cell_path(&full_cell_path.tail)? .into_owned() .into_pipeline_data() } else { diff --git a/crates/nu-engine/src/eval_ir.rs b/crates/nu-engine/src/eval_ir.rs index ffd0938079..01f0eead0a 100644 --- a/crates/nu-engine/src/eval_ir.rs +++ b/crates/nu-engine/src/eval_ir.rs @@ -678,7 +678,7 @@ fn eval_instruction( let data = ctx.take_reg(*src_dst); let path = ctx.take_reg(*path); if let PipelineData::Value(Value::CellPath { val: path, .. }, _) = path { - let value = data.follow_cell_path(&path.members, *span, true)?; + let value = data.follow_cell_path(&path.members, *span)?; ctx.put_reg(*src_dst, value.into_pipeline_data()); Ok(Continue) } else if let PipelineData::Value(Value::Error { error, .. }, _) = path { @@ -694,7 +694,7 @@ fn eval_instruction( let value = ctx.clone_reg_value(*src, *span)?; let path = ctx.take_reg(*path); if let PipelineData::Value(Value::CellPath { val: path, .. }, _) = path { - let value = value.follow_cell_path(&path.members, true)?; + let value = value.follow_cell_path(&path.members)?; ctx.put_reg(*dst, value.into_owned().into_pipeline_data()); Ok(Continue) } else if let PipelineData::Value(Value::Error { error, .. }, _) = path { diff --git a/crates/nu-lsp/src/goto.rs b/crates/nu-lsp/src/goto.rs index f8623ee0d7..436ae50300 100644 --- a/crates/nu-lsp/src/goto.rs +++ b/crates/nu-lsp/src/goto.rs @@ -64,7 +64,7 @@ impl LanguageServer { Some( var.const_val .as_ref() - .and_then(|val| val.follow_cell_path(cell_path, false).ok()) + .and_then(|val| val.follow_cell_path(cell_path).ok()) .map(|val| val.span()) .unwrap_or(var.declaration_span), ) diff --git a/crates/nu-lsp/src/hover.rs b/crates/nu-lsp/src/hover.rs index c75499f0c2..fe31809d74 100644 --- a/crates/nu-lsp/src/hover.rs +++ b/crates/nu-lsp/src/hover.rs @@ -161,7 +161,7 @@ impl LanguageServer { markdown_hover( var.const_val .as_ref() - .and_then(|val| val.follow_cell_path(&cell_path, false).ok()) + .and_then(|val| val.follow_cell_path(&cell_path).ok()) .map(|val| { let ty = val.get_type(); if let Ok(s) = val.coerce_str() { diff --git a/crates/nu-protocol/src/pipeline/pipeline_data.rs b/crates/nu-protocol/src/pipeline/pipeline_data.rs index a0ea603dc1..1216aa3a6a 100644 --- a/crates/nu-protocol/src/pipeline/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline/pipeline_data.rs @@ -411,16 +411,13 @@ impl PipelineData { self, cell_path: &[PathMember], head: Span, - insensitive: bool, ) -> Result { match self { // FIXME: there are probably better ways of doing this PipelineData::ListStream(stream, ..) => Value::list(stream.into_iter().collect(), head) - .follow_cell_path(cell_path, insensitive) - .map(Cow::into_owned), - PipelineData::Value(v, ..) => v - .follow_cell_path(cell_path, insensitive) + .follow_cell_path(cell_path) .map(Cow::into_owned), + PipelineData::Value(v, ..) => v.follow_cell_path(cell_path).map(Cow::into_owned), PipelineData::Empty => Err(ShellError::IncompatiblePathAccess { type_name: "empty pipeline".to_string(), span: head, diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 357b5478ca..7f1e3c2a57 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -1083,7 +1083,6 @@ impl Value { pub fn follow_cell_path<'out>( &'out self, cell_path: &[PathMember], - insensitive: bool, ) -> Result, ShellError> { enum MultiLife<'out, 'local, T> where @@ -1116,7 +1115,7 @@ impl Value { for member in cell_path { current = match current { - MultiLife::Out(current) => match get_value_member(current, member, insensitive)? { + MultiLife::Out(current) => match get_value_member(current, member)? { ControlFlow::Break(span) => return Ok(Cow::Owned(Value::nothing(span))), ControlFlow::Continue(x) => match x { Cow::Borrowed(x) => MultiLife::Out(x), @@ -1126,18 +1125,16 @@ impl Value { } }, }, - MultiLife::Local(current) => { - match get_value_member(current, member, insensitive)? { - ControlFlow::Break(span) => return Ok(Cow::Owned(Value::nothing(span))), - ControlFlow::Continue(x) => match x { - Cow::Borrowed(x) => MultiLife::Local(x), - Cow::Owned(x) => { - store = x; - MultiLife::Local(&store) - } - }, - } - } + MultiLife::Local(current) => match get_value_member(current, member)? { + ControlFlow::Break(span) => return Ok(Cow::Owned(Value::nothing(span))), + ControlFlow::Continue(x) => match x { + Cow::Borrowed(x) => MultiLife::Local(x), + Cow::Owned(x) => { + store = x; + MultiLife::Local(&store) + } + }, + }, }; } @@ -1166,7 +1163,7 @@ impl Value { cell_path: &[PathMember], callback: Box Value>, ) -> Result<(), ShellError> { - let new_val = callback(self.follow_cell_path(cell_path, false)?.as_ref()); + let new_val = callback(self.follow_cell_path(cell_path)?.as_ref()); match new_val { Value::Error { error, .. } => Err(*error), @@ -1266,7 +1263,7 @@ impl Value { cell_path: &[PathMember], callback: Box Value + 'a>, ) -> Result<(), ShellError> { - let new_val = callback(self.follow_cell_path(cell_path, false)?.as_ref()); + let new_val = callback(self.follow_cell_path(cell_path)?.as_ref()); match new_val { Value::Error { error, .. } => Err(*error), @@ -2007,7 +2004,6 @@ impl Value { fn get_value_member<'a>( current: &'a Value, member: &PathMember, - insensitive: bool, ) -> Result>, ShellError> { match member { PathMember::Int { @@ -2100,7 +2096,7 @@ fn get_value_member<'a>( match current { Value::Record { val, .. } => { if let Some(found) = val.iter().rev().find(|x| { - if insensitive { + if *insensitive { x.0.eq_ignore_case(column_name) } else { x.0 == column_name @@ -2134,7 +2130,7 @@ fn get_value_member<'a>( match val { Value::Record { val, .. } => { if let Some(found) = val.iter().rev().find(|x| { - if insensitive { + if *insensitive { x.0.eq_ignore_case(column_name) } else { x.0 == column_name diff --git a/crates/nu_plugin_inc/src/inc.rs b/crates/nu_plugin_inc/src/inc.rs index c479cd4457..f2a41b8a03 100644 --- a/crates/nu_plugin_inc/src/inc.rs +++ b/crates/nu_plugin_inc/src/inc.rs @@ -91,7 +91,7 @@ impl Inc { pub fn inc(&self, head: Span, value: &Value) -> Result { if let Some(cell_path) = &self.cell_path { - let cell_value = value.follow_cell_path(&cell_path.members, false)?; + let cell_value = value.follow_cell_path(&cell_path.members)?; let cell_value = self.inc_value(head, &cell_value)?;