diff options
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index a76d1ce45..5f2797e41 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -7,7 +7,7 @@ use ra_syntax::{ | |||
7 | algo::{find_covering_element, find_node_at_offset}, | 7 | algo::{find_covering_element, find_node_at_offset}, |
8 | ast, AstNode, | 8 | ast, AstNode, |
9 | SyntaxKind::*, | 9 | SyntaxKind::*, |
10 | SyntaxNode, SyntaxToken, TextRange, TextUnit, | 10 | SyntaxNode, SyntaxToken, TextRange, TextSize, |
11 | }; | 11 | }; |
12 | use ra_text_edit::AtomTextEdit; | 12 | use ra_text_edit::AtomTextEdit; |
13 | 13 | ||
@@ -20,7 +20,7 @@ pub(crate) struct CompletionContext<'a> { | |||
20 | pub(super) sema: Semantics<'a, RootDatabase>, | 20 | pub(super) sema: Semantics<'a, RootDatabase>, |
21 | pub(super) db: &'a RootDatabase, | 21 | pub(super) db: &'a RootDatabase, |
22 | pub(super) config: &'a CompletionConfig, | 22 | pub(super) config: &'a CompletionConfig, |
23 | pub(super) offset: TextUnit, | 23 | pub(super) offset: TextSize, |
24 | /// The token before the cursor, in the original file. | 24 | /// The token before the cursor, in the original file. |
25 | pub(super) original_token: SyntaxToken, | 25 | pub(super) original_token: SyntaxToken, |
26 | /// The token before the cursor, in the macro-expanded file. | 26 | /// The token before the cursor, in the macro-expanded file. |
@@ -57,6 +57,7 @@ pub(crate) struct CompletionContext<'a> { | |||
57 | pub(super) is_macro_call: bool, | 57 | pub(super) is_macro_call: bool, |
58 | pub(super) is_path_type: bool, | 58 | pub(super) is_path_type: bool, |
59 | pub(super) has_type_args: bool, | 59 | pub(super) has_type_args: bool, |
60 | pub(super) is_attribute: bool, | ||
60 | } | 61 | } |
61 | 62 | ||
62 | impl<'a> CompletionContext<'a> { | 63 | impl<'a> CompletionContext<'a> { |
@@ -113,6 +114,7 @@ impl<'a> CompletionContext<'a> { | |||
113 | is_path_type: false, | 114 | is_path_type: false, |
114 | has_type_args: false, | 115 | has_type_args: false, |
115 | dot_receiver_is_ambiguous_float_literal: false, | 116 | dot_receiver_is_ambiguous_float_literal: false, |
117 | is_attribute: false, | ||
116 | }; | 118 | }; |
117 | 119 | ||
118 | let mut original_file = original_file.syntax().clone(); | 120 | let mut original_file = original_file.syntax().clone(); |
@@ -165,7 +167,7 @@ impl<'a> CompletionContext<'a> { | |||
165 | match self.token.kind() { | 167 | match self.token.kind() { |
166 | // workaroud when completion is triggered by trigger characters. | 168 | // workaroud when completion is triggered by trigger characters. |
167 | IDENT => self.original_token.text_range(), | 169 | IDENT => self.original_token.text_range(), |
168 | _ => TextRange::offset_len(self.offset, 0.into()), | 170 | _ => TextRange::empty(self.offset), |
169 | } | 171 | } |
170 | } | 172 | } |
171 | 173 | ||
@@ -188,7 +190,7 @@ impl<'a> CompletionContext<'a> { | |||
188 | &mut self, | 190 | &mut self, |
189 | original_file: &SyntaxNode, | 191 | original_file: &SyntaxNode, |
190 | file_with_fake_ident: SyntaxNode, | 192 | file_with_fake_ident: SyntaxNode, |
191 | offset: TextUnit, | 193 | offset: TextSize, |
192 | ) { | 194 | ) { |
193 | // First, let's try to complete a reference to some declaration. | 195 | // First, let's try to complete a reference to some declaration. |
194 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&file_with_fake_ident, offset) { | 196 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&file_with_fake_ident, offset) { |
@@ -222,7 +224,8 @@ impl<'a> CompletionContext<'a> { | |||
222 | } | 224 | } |
223 | if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { | 225 | if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { |
224 | if let Some(pat) = let_stmt.pat() { | 226 | if let Some(pat) = let_stmt.pat() { |
225 | if bind_pat.syntax().text_range().is_subrange(&pat.syntax().text_range()) { | 227 | if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) |
228 | { | ||
226 | self.is_pat_binding_or_const = false; | 229 | self.is_pat_binding_or_const = false; |
227 | } | 230 | } |
228 | } | 231 | } |
@@ -244,7 +247,7 @@ impl<'a> CompletionContext<'a> { | |||
244 | &mut self, | 247 | &mut self, |
245 | original_file: &SyntaxNode, | 248 | original_file: &SyntaxNode, |
246 | name_ref: ast::NameRef, | 249 | name_ref: ast::NameRef, |
247 | offset: TextUnit, | 250 | offset: TextSize, |
248 | ) { | 251 | ) { |
249 | self.name_ref_syntax = | 252 | self.name_ref_syntax = |
250 | find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); | 253 | find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); |
@@ -306,6 +309,7 @@ impl<'a> CompletionContext<'a> { | |||
306 | .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) | 309 | .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) |
307 | .is_some(); | 310 | .is_some(); |
308 | self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some(); | 311 | self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some(); |
312 | self.is_attribute = path.syntax().parent().and_then(ast::Attr::cast).is_some(); | ||
309 | 313 | ||
310 | self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); | 314 | self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); |
311 | self.has_type_args = segment.type_arg_list().is_some(); | 315 | self.has_type_args = segment.type_arg_list().is_some(); |