diff options
author | Aleksey Kladov <[email protected]> | 2019-11-27 18:32:33 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-27 18:35:06 +0000 |
commit | 757e593b253b4df7e6fc8bf15a4d4f34c9d484c5 (patch) | |
tree | d972d3a7e6457efdb5e0c558a8350db1818d07ae /crates/ra_ide/src/completion.rs | |
parent | d9a36a736bfb91578a36505e7237212959bb55fe (diff) |
rename ra_ide_api -> ra_ide
Diffstat (limited to 'crates/ra_ide/src/completion.rs')
-rw-r--r-- | crates/ra_ide/src/completion.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs new file mode 100644 index 000000000..abe1f36ce --- /dev/null +++ b/crates/ra_ide/src/completion.rs | |||
@@ -0,0 +1,77 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | mod completion_item; | ||
4 | mod completion_context; | ||
5 | mod presentation; | ||
6 | |||
7 | mod complete_dot; | ||
8 | mod complete_record_literal; | ||
9 | mod complete_record_pattern; | ||
10 | mod complete_pattern; | ||
11 | mod complete_fn_param; | ||
12 | mod complete_keyword; | ||
13 | mod complete_snippet; | ||
14 | mod complete_path; | ||
15 | mod complete_scope; | ||
16 | mod complete_postfix; | ||
17 | mod complete_macro_in_item_position; | ||
18 | |||
19 | use ra_db::SourceDatabase; | ||
20 | |||
21 | #[cfg(test)] | ||
22 | use crate::completion::completion_item::do_completion; | ||
23 | use crate::{ | ||
24 | completion::{ | ||
25 | completion_context::CompletionContext, | ||
26 | completion_item::{CompletionKind, Completions}, | ||
27 | }, | ||
28 | db, FilePosition, | ||
29 | }; | ||
30 | |||
31 | pub use crate::completion::completion_item::{ | ||
32 | CompletionItem, CompletionItemKind, InsertTextFormat, | ||
33 | }; | ||
34 | |||
35 | /// Main entry point for completion. We run completion as a two-phase process. | ||
36 | /// | ||
37 | /// First, we look at the position and collect a so-called `CompletionContext. | ||
38 | /// This is a somewhat messy process, because, during completion, syntax tree is | ||
39 | /// incomplete and can look really weird. | ||
40 | /// | ||
41 | /// Once the context is collected, we run a series of completion routines which | ||
42 | /// look at the context and produce completion items. One subtlety about this | ||
43 | /// phase is that completion engine should not filter by the substring which is | ||
44 | /// already present, it should give all possible variants for the identifier at | ||
45 | /// the caret. In other words, for | ||
46 | /// | ||
47 | /// ```no-run | ||
48 | /// fn f() { | ||
49 | /// let foo = 92; | ||
50 | /// let _ = bar<|> | ||
51 | /// } | ||
52 | /// ``` | ||
53 | /// | ||
54 | /// `foo` *should* be present among the completion variants. Filtering by | ||
55 | /// identifier prefix/fuzzy match should be done higher in the stack, together | ||
56 | /// with ordering of completions (currently this is done by the client). | ||
57 | pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option<Completions> { | ||
58 | let original_parse = db.parse(position.file_id); | ||
59 | let ctx = CompletionContext::new(db, &original_parse, position)?; | ||
60 | |||
61 | let mut acc = Completions::default(); | ||
62 | |||
63 | complete_fn_param::complete_fn_param(&mut acc, &ctx); | ||
64 | complete_keyword::complete_expr_keyword(&mut acc, &ctx); | ||
65 | complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); | ||
66 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); | ||
67 | complete_snippet::complete_item_snippet(&mut acc, &ctx); | ||
68 | complete_path::complete_path(&mut acc, &ctx); | ||
69 | complete_scope::complete_scope(&mut acc, &ctx); | ||
70 | complete_dot::complete_dot(&mut acc, &ctx); | ||
71 | complete_record_literal::complete_record_literal(&mut acc, &ctx); | ||
72 | complete_record_pattern::complete_record_pattern(&mut acc, &ctx); | ||
73 | complete_pattern::complete_pattern(&mut acc, &ctx); | ||
74 | complete_postfix::complete_postfix(&mut acc, &ctx); | ||
75 | complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx); | ||
76 | Some(acc) | ||
77 | } | ||