mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
Improve clarify of type errors and tooltip diagnostics
This commit is contained in:
@@ -324,26 +324,30 @@ fn format_type(ty: &str) -> String {
|
||||
|
||||
impl core::fmt::Debug for Type {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
Self::Generic(arg0) => write!(f, "Generic<{arg0}>"),
|
||||
let result = match self {
|
||||
Self::Generic(name) => name.to_string(),
|
||||
#[cfg(feature = "type_id_logging")]
|
||||
Self::Concrete(arg0) => write!(f, "Concrete<{}, {:?}>", arg0.name, arg0.id),
|
||||
Self::Concrete(ty) => format!("Concrete<{}, {:?}>", ty.name, ty.id),
|
||||
#[cfg(not(feature = "type_id_logging"))]
|
||||
Self::Concrete(arg0) => write!(f, "Concrete<{}>", format_type(&arg0.name)),
|
||||
Self::Fn(arg0, arg1) => write!(f, "{arg0:?} → {arg1:?}"),
|
||||
Self::Future(arg0) => write!(f, "Future<{arg0:?}>"),
|
||||
}
|
||||
Self::Concrete(ty) => format_type(&ty.name),
|
||||
Self::Fn(call_arg, return_value) => format!("{return_value:?} called with {call_arg:?}"),
|
||||
Self::Future(ty) => format!("{ty:?}"),
|
||||
};
|
||||
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
|
||||
write!(f, "{}", result)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Type {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Type::Generic(name) => write!(f, "{name}"),
|
||||
Type::Concrete(ty) => write!(f, "{}", format_type(&ty.name)),
|
||||
Type::Fn(input, output) => write!(f, "{input} → {output}"),
|
||||
Type::Future(ty) => write!(f, "Future<{ty}>"),
|
||||
}
|
||||
let result = match self {
|
||||
Type::Generic(name) => name.to_string(),
|
||||
Type::Concrete(ty) => format_type(&ty.name),
|
||||
Type::Fn(call_arg, return_value) => format!("{return_value} called with {call_arg}"),
|
||||
Type::Future(ty) => ty.to_string(),
|
||||
};
|
||||
let result = result.replace("Option<Arc<OwnedContextImpl>>", "Context");
|
||||
write!(f, "{}", result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -552,19 +552,36 @@ impl core::fmt::Debug for GraphErrorType {
|
||||
GraphErrorType::NoImplementations => write!(f, "No implementations found"),
|
||||
GraphErrorType::NoConstructor => write!(f, "No construct found for node"),
|
||||
GraphErrorType::InvalidImplementations { inputs, error_inputs } => {
|
||||
let format_error = |(index, (_found, expected)): &(usize, (Type, Type))| format!("• Input {}: {expected}, found: {_found}", index + 1);
|
||||
let format_error_list = |errors: &Vec<(usize, (Type, Type))>| errors.iter().map(format_error).collect::<Vec<_>>().join("\n").replace("Option<Arc<OwnedContextImpl>>", "Context");
|
||||
let format_error = |(index, (found, expected)): &(usize, (Type, Type))| {
|
||||
let index = index + 1;
|
||||
format!(
|
||||
"\
|
||||
• Input {index}:\n\
|
||||
…found: {found}\n\
|
||||
…expected: {expected}\
|
||||
"
|
||||
)
|
||||
};
|
||||
let format_error_list = |errors: &Vec<(usize, (Type, Type))>| errors.iter().map(format_error).collect::<Vec<_>>().join("\n");
|
||||
let mut errors = error_inputs.iter().map(format_error_list).collect::<Vec<_>>();
|
||||
errors.sort();
|
||||
let inputs = inputs.replace("Option<Arc<OwnedContextImpl>>", "Context");
|
||||
let errors = errors.join("\n");
|
||||
let incompatibility = if errors.chars().filter(|&c| c == '•').count() == 1 {
|
||||
"This input type is incompatible:"
|
||||
} else {
|
||||
"These input types are incompatible:"
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
"This node isn't compatible with the combination of types for the data it is given:\n\
|
||||
{inputs}\n\
|
||||
"\
|
||||
{incompatibility}\n\
|
||||
{errors}\n\
|
||||
\n\
|
||||
Each invalid input should be replaced by data with one of these supported types:\n\
|
||||
{}",
|
||||
errors.join("\n")
|
||||
The node is currently receiving all of the following input types:\n\
|
||||
{inputs}\n\
|
||||
This is not a supported arrangement of types for the node.\
|
||||
"
|
||||
)
|
||||
}
|
||||
GraphErrorType::MultipleImplementations { inputs, valid } => write!(f, "Multiple implementations found ({inputs}):\n{valid:#?}"),
|
||||
|
||||
Reference in New Issue
Block a user