From 367f79cb4fc2f281abe608840733f78f664b34a7 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 11 Sep 2022 12:58:19 -0400 Subject: [PATCH] Don't compute 'did you mean' suggestions unless showing them to user (#6540) --- crates/nu-engine/src/env.rs | 2 +- crates/nu-protocol/src/value/mod.rs | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/nu-engine/src/env.rs b/crates/nu-engine/src/env.rs index 04dbc3e27c..336828593c 100644 --- a/crates/nu-engine/src/env.rs +++ b/crates/nu-engine/src/env.rs @@ -336,7 +336,7 @@ fn get_converted_value( val: block_id, span: from_span, .. - }) = env_conversions.follow_cell_path(path_members, false) + }) = env_conversions.follow_cell_path_not_from_user_input(path_members, false) { let block = engine_state.get_block(block_id); diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index c07bf4ca7e..4d9762ba9f 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -609,6 +609,23 @@ impl Value { self, cell_path: &[PathMember], insensitive: bool, + ) -> Result { + self.follow_cell_path_helper(cell_path, insensitive, true) + } + + pub fn follow_cell_path_not_from_user_input( + self, + cell_path: &[PathMember], + insensitive: bool, + ) -> Result { + self.follow_cell_path_helper(cell_path, insensitive, false) + } + + fn follow_cell_path_helper( + self, + cell_path: &[PathMember], + insensitive: bool, + from_user_input: bool, ) -> Result { let mut current = self; for member in cell_path { @@ -673,9 +690,12 @@ impl Value { } }) { current = found.1.clone(); - } else if let Some(suggestion) = did_you_mean(&cols, column_name) { - return Err(ShellError::DidYouMean(suggestion, *origin_span)); } else { + if from_user_input { + if let Some(suggestion) = did_you_mean(&cols, column_name) { + return Err(ShellError::DidYouMean(suggestion, *origin_span)); + } + } return Err(ShellError::CantFindColumn(*origin_span, span)); } }