aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion.rs')
-rw-r--r--crates/ra_ide/src/completion.rs77
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
3mod completion_item;
4mod completion_context;
5mod presentation;
6
7mod complete_dot;
8mod complete_record_literal;
9mod complete_record_pattern;
10mod complete_pattern;
11mod complete_fn_param;
12mod complete_keyword;
13mod complete_snippet;
14mod complete_path;
15mod complete_scope;
16mod complete_postfix;
17mod complete_macro_in_item_position;
18
19use ra_db::SourceDatabase;
20
21#[cfg(test)]
22use crate::completion::completion_item::do_completion;
23use crate::{
24 completion::{
25 completion_context::CompletionContext,
26 completion_item::{CompletionKind, Completions},
27 },
28 db, FilePosition,
29};
30
31pub 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).
57pub(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}