mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Only autocomplete methods which take self (#5824)
This commit is contained in:
parent
2eef9e84e1
commit
8f039dd614
@ -410,9 +410,17 @@ fn field_access_completions(
|
|||||||
elem.into_iter().chain(Some(ty))
|
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()) {
|
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() {
|
if let Some(scope) = value.scope() {
|
||||||
@ -1764,6 +1772,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_autocomplete_type_methods() {
|
fn test_autocomplete_type_methods() {
|
||||||
test("#\"hello\".", -1).must_include(["len", "contains"]);
|
test("#\"hello\".", -1).must_include(["len", "contains"]);
|
||||||
|
test("#table().", -1).must_exclude(["cell"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user