diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-27 18:45:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-27 18:45:05 +0000 |
commit | 360f6b7bb32d6280ed787075c4a54f4e5b46fcb6 (patch) | |
tree | 4c059427819ef442c785125f48fe83f81f6d667a /crates/ra_ide/src/completion.rs | |
parent | 4946169a96f3d442f463724af481fdb760381ccb (diff) | |
parent | 27b362b05910c81fd5b28f6cd5d2c075311032f9 (diff) |
Merge #2430
2430: rename ra_ide_api -> ra_ide r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
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 | } | ||