aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index a8c8cc7b0..bda7d9bb2 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -1,6 +1,6 @@
1use ra_text_edit::AtomTextEdit; 1use ra_text_edit::AtomTextEdit;
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, 3 AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, Parse,
4 ast, 4 ast,
5 algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, 5 algo::{find_token_at_offset, find_covering_element, find_node_at_offset},
6 SyntaxKind::*, 6 SyntaxKind::*,
@@ -43,11 +43,12 @@ pub(crate) struct CompletionContext<'a> {
43impl<'a> CompletionContext<'a> { 43impl<'a> CompletionContext<'a> {
44 pub(super) fn new( 44 pub(super) fn new(
45 db: &'a db::RootDatabase, 45 db: &'a db::RootDatabase,
46 original_file: &'a SourceFile, 46 original_parse: &'a Parse,
47 position: FilePosition, 47 position: FilePosition,
48 ) -> Option<CompletionContext<'a>> { 48 ) -> Option<CompletionContext<'a>> {
49 let module = source_binder::module_from_position(db, position); 49 let module = source_binder::module_from_position(db, position);
50 let token = find_token_at_offset(original_file.syntax(), position.offset).left_biased()?; 50 let token =
51 find_token_at_offset(original_parse.tree.syntax(), position.offset).left_biased()?;
51 let analyzer = 52 let analyzer =
52 hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset)); 53 hir::SourceAnalyzer::new(db, position.file_id, token.parent(), Some(position.offset));
53 let mut ctx = CompletionContext { 54 let mut ctx = CompletionContext {
@@ -69,7 +70,7 @@ impl<'a> CompletionContext<'a> {
69 dot_receiver: None, 70 dot_receiver: None,
70 is_call: false, 71 is_call: false,
71 }; 72 };
72 ctx.fill(original_file, position.offset); 73 ctx.fill(&original_parse, position.offset);
73 Some(ctx) 74 Some(ctx)
74 } 75 }
75 76
@@ -82,13 +83,13 @@ impl<'a> CompletionContext<'a> {
82 } 83 }
83 } 84 }
84 85
85 fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { 86 fn fill(&mut self, original_parse: &'a Parse, offset: TextUnit) {
86 // Insert a fake ident to get a valid parse tree. We will use this file 87 // Insert a fake ident to get a valid parse tree. We will use this file
87 // to determine context, though the original_file will be used for 88 // to determine context, though the original_file will be used for
88 // actual completion. 89 // actual completion.
89 let file = { 90 let file = {
90 let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string()); 91 let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string());
91 original_file.reparse(&edit) 92 original_parse.reparse(&edit).tree
92 }; 93 };
93 94
94 // First, let's try to complete a reference to some declaration. 95 // First, let's try to complete a reference to some declaration.
@@ -99,7 +100,7 @@ impl<'a> CompletionContext<'a> {
99 self.is_param = true; 100 self.is_param = true;
100 return; 101 return;
101 } 102 }
102 self.classify_name_ref(original_file, name_ref); 103 self.classify_name_ref(&original_parse.tree, name_ref);
103 } 104 }
104 105
105 // Otherwise, see if this is a declaration. We can use heuristics to 106 // Otherwise, see if this is a declaration. We can use heuristics to