fix: don't complete import items across line (#952)

This commit is contained in:
Myriad-Dreamin 2024-12-06 13:29:21 +08:00 committed by GitHub
parent 9b3eaf9926
commit 22d2ed88a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,7 @@
/// path: base.typ
#let aa() = 1;
-----
/// contains: base,aa
#import "base.typ":
/* range 0..1 */

View file

@ -0,0 +1,13 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (42..43)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/import_item_cross_line.typ
snapshot_kind: text
---
[
{
"isIncomplete": false,
"items": []
}
]

View file

@ -535,6 +535,8 @@ fn complete_imports(ctx: &mut CompletionContext) -> bool {
if_chain! {
if let Some(prev) = ctx.leaf.prev_sibling();
if let Some(ast::Expr::Import(import)) = prev.get().cast();
if ctx.leaf.range().end <= prev.range().end ||
!ctx.text[prev.offset()..ctx.leaf.range().end].contains('\n');
if let Some(ast::Imports::Items(items)) = import.imports();
if let Some(source) = prev.children().find(|child| child.is::<ast::Expr>());
then {