Move CompletionContext::incomplete_let into PathKind::Expr

This commit is contained in:
Lukas Wirth 2022-06-18 10:18:56 +02:00
parent 7369e5120d
commit 83e8f3ac30
4 changed files with 29 additions and 12 deletions

View file

@ -110,12 +110,18 @@ impl Completions {
["self", "super", "crate"].into_iter().for_each(|kw| self.add_keyword(ctx, kw));
}
pub(crate) fn add_keyword_snippet(&mut self, ctx: &CompletionContext, kw: &str, snippet: &str) {
pub(crate) fn add_keyword_snippet_expr(
&mut self,
ctx: &CompletionContext,
kw: &str,
snippet: &str,
incomplete_let: bool,
) {
let mut item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), kw);
match ctx.config.snippet_cap {
Some(cap) => {
if snippet.ends_with('}') && ctx.incomplete_let {
if snippet.ends_with('}') && incomplete_let {
// complete block expression snippets with a trailing semicolon, if inside an incomplete let
cov_mark::hit!(let_semi);
item.insert_snippet(cap, format!("{};", snippet));
@ -130,6 +136,16 @@ impl Completions {
item.add_to(self);
}
pub(crate) fn add_keyword_snippet(&mut self, ctx: &CompletionContext, kw: &str, snippet: &str) {
let mut item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), kw);
match ctx.config.snippet_cap {
Some(cap) => item.insert_snippet(cap, snippet),
None => item.insert_text(if snippet.contains('$') { kw } else { snippet }),
};
item.add_to(self);
}
pub(crate) fn add_crate_roots(&mut self, ctx: &CompletionContext) {
ctx.process_all_names(&mut |name, res| match res {
ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) if m.is_crate_root(ctx.db) => {