diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-02-06 10:34:28 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2025-02-06 11:24:19 +0100 |
| commit | d8b79b5b9bddeff4a9cb5b5978a1dc124a761901 (patch) | |
| tree | 41c62edaa00a0dd84e7a243ca21fde962e83ef5e | |
| parent | 56d8188c61de95e4fb6b8e77a175e72e20dba99e (diff) | |
Autocomplete content methods (#5822)
| -rw-r--r-- | crates/typst-ide/src/complete.rs | 23 |
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"]); + } } |
