Merge pull request #696 from jonathandturner/moredidyoumean

More 'did you mean?' errors
This commit is contained in:
Jonathan Turner 2019-09-24 08:44:26 +12:00 committed by GitHub
commit 7d41ac54b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 23 deletions

View File

@ -12,20 +12,6 @@ pub enum Description {
Synthetic(String), Synthetic(String),
} }
impl Description {
pub fn from(value: Tagged<impl Into<String>>) -> Description {
let value_tag = value.tag();
match value_tag {
Tag {
span: crate::data::meta::Span { start: 0, end: 0 },
..
} => Description::Synthetic(value.item.into()),
_ => Description::Source(Tagged::from_item(value.item.into(), value_tag)),
}
}
}
impl Description { impl Description {
fn into_label(self) -> Result<Label<Tag>, String> { fn into_label(self) -> Result<Label<Tag>, String> {
match self { match self {
@ -114,10 +100,6 @@ impl ShellError {
.start() .start()
} }
pub(crate) fn missing_property(subpath: Description, expr: Description) -> ShellError {
ProximateShellError::MissingProperty { subpath, expr }.start()
}
pub(crate) fn missing_value(tag: Option<Tag>, reason: impl Into<String>) -> ShellError { pub(crate) fn missing_value(tag: Option<Tag>, reason: impl Into<String>) -> ShellError {
ProximateShellError::MissingValue { ProximateShellError::MissingValue {
tag, tag,

View File

@ -1,5 +1,5 @@
use crate::data::base::Block; use crate::data::base::Block;
use crate::errors::{ArgumentError, Description}; use crate::errors::ArgumentError;
use crate::parser::{ use crate::parser::{
hir::{self, Expression, RawExpression}, hir::{self, Expression, RawExpression},
CommandRegistry, Text, CommandRegistry, Text,
@ -87,10 +87,20 @@ pub(crate) fn evaluate_baseline_expr(
match next { match next {
None => { None => {
return Err(ShellError::missing_property( let possibilities = item.data_descriptors();
Description::from(item.tagged_type_name()),
Description::from(name.clone()), let mut possible_matches: Vec<_> = possibilities
)) .iter()
.map(|x| (natural::distance::levenshtein_distance(x, &name), x))
.collect();
possible_matches.sort();
return Err(ShellError::labeled_error(
"Unknown column",
format!("did you mean '{}'?", possible_matches[0].1),
expr.tag(),
));
} }
Some(next) => { Some(next) => {
item = next.clone().item.tagged(expr.tag()); item = next.clone().item.tagged(expr.tag());