diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-02-25 15:10:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-25 14:10:01 +0000 |
| commit | 8f039dd614ba518976b8b486e0a138bd6a9c660c (patch) | |
| tree | f7e23c13d7511c4fd7e98a07a427010064ba1ab6 | |
| parent | 2eef9e84e117670ea0db964a5a8addc89e0ee785 (diff) | |
Only autocomplete methods which take self (#5824)
| -rw-r--r-- | crates/typst-ide/src/complete.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index e3dcc442..e3d77711 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -410,9 +410,17 @@ fn field_access_completions( elem.into_iter().chain(Some(ty)) }; - // Autocomplete methods from the element's or type's scope. + // Autocomplete methods from the element's or type's scope. We only complete + // those which have a `self` parameter. for (name, binding) in scopes.flat_map(|scope| scope.iter()) { - ctx.call_completion(name.clone(), binding.read()); + let Ok(func) = binding.read().clone().cast::<Func>() else { continue }; + if func + .params() + .and_then(|params| params.first()) + .is_some_and(|param| param.name == "self") + { + ctx.call_completion(name.clone(), binding.read()); + } } if let Some(scope) = value.scope() { @@ -1764,6 +1772,7 @@ mod tests { #[test] fn test_autocomplete_type_methods() { test("#\"hello\".", -1).must_include(["len", "contains"]); + test("#table().", -1).must_exclude(["cell"]); } #[test] |
