mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Factor out pick_best_token
ide pattern into ide_db
This commit is contained in:
parent
4e2ec914f4
commit
f615efdfc3
9 changed files with 62 additions and 101 deletions
|
@ -1,11 +1,8 @@
|
|||
use std::iter;
|
||||
|
||||
use hir::Semantics;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{
|
||||
ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxToken,
|
||||
TokenAtOffset, WalkEvent, T,
|
||||
};
|
||||
use ide_db::{helpers::pick_best_token, RootDatabase};
|
||||
use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxKind::*, SyntaxNode, WalkEvent, T};
|
||||
|
||||
use crate::FilePosition;
|
||||
|
||||
|
@ -29,7 +26,10 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
let sema = Semantics::new(db);
|
||||
let file = sema.parse(position.file_id);
|
||||
|
||||
let tok = pick_best(file.syntax().token_at_offset(position.offset))?;
|
||||
let tok = pick_best_token(file.syntax().token_at_offset(position.offset), |kind| match kind {
|
||||
SyntaxKind::IDENT => 1,
|
||||
_ => 0,
|
||||
})?;
|
||||
let mut expanded = None;
|
||||
let mut name = None;
|
||||
for node in tok.ancestors() {
|
||||
|
@ -57,16 +57,6 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
Some(ExpandedMacro { name: name?, expansion })
|
||||
}
|
||||
|
||||
fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
|
||||
return tokens.max_by_key(priority);
|
||||
fn priority(n: &SyntaxToken) -> usize {
|
||||
match n.kind() {
|
||||
IDENT => 1,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_macro_recur(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
macro_call: &ast::MacroCall,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue