diff options
| author | Yifan Song <41675306+Eric-Song-Nop@users.noreply.github.com> | 2024-12-18 19:11:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-18 18:11:13 +0000 |
| commit | 45c866fbb947715cfee1937c85d6d6d6f393d7a8 (patch) | |
| tree | b35268f1ba2dcfabd3166ed5afb01a8f46455454 | |
| parent | 9b697d59ae4d06a0ee0b1bc6b3879d3b9c67a8d4 (diff) | |
Fix autocompletion of half-completed import item (#5531)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
| -rw-r--r-- | crates/typst-ide/src/complete.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index 5c2b500a..c731165d 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -521,11 +521,13 @@ fn complete_imports(ctx: &mut CompletionContext) -> bool { if_chain! { if ctx.leaf.kind() == SyntaxKind::Ident; if let Some(parent) = ctx.leaf.parent(); - if parent.kind() == SyntaxKind::ImportItems; + if parent.kind() == SyntaxKind::ImportItemPath; if let Some(grand) = parent.parent(); - if let Some(ast::Expr::Import(import)) = grand.get().cast(); + if grand.kind() == SyntaxKind::ImportItems; + if let Some(great) = grand.parent(); + if let Some(ast::Expr::Import(import)) = great.get().cast(); if let Some(ast::Imports::Items(items)) = import.imports(); - if let Some(source) = grand.children().find(|child| child.is::<ast::Expr>()); + if let Some(source) = great.children().find(|child| child.is::<ast::Expr>()); then { ctx.from = ctx.leaf.offset(); import_item_completions(ctx, items, &source); @@ -1743,4 +1745,18 @@ mod tests { test("#figure(cap)", -1).must_apply("caption", "caption: [${}]"); } + + #[test] + fn test_autocomplete_import_items() { + let world = TestWorld::new("#import \"other.typ\": ") + .with_source("second.typ", "#import \"other.typ\": th") + .with_source("other.typ", "#let this = 1; #let that = 2"); + + test_with_path(&world, "main.typ", 21) + .must_include(["*", "this", "that"]) + .must_exclude(["figure"]); + test_with_path(&world, "second.typ", 23) + .must_include(["this", "that"]) + .must_exclude(["*", "figure"]); + } } |
