diff options
Diffstat (limited to 'crates/assists/src/assist_context.rs')
-rw-r--r-- | crates/assists/src/assist_context.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index d11fee196..fcfe2d6ee 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -12,7 +12,7 @@ use ide_db::{ | |||
12 | }; | 12 | }; |
13 | use syntax::{ | 13 | use syntax::{ |
14 | algo::{self, find_node_at_offset, SyntaxRewriter}, | 14 | algo::{self, find_node_at_offset, SyntaxRewriter}, |
15 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxToken, TextRange, TextSize, | 15 | AstNode, AstToken, SourceFile, SyntaxElement, SyntaxKind, SyntaxToken, TextRange, TextSize, |
16 | TokenAtOffset, | 16 | TokenAtOffset, |
17 | }; | 17 | }; |
18 | use text_edit::{TextEdit, TextEditBuilder}; | 18 | use text_edit::{TextEdit, TextEditBuilder}; |
@@ -81,9 +81,12 @@ impl<'a> AssistContext<'a> { | |||
81 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { | 81 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { |
82 | self.source_file.syntax().token_at_offset(self.offset()) | 82 | self.source_file.syntax().token_at_offset(self.offset()) |
83 | } | 83 | } |
84 | pub(crate) fn find_token_at_offset(&self, kind: SyntaxKind) -> Option<SyntaxToken> { | 84 | pub(crate) fn find_token_syntax_at_offset(&self, kind: SyntaxKind) -> Option<SyntaxToken> { |
85 | self.token_at_offset().find(|it| it.kind() == kind) | 85 | self.token_at_offset().find(|it| it.kind() == kind) |
86 | } | 86 | } |
87 | pub(crate) fn find_token_at_offset<T: AstToken>(&self) -> Option<T> { | ||
88 | self.token_at_offset().find_map(T::cast) | ||
89 | } | ||
87 | pub(crate) fn find_node_at_offset<N: AstNode>(&self) -> Option<N> { | 90 | pub(crate) fn find_node_at_offset<N: AstNode>(&self) -> Option<N> { |
88 | find_node_at_offset(self.source_file.syntax(), self.offset()) | 91 | find_node_at_offset(self.source_file.syntax(), self.offset()) |
89 | } | 92 | } |