diff options
author | TomasKralCZ <[email protected]> | 2020-01-19 17:55:56 +0000 |
---|---|---|
committer | TomasKralCZ <[email protected]> | 2020-01-19 17:55:56 +0000 |
commit | f67ee69777e53ca1121e6aa461ecf84a3c01e139 (patch) | |
tree | 808b2ca3bff4a299a4997a5f1f4847d072f0e42c | |
parent | 514df15d9e32e057ba23dda0d4f5c07e82e7ed23 (diff) |
added eq_token() method to LetStmt
-rw-r--r-- | crates/ra_assists/src/assists/add_explicit_type.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 7 |
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 @@ | |||
1 | use hir::{db::HirDatabase, HirDisplay}; | 1 | use hir::{db::HirDatabase, HirDisplay}; |
2 | use ra_syntax::{ | 2 | use 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 | ||
239 | impl ast::ExprStmt { | 246 | impl ast::ExprStmt { |