mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-12-23 08:47:50 +00:00
dev: identify let context completely (#255)
This commit is contained in:
parent
806fb9bdfc
commit
7e59b9dbcb
3 changed files with 54 additions and 11 deletions
|
|
@ -83,17 +83,19 @@ impl StatefulRequest for CompletionRequest {
|
|||
|
||||
if let Some(d) = &deref_target {
|
||||
let node = d.node();
|
||||
// skip if is the let binding item, todo, check whether the pattern is exact
|
||||
// todo: check if the pattern(span) is exact, instead of just checking the
|
||||
// parent kind
|
||||
if matches!(
|
||||
(d, node.parent_kind()),
|
||||
(
|
||||
DerefTarget::VarAccess(..),
|
||||
Some(SyntaxKind::LetBinding | SyntaxKind::Closure)
|
||||
)
|
||||
) {
|
||||
return None;
|
||||
// skip if is the let binding item *directly*
|
||||
if matches!(d, DerefTarget::VarAccess(..)) {
|
||||
match node.parent_kind() {
|
||||
// complete the init part of the let binding
|
||||
Some(SyntaxKind::LetBinding) => {
|
||||
let parent = node.parent()?;
|
||||
let parent_init = parent.cast::<ast::LetBinding>()?.init()?;
|
||||
let parent_init = parent.find(parent_init.span())?;
|
||||
parent_init.find(node.span())?;
|
||||
}
|
||||
Some(SyntaxKind::Closure) => return None,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
// contains: a
|
||||
|
||||
#let a = 1;
|
||||
#let b = /* range after 1..2 */ #();
|
||||
|
||||
#let add(x, y) = {
|
||||
x + y
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (60..61)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/let-context.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"label": "a",
|
||||
"labelDetails": {
|
||||
"description": "1"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "a",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 32,
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 32,
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue