Skip to content

Commit

Permalink
feat: allow fuzzy selection to deref targets (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Mar 15, 2024
1 parent be24484 commit f683426
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions crates/tinymist-query/src/syntax/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,51 @@ impl<'a> DerefTarget<'a> {
}
}

fn is_mark(sk: SyntaxKind) -> bool {
use SyntaxKind::*;
matches!(
sk,
MathAlignPoint
| Plus
| Minus
| Slash
| Hat
| Dot
| Eq
| EqEq
| ExclEq
| Lt
| LtEq
| Gt
| GtEq
| PlusEq
| HyphEq
| StarEq
| SlashEq
| Dots
| Arrow
| Not
| And
| Or
| LeftBrace
| RightBrace
| LeftBracket
| RightBracket
| LeftParen
| RightParen
| Comma
| Semicolon
| Colon
| Hash
)
}

pub fn get_deref_target(node: LinkedNode) -> Option<DerefTarget> {
let mut ancestor = node;
if ancestor.kind().is_trivia() || is_mark(ancestor.kind()) {
ancestor = ancestor.prev_sibling()?;
}

while !ancestor.is::<ast::Expr>() {
ancestor = ancestor.parent()?.clone();
}
Expand Down

0 comments on commit f683426

Please sign in to comment.