2019-09-30 03:58:53 -05:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2020-04-23 19:01:23 -05:00
|
|
|
mod completion_config;
|
2019-01-08 13:33:36 -06:00
|
|
|
mod completion_item;
|
|
|
|
mod completion_context;
|
2019-02-24 09:51:38 -06:00
|
|
|
mod presentation;
|
2019-01-08 13:33:36 -06:00
|
|
|
|
2020-04-23 11:22:33 -05:00
|
|
|
mod complete_attribute;
|
2019-01-08 13:33:36 -06:00
|
|
|
mod complete_dot;
|
2020-03-31 16:50:45 -05:00
|
|
|
mod complete_record;
|
2019-02-24 14:49:47 -06:00
|
|
|
mod complete_pattern;
|
2019-01-08 13:33:36 -06:00
|
|
|
mod complete_fn_param;
|
|
|
|
mod complete_keyword;
|
|
|
|
mod complete_snippet;
|
2020-04-07 06:19:57 -05:00
|
|
|
mod complete_qualified_path;
|
|
|
|
mod complete_unqualified_path;
|
2019-01-20 23:19:51 -06:00
|
|
|
mod complete_postfix;
|
2019-09-11 09:44:44 -05:00
|
|
|
mod complete_macro_in_item_position;
|
2020-01-22 22:38:03 -06:00
|
|
|
mod complete_trait_impl;
|
2020-03-11 04:46:43 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test_utils;
|
2019-01-08 13:33:36 -06:00
|
|
|
|
2020-02-06 05:52:32 -06:00
|
|
|
use ra_ide_db::RootDatabase;
|
2019-01-08 13:33:36 -06:00
|
|
|
|
|
|
|
use crate::{
|
|
|
|
completion::{
|
|
|
|
completion_context::CompletionContext,
|
2019-07-04 15:05:17 -05:00
|
|
|
completion_item::{CompletionKind, Completions},
|
2019-01-08 13:33:36 -06:00
|
|
|
},
|
2020-02-06 05:52:32 -06:00
|
|
|
FilePosition,
|
2019-01-08 13:33:36 -06:00
|
|
|
};
|
|
|
|
|
2020-04-23 19:01:23 -05:00
|
|
|
pub use crate::completion::{
|
|
|
|
completion_config::CompletionConfig,
|
|
|
|
completion_item::{CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat},
|
2019-07-04 15:05:17 -05:00
|
|
|
};
|
2019-01-08 13:33:36 -06:00
|
|
|
|
|
|
|
/// Main entry point for completion. We run completion as a two-phase process.
|
|
|
|
///
|
|
|
|
/// First, we look at the position and collect a so-called `CompletionContext.
|
|
|
|
/// This is a somewhat messy process, because, during completion, syntax tree is
|
|
|
|
/// incomplete and can look really weird.
|
|
|
|
///
|
|
|
|
/// Once the context is collected, we run a series of completion routines which
|
2019-02-11 10:18:27 -06:00
|
|
|
/// look at the context and produce completion items. One subtlety about this
|
2019-01-08 13:33:36 -06:00
|
|
|
/// phase is that completion engine should not filter by the substring which is
|
|
|
|
/// already present, it should give all possible variants for the identifier at
|
|
|
|
/// the caret. In other words, for
|
|
|
|
///
|
|
|
|
/// ```no-run
|
|
|
|
/// fn f() {
|
|
|
|
/// let foo = 92;
|
|
|
|
/// let _ = bar<|>
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// `foo` *should* be present among the completion variants. Filtering by
|
|
|
|
/// identifier prefix/fuzzy match should be done higher in the stack, together
|
|
|
|
/// with ordering of completions (currently this is done by the client).
|
2020-03-10 12:39:17 -05:00
|
|
|
pub(crate) fn completions(
|
|
|
|
db: &RootDatabase,
|
|
|
|
position: FilePosition,
|
2020-03-31 09:02:55 -05:00
|
|
|
config: &CompletionConfig,
|
2020-03-10 12:39:17 -05:00
|
|
|
) -> Option<Completions> {
|
2020-03-31 09:02:55 -05:00
|
|
|
let ctx = CompletionContext::new(db, position, config)?;
|
2019-01-08 13:33:36 -06:00
|
|
|
|
|
|
|
let mut acc = Completions::default();
|
|
|
|
|
|
|
|
complete_fn_param::complete_fn_param(&mut acc, &ctx);
|
|
|
|
complete_keyword::complete_expr_keyword(&mut acc, &ctx);
|
|
|
|
complete_keyword::complete_use_tree_keyword(&mut acc, &ctx);
|
|
|
|
complete_snippet::complete_expr_snippet(&mut acc, &ctx);
|
|
|
|
complete_snippet::complete_item_snippet(&mut acc, &ctx);
|
2020-04-07 06:20:41 -05:00
|
|
|
complete_qualified_path::complete_qualified_path(&mut acc, &ctx);
|
|
|
|
complete_unqualified_path::complete_unqualified_path(&mut acc, &ctx);
|
2019-01-15 12:09:51 -06:00
|
|
|
complete_dot::complete_dot(&mut acc, &ctx);
|
2020-03-31 16:50:45 -05:00
|
|
|
complete_record::complete_record(&mut acc, &ctx);
|
2019-02-24 14:49:47 -06:00
|
|
|
complete_pattern::complete_pattern(&mut acc, &ctx);
|
2019-01-20 23:19:51 -06:00
|
|
|
complete_postfix::complete_postfix(&mut acc, &ctx);
|
2019-09-11 09:44:44 -05:00
|
|
|
complete_macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx);
|
2020-01-22 22:38:03 -06:00
|
|
|
complete_trait_impl::complete_trait_impl(&mut acc, &ctx);
|
2020-04-23 11:22:33 -05:00
|
|
|
complete_attribute::complete_attribute(&mut acc, &ctx);
|
2020-02-09 12:24:34 -06:00
|
|
|
|
2019-01-15 12:09:51 -06:00
|
|
|
Some(acc)
|
2019-01-08 13:33:36 -06:00
|
|
|
}
|