Skip to content

Commit

Permalink
fix: skip code completion when editing length (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Nov 22, 2024
1 parent 49d33e5 commit 422971c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/tinymist-query/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ impl StatefulRequest for CompletionRequest {
}
}

// Skip if an error node starts with number (e.g. `1pt`)
if matches!(
deref_target,
Some(DerefTarget::Callee(..) | DerefTarget::VarAccess(..) | DerefTarget::Normal(..),)
) {
let node = LinkedNode::new(source.root()).leaf_at_compat(cursor)?;
if node.erroneous() {
let mut n = node.text().chars();

match n.next() {
Some(c) if c.is_numeric() => return None,
Some('.') => {
if matches!(n.next(), Some(c) if c.is_numeric()) {
return None;
}
}
_ => {}
}
}
}

// Do some completion specific to the deref target
let mut ident_like = None;
let mut completion_result = None;
Expand Down
2 changes: 2 additions & 0 deletions crates/tinymist-query/src/fixtures/completion/edit_length.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// contains: top-edge
#text(size: 1p/* range 0..1 */)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (37..38)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/edit_length.typ
snapshot_kind: text
---
[
null
]

0 comments on commit 422971c

Please sign in to comment.