summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2025-02-06 10:34:28 +0100
committerGitHub <noreply@github.com>2025-02-06 09:34:28 +0000
commitd897ab5e7d2e941494df8ba137a1f92f8aada03a (patch)
tree401f93c113d966c38c4a9114fe0b2180ad202b9c /crates
parent4a9a5d2716fc91f60734769eb001aef32fe15403 (diff)
Autocomplete content methods (#5822)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-ide/src/complete.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs
index c1f08cf0..7df788dc 100644
--- a/crates/typst-ide/src/complete.rs
+++ b/crates/typst-ide/src/complete.rs
@@ -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"]);
+ }
}