pub(crate) mod macro_in_item_position;
pub(crate) mod trait_impl;
pub(crate) mod mod_;
+
+use crate::item::{Builder, CompletionItem};
+
+/// Represents an in-progress set of completions being built.
+#[derive(Debug, Default)]
+pub struct Completions {
+ buf: Vec<CompletionItem>,
+}
+
+impl Completions {
+ pub fn add(&mut self, item: CompletionItem) {
+ self.buf.push(item.into())
+ }
+
+ pub fn add_all<I>(&mut self, items: I)
+ where
+ I: IntoIterator,
+ I::Item: Into<CompletionItem>,
+ {
+ items.into_iter().for_each(|item| self.add(item.into()))
+ }
+}
+
+impl Into<Vec<CompletionItem>> for Completions {
+ fn into(self) -> Vec<CompletionItem> {
+ self.buf
+ }
+}
+
+impl Builder {
+ /// Convenience method, which allows to add a freshly created completion into accumulator
+ /// without binding it to the variable.
+ pub(crate) fn add_to(self, acc: &mut Completions) {
+ acc.add(self.build())
+ }
+}
use crate::{
context::CompletionContext,
generated_lint_completions::{CLIPPY_LINTS, FEATURES},
- item::{CompletionItem, CompletionItemKind, CompletionKind, Completions},
+ item::{CompletionItem, CompletionItemKind, CompletionKind},
+ Completions,
};
pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
}
if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner {
- acc.add(item);
+ acc.add(item.build());
}
}
}
label.push_str(", ");
label.push_str(dependency);
}
- acc.add(
- CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label)
- .kind(CompletionItemKind::Attribute),
- );
+ CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label)
+ .kind(CompletionItemKind::Attribute)
+ .add_to(acc)
}
for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) {
- acc.add(
- CompletionItem::new(
- CompletionKind::Attribute,
- ctx.source_range(),
- custom_derive_name,
- )
- .kind(CompletionItemKind::Attribute),
- );
+ CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), custom_derive_name)
+ .kind(CompletionItemKind::Attribute)
+ .add_to(acc)
}
}
}
.into_iter()
.filter(|completion| !existing_lints.contains(completion.label))
{
- acc.add(
- CompletionItem::new(
- CompletionKind::Attribute,
- ctx.source_range(),
- lint_completion.label,
- )
- .kind(CompletionItemKind::Attribute)
- .detail(lint_completion.description),
- );
+ CompletionItem::new(
+ CompletionKind::Attribute,
+ ctx.source_range(),
+ lint_completion.label,
+ )
+ .kind(CompletionItemKind::Attribute)
+ .detail(lint_completion.description)
+ .add_to(acc)
}
}
}
use rustc_hash::FxHashSet;
use test_utils::mark;
-use crate::{context::CompletionContext, item::Completions};
+use crate::{context::CompletionContext, Completions};
/// Complete dot accesses, i.e. fields or methods.
pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
use crate::{CompletionItem, CompletionItemKind};
-use crate::{context::CompletionContext, item::CompletionKind, item::Completions};
+use crate::{context::CompletionContext, item::CompletionKind, Completions};
/// Complete mod declaration, i.e. `mod <|> ;`
pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
if mod_under_caret.semicolon_token().is_none() {
label.push(';')
}
- acc.add(
- CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
- .kind(CompletionItemKind::Module),
- )
+ CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
+ .kind(CompletionItemKind::Module)
+ .add_to(acc)
});
Some(())
use crate::{
config::SnippetCap,
context::CompletionContext,
- item::{Builder, CompletionKind, Completions},
- CompletionItem, CompletionItemKind,
+ item::{Builder, CompletionKind},
+ CompletionItem, CompletionItemKind, Completions,
};
pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
use crate::{
completions::postfix::postfix_snippet, config::SnippetCap, context::CompletionContext,
- item::Completions,
+ Completions,
};
use syntax::ast::{self, AstToken};
}
impl Builder {
- pub(crate) fn add_to(self, acc: &mut Completions) {
- acc.add(self.build())
- }
-
pub(crate) fn build(self) -> CompletionItem {
let label = self.label;
let text_edit = match self.text_edit {
self.build()
}
}
-
-/// Represents an in-progress set of completions being built.
-#[derive(Debug, Default)]
-pub struct Completions {
- buf: Vec<CompletionItem>,
-}
-
-impl Completions {
- pub fn add(&mut self, item: impl Into<CompletionItem>) {
- self.buf.push(item.into())
- }
- pub fn add_all<I>(&mut self, items: I)
- where
- I: IntoIterator,
- I::Item: Into<CompletionItem>,
- {
- items.into_iter().for_each(|item| self.add(item.into()))
- }
-}
-
-impl Into<Vec<CompletionItem>> for Completions {
- fn into(self) -> Vec<CompletionItem> {
- self.buf
- }
-}
use ide_db::base_db::FilePosition;
use ide_db::RootDatabase;
-use crate::{
- context::CompletionContext,
- item::{CompletionKind, Completions},
-};
+use crate::{completions::Completions, context::CompletionContext, item::CompletionKind};
pub use crate::{
config::CompletionConfig,
let kind = match resolution {
ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::Module,
ScopeDef::ModuleDef(Function(func)) => {
- return self.add_function(ctx, *func, Some(local_name));
+ self.add_function(ctx, *func, Some(local_name));
+ return;
}
ScopeDef::ModuleDef(Adt(hir::Adt::Struct(_))) => CompletionItemKind::Struct,
// FIXME: add CompletionItemKind::Union
ScopeDef::ModuleDef(Adt(hir::Adt::Enum(_))) => CompletionItemKind::Enum,
ScopeDef::ModuleDef(EnumVariant(var)) => {
- return self.add_enum_variant(ctx, *var, Some(local_name));
+ self.add_enum_variant(ctx, *var, Some(local_name));
+ return;
}
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::Const,
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::Static,
// (does this need its own kind?)
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
ScopeDef::MacroDef(mac) => {
- return self.add_macro(ctx, Some(local_name), *mac);
+ self.add_macro(ctx, Some(local_name), *mac);
+ return;
}
ScopeDef::Unknown => {
- return self.add(
- CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
- .kind(CompletionItemKind::UnresolvedReference),
- );
+ CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name)
+ .kind(CompletionItemKind::UnresolvedReference)
+ .add_to(self);
+ return;
}
};
}
};
- self.add(builder);
+ self.add(builder.build());
}
pub(crate) fn add_function(
builder = builder.add_call_parens(ctx, name, Params::Named(params));
- self.add(builder)
+ self.add(builder.build())
}
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {