diff options
| author | voidiz <29259387+voidiz@users.noreply.github.com> | 2023-12-28 15:28:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-28 14:28:04 +0000 |
| commit | 4e5afa672f502d53e931d432ec1a36bdc6e16583 (patch) | |
| tree | d6adc0ee89bde75b31a400e33960cbf103fb8864 /crates | |
| parent | 2dd3af937a83f02c59ad069ca6d8e41b9173aff2 (diff) | |
Suggest accessing field if method doesn't exist (#2977)
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/eval/call.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/typst/src/eval/call.rs b/crates/typst/src/eval/call.rs index 9e4a128f..a4b05777 100644 --- a/crates/typst/src/eval/call.rs +++ b/crates/typst/src/eval/call.rs @@ -1,5 +1,5 @@ use comemo::{Prehashed, Tracked, TrackedMut}; -use ecow::EcoVec; +use ecow::{eco_format, EcoVec}; use crate::diag::{bail, error, At, HintedStrResult, SourceResult, Trace, Tracepoint}; use crate::engine::Engine; @@ -99,13 +99,27 @@ impl Eval for ast::FuncCall<'_> { field.as_str() ); - if let Value::Dict(dict) = target { - if matches!(dict.get(&field), Ok(Value::Func(_))) { - error.hint( - "to call the function stored in the dictionary, \ + let mut field_hint = || { + if target.field(&field).is_ok() { + error.hint(eco_format!( + "did you mean to access the field `{}`?", + field.as_str() + )); + } + }; + + match target { + Value::Dict(ref dict) => { + if matches!(dict.get(&field), Ok(Value::Func(_))) { + error.hint( + "to call the function stored in the dictionary, \ surround the field access with parentheses", - ); + ); + } else { + field_hint(); + } } + _ => field_hint(), } bail!(error); |
