aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-21 21:52:02 +0000
committerAleksey Kladov <[email protected]>2018-12-21 21:52:02 +0000
commitccca5aae43a27c94180bb099bcc09bb6c29c2ea3 (patch)
tree3d6ce58a0e87cb89ef4ca2df29e5f25bac86d0b8 /crates/ra_analysis/src/completion.rs
parent2136e75c0bce090d104bb5b5006e48e42fb22a0a (diff)
scope-based copmletions on original file
Diffstat (limited to 'crates/ra_analysis/src/completion.rs')
-rw-r--r--crates/ra_analysis/src/completion.rs18
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 @@
1mod completion_item; 1mod completion_item;
2mod reference_completion;
3 2
4mod complete_fn_param; 3mod complete_fn_param;
5mod complete_keyword; 4mod complete_keyword;
6mod complete_snippet; 5mod complete_snippet;
7mod complete_path; 6mod complete_path;
7mod complete_scope;
8 8
9use ra_editor::find_node_at_offset; 9use ra_editor::find_node_at_offset;
10use ra_text_edit::AtomTextEdit; 10use 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)]
63pub(super) struct SyntaxContext<'a> { 53pub(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,