mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Autocomplete content methods (#5822)
This commit is contained in:
parent
4a9a5d2716
commit
d897ab5e7d
@ -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"]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user