diff options
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index d91304bc2..93edcc4c2 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | mod completion_item; | 1 | mod completion_item; |
2 | mod reference_completion; | ||
3 | 2 | ||
4 | mod complete_fn_param; | 3 | mod complete_fn_param; |
5 | mod complete_keyword; | 4 | mod complete_keyword; |
6 | mod complete_snippet; | 5 | mod complete_snippet; |
7 | mod complete_path; | 6 | mod complete_path; |
7 | mod complete_scope; | ||
8 | 8 | ||
9 | use ra_editor::find_node_at_offset; | 9 | use ra_editor::find_node_at_offset; |
10 | use ra_text_edit::AtomTextEdit; | 10 | use ra_text_edit::AtomTextEdit; |
@@ -33,26 +33,16 @@ pub(crate) fn completions( | |||
33 | position: FilePosition, | 33 | position: FilePosition, |
34 | ) -> Cancelable<Option<Completions>> { | 34 | ) -> Cancelable<Option<Completions>> { |
35 | let original_file = db.source_file(position.file_id); | 35 | let original_file = db.source_file(position.file_id); |
36 | // Insert a fake ident to get a valid parse tree | 36 | let ctx = ctry!(SyntaxContext::new(db, &original_file, position)?); |
37 | let file = { | ||
38 | let edit = AtomTextEdit::insert(position.offset, "intellijRulezz".to_string()); | ||
39 | original_file.reparse(&edit) | ||
40 | }; | ||
41 | let module = ctry!(source_binder::module_from_position(db, position)?); | ||
42 | 37 | ||
43 | let mut acc = Completions::default(); | 38 | let mut acc = Completions::default(); |
44 | 39 | ||
45 | // First, let's try to complete a reference to some declaration. | ||
46 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | ||
47 | reference_completion::completions(&mut acc, db, &module, &file, name_ref)?; | ||
48 | } | ||
49 | |||
50 | let ctx = ctry!(SyntaxContext::new(db, &original_file, position)?); | ||
51 | complete_fn_param::complete_fn_param(&mut acc, &ctx); | 40 | complete_fn_param::complete_fn_param(&mut acc, &ctx); |
52 | complete_keyword::complete_expr_keyword(&mut acc, &ctx); | 41 | complete_keyword::complete_expr_keyword(&mut acc, &ctx); |
53 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); | 42 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); |
54 | complete_snippet::complete_item_snippet(&mut acc, &ctx); | 43 | complete_snippet::complete_item_snippet(&mut acc, &ctx); |
55 | complete_path::complete_path(&mut acc, &ctx)?; | 44 | complete_path::complete_path(&mut acc, &ctx)?; |
45 | complete_scope::complete_scope(&mut acc, &ctx)?; | ||
56 | 46 | ||
57 | Ok(Some(acc)) | 47 | Ok(Some(acc)) |
58 | } | 48 | } |
@@ -62,6 +52,7 @@ pub(crate) fn completions( | |||
62 | #[derive(Debug)] | 52 | #[derive(Debug)] |
63 | pub(super) struct SyntaxContext<'a> { | 53 | pub(super) struct SyntaxContext<'a> { |
64 | db: &'a db::RootDatabase, | 54 | db: &'a db::RootDatabase, |
55 | offset: TextUnit, | ||
65 | leaf: SyntaxNodeRef<'a>, | 56 | leaf: SyntaxNodeRef<'a>, |
66 | module: Option<hir::Module>, | 57 | module: Option<hir::Module>, |
67 | enclosing_fn: Option<ast::FnDef<'a>>, | 58 | enclosing_fn: Option<ast::FnDef<'a>>, |
@@ -88,6 +79,7 @@ impl<'a> SyntaxContext<'a> { | |||
88 | let mut ctx = SyntaxContext { | 79 | let mut ctx = SyntaxContext { |
89 | db, | 80 | db, |
90 | leaf, | 81 | leaf, |
82 | offset: position.offset, | ||
91 | module, | 83 | module, |
92 | enclosing_fn: None, | 84 | enclosing_fn: None, |
93 | is_param: false, | 85 | is_param: false, |