mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 10:03:24 +02:00
Add 'did you mean' error (#305)
This commit is contained in:
@@ -15,7 +15,7 @@ use std::collections::HashMap;
|
||||
use std::{cmp::Ordering, fmt::Debug};
|
||||
|
||||
use crate::ast::{CellPath, PathMember};
|
||||
use crate::{span, BlockId, Span, Spanned, Type};
|
||||
use crate::{did_you_mean, span, BlockId, Span, Spanned, Type};
|
||||
|
||||
use crate::ShellError;
|
||||
|
||||
@@ -269,17 +269,16 @@ impl Value {
|
||||
span: origin_span,
|
||||
} => match &mut current {
|
||||
Value::Record { cols, vals, span } => {
|
||||
let cols = cols.clone();
|
||||
let span = *span;
|
||||
let mut found = false;
|
||||
for col in cols.iter().zip(vals.iter()) {
|
||||
if col.0 == column_name {
|
||||
current = col.1.clone();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
if let Some(found) =
|
||||
cols.iter().zip(vals.iter()).find(|x| x.0 == column_name)
|
||||
{
|
||||
current = found.1.clone();
|
||||
} else if let Some(suggestion) = did_you_mean(&cols, column_name) {
|
||||
return Err(ShellError::DidYouMean(suggestion, *origin_span));
|
||||
} else {
|
||||
return Err(ShellError::CantFindColumn(*origin_span, span));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user