aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index c4646b727..1ef07d8f4 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -5,12 +5,16 @@ use ra_db::SourceDatabase;
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::{ 6use ra_syntax::{
7 algo::{find_covering_element, find_node_at_offset}, 7 algo::{find_covering_element, find_node_at_offset},
8 ast, match_ast, AstNode, 8 ast, match_ast, AstNode, NodeOrToken,
9 SyntaxKind::*, 9 SyntaxKind::*,
10 SyntaxNode, SyntaxToken, TextRange, TextSize, 10 SyntaxNode, SyntaxToken, TextRange, TextSize,
11}; 11};
12use ra_text_edit::Indel; 12use ra_text_edit::Indel;
13 13
14use super::patterns::{
15 goes_after_unsafe, has_bind_pat_parent, has_block_expr_parent, has_ref_pat_parent,
16 is_in_loop_body,
17};
14use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition}; 18use crate::{call_info::ActiveParameter, completion::CompletionConfig, FilePosition};
15use test_utils::mark; 19use test_utils::mark;
16 20
@@ -60,6 +64,11 @@ pub(crate) struct CompletionContext<'a> {
60 pub(super) is_path_type: bool, 64 pub(super) is_path_type: bool,
61 pub(super) has_type_args: bool, 65 pub(super) has_type_args: bool,
62 pub(super) attribute_under_caret: Option<ast::Attr>, 66 pub(super) attribute_under_caret: Option<ast::Attr>,
67 pub(super) after_unsafe: bool,
68 pub(super) block_expr_parent: bool,
69 pub(super) bind_pat_parent: bool,
70 pub(super) ref_pat_parent: bool,
71 pub(super) in_loop_body: bool,
63} 72}
64 73
65impl<'a> CompletionContext<'a> { 74impl<'a> CompletionContext<'a> {
@@ -118,6 +127,11 @@ impl<'a> CompletionContext<'a> {
118 has_type_args: false, 127 has_type_args: false,
119 dot_receiver_is_ambiguous_float_literal: false, 128 dot_receiver_is_ambiguous_float_literal: false,
120 attribute_under_caret: None, 129 attribute_under_caret: None,
130 after_unsafe: false,
131 in_loop_body: false,
132 ref_pat_parent: false,
133 bind_pat_parent: false,
134 block_expr_parent: false,
121 }; 135 };
122 136
123 let mut original_file = original_file.syntax().clone(); 137 let mut original_file = original_file.syntax().clone();
@@ -159,7 +173,7 @@ impl<'a> CompletionContext<'a> {
159 break; 173 break;
160 } 174 }
161 } 175 }
162 176 ctx.fill_keyword_patterns(&hypothetical_file, offset);
163 ctx.fill(&original_file, hypothetical_file, offset); 177 ctx.fill(&original_file, hypothetical_file, offset);
164 Some(ctx) 178 Some(ctx)
165 } 179 }
@@ -188,6 +202,16 @@ impl<'a> CompletionContext<'a> {
188 self.sema.scope_at_offset(&self.token.parent(), self.offset) 202 self.sema.scope_at_offset(&self.token.parent(), self.offset)
189 } 203 }
190 204
205 fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) {
206 let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap();
207 let syntax_element = NodeOrToken::Token(fake_ident_token.clone());
208 self.block_expr_parent = has_block_expr_parent(syntax_element.clone());
209 self.after_unsafe = goes_after_unsafe(syntax_element.clone());
210 self.bind_pat_parent = has_bind_pat_parent(syntax_element.clone());
211 self.ref_pat_parent = has_ref_pat_parent(syntax_element.clone());
212 self.in_loop_body = is_in_loop_body(syntax_element.clone());
213 }
214
191 fn fill( 215 fn fill(
192 &mut self, 216 &mut self,
193 original_file: &SyntaxNode, 217 original_file: &SyntaxNode,