Don't compute 'did you mean' suggestions unless showing them to user (#6540)

This commit is contained in:
Dan Davison 2022-09-11 12:58:19 -04:00 committed by GitHub
parent 4926865c4e
commit 367f79cb4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -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);

View File

@ -609,6 +609,23 @@ impl Value {
self,
cell_path: &[PathMember],
insensitive: bool,
) -> Result<Value, ShellError> {
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<Value, ShellError> {
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<Value, ShellError> {
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));
}
}