aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/assists/add_explicit_type.rs3
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs7
2 files changed, 8 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs
index 713abf910..38a351a54 100644
--- a/crates/ra_assists/src/assists/add_explicit_type.rs
+++ b/crates/ra_assists/src/assists/add_explicit_type.rs
@@ -1,7 +1,6 @@
1use hir::{db::HirDatabase, HirDisplay}; 1use hir::{db::HirDatabase, HirDisplay};
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, LetStmt, NameOwner}, 3 ast::{self, AstNode, LetStmt, NameOwner},
4 SyntaxKind::EQ,
5 TextRange, T, 4 TextRange, T,
6}; 5};
7 6
@@ -37,7 +36,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
37 let name_range = name.syntax().text_range(); 36 let name_range = name.syntax().text_range();
38 // Assist should only be applicable if cursor is between 'let' and '=' 37 // Assist should only be applicable if cursor is between 'let' and '='
39 let stmt_range = stmt.syntax().text_range(); 38 let stmt_range = stmt.syntax().text_range();
40 let eq_range = stmt.syntax().descendants_with_tokens().find(|t| t.kind() == EQ)?.text_range(); 39 let eq_range = stmt.eq_token()?.text_range();
41 let let_range = TextRange::from_to(stmt_range.start(), eq_range.start()); 40 let let_range = TextRange::from_to(stmt_range.start(), eq_range.start());
42 let cursor_in_range = ctx.frange.range.is_subrange(&let_range); 41 let cursor_in_range = ctx.frange.range.is_subrange(&let_range);
43 if !cursor_in_range { 42 if !cursor_in_range {
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index d9666cdca..b8043b726 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -234,6 +234,13 @@ impl ast::LetStmt {
234 Some(node) => node.kind() == T![;], 234 Some(node) => node.kind() == T![;],
235 } 235 }
236 } 236 }
237
238 pub fn eq_token(&self) -> Option<SyntaxToken> {
239 self.syntax()
240 .descendants_with_tokens()
241 .find(|t| t.kind() == EQ)
242 .and_then(|it| it.into_token())
243 }
237} 244}
238 245
239impl ast::ExprStmt { 246impl ast::ExprStmt {