mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
added eq_token() method to LetStmt
This commit is contained in:
parent
514df15d9e
commit
f67ee69777
@ -1,7 +1,6 @@
|
||||
use hir::{db::HirDatabase, HirDisplay};
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode, LetStmt, NameOwner},
|
||||
SyntaxKind::EQ,
|
||||
TextRange, T,
|
||||
};
|
||||
|
||||
@ -37,7 +36,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
|
||||
let name_range = name.syntax().text_range();
|
||||
// Assist should only be applicable if cursor is between 'let' and '='
|
||||
let stmt_range = stmt.syntax().text_range();
|
||||
let eq_range = stmt.syntax().descendants_with_tokens().find(|t| t.kind() == EQ)?.text_range();
|
||||
let eq_range = stmt.eq_token()?.text_range();
|
||||
let let_range = TextRange::from_to(stmt_range.start(), eq_range.start());
|
||||
let cursor_in_range = ctx.frange.range.is_subrange(&let_range);
|
||||
if !cursor_in_range {
|
||||
|
@ -234,6 +234,13 @@ impl ast::LetStmt {
|
||||
Some(node) => node.kind() == T![;],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_token(&self) -> Option<SyntaxToken> {
|
||||
self.syntax()
|
||||
.descendants_with_tokens()
|
||||
.find(|t| t.kind() == EQ)
|
||||
.and_then(|it| it.into_token())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprStmt {
|
||||
|
Loading…
Reference in New Issue
Block a user