Autocomplete content methods (#5822)

This commit is contained in:
Laurenz 2025-02-06 10:34:28 +01:00 committed by GitHub
parent 4a9a5d2716
commit d897ab5e7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -398,7 +398,17 @@ fn field_access_completions(
value: &Value,
styles: &Option<Styles>,
) {
for (name, binding) in value.ty().scope().iter() {
let scopes = {
let ty = value.ty().scope();
let elem = match value {
Value::Content(content) => Some(content.elem().scope()),
_ => None,
};
elem.into_iter().chain(Some(ty))
};
// Autocomplete methods from the element's or type's scope.
for (name, binding) in scopes.flat_map(|scope| scope.iter()) {
ctx.call_completion(name.clone(), binding.read());
}
@ -1747,4 +1757,15 @@ mod tests {
.must_include(["this", "that"])
.must_exclude(["*", "figure"]);
}
#[test]
fn test_autocomplete_type_methods() {
test("#\"hello\".", -1).must_include(["len", "contains"]);
}
#[test]
fn test_autocomplete_content_methods() {
test("#show outline.entry: it => it.\n#outline()\n= Hi", 30)
.must_include(["indented", "body", "page"]);
}
}