2 mod completion_context;
12 use ra_db::SourceDatabase;
18 completion_item::{Completions, CompletionKind},
19 completion_context::CompletionContext,
23 pub use crate::completion::completion_item::{CompletionItem, CompletionItemKind, InsertTextFormat};
25 /// Main entry point for completion. We run completion as a two-phase process.
27 /// First, we look at the position and collect a so-called `CompletionContext.
28 /// This is a somewhat messy process, because, during completion, syntax tree is
29 /// incomplete and can look really weird.
31 /// Once the context is collected, we run a series of completion routines which
32 /// look at the context and produce completion items. One subtelty about this
33 /// phase is that completion engine should not filter by the substring which is
34 /// already present, it should give all possible variants for the identifier at
35 /// the caret. In other words, for
44 /// `foo` *should* be present among the completion variants. Filtering by
45 /// identifier prefix/fuzzy match should be done higher in the stack, together
46 /// with ordering of completions (currently this is done by the client).
47 pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option<Completions> {
48 let original_file = db.parse(position.file_id);
49 let ctx = CompletionContext::new(db, &original_file, position)?;
51 let mut acc = Completions::default();
53 complete_fn_param::complete_fn_param(&mut acc, &ctx);
54 complete_keyword::complete_expr_keyword(&mut acc, &ctx);
55 complete_keyword::complete_use_tree_keyword(&mut acc, &ctx);
56 complete_snippet::complete_expr_snippet(&mut acc, &ctx);
57 complete_snippet::complete_item_snippet(&mut acc, &ctx);
58 complete_path::complete_path(&mut acc, &ctx);
59 complete_scope::complete_scope(&mut acc, &ctx);
60 complete_dot::complete_dot(&mut acc, &ctx);
61 complete_postfix::complete_postfix(&mut acc, &ctx);