Fix some clippy lints in ide_completion

This commit is contained in:
Lukas Wirth 2021-07-21 19:50:28 +02:00
parent ccde0bcd1f
commit 9485d6efba
10 changed files with 34 additions and 41 deletions

View File

@ -32,7 +32,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
Some("target_vendor") => KNOWN_VENDOR.iter().for_each(add_completion), Some("target_vendor") => KNOWN_VENDOR.iter().for_each(add_completion),
Some("target_endian") => ["little", "big"].iter().for_each(add_completion), Some("target_endian") => ["little", "big"].iter().for_each(add_completion),
Some(name) => { Some(name) => {
ctx.krate.map(|krate| { if let Some(krate) = ctx.krate {
krate.potential_cfg(ctx.db).get_cfg_values(&name).iter().for_each(|s| { krate.potential_cfg(ctx.db).get_cfg_values(&name).iter().for_each(|s| {
let mut item = CompletionItem::new( let mut item = CompletionItem::new(
CompletionKind::Attribute, CompletionKind::Attribute,
@ -43,10 +43,10 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
acc.add(item.build()); acc.add(item.build());
}) })
}); };
} }
None => { None => {
ctx.krate.map(|krate| { if let Some(krate) = ctx.krate {
krate.potential_cfg(ctx.db).get_cfg_keys().iter().for_each(|s| { krate.potential_cfg(ctx.db).get_cfg_keys().iter().for_each(|s| {
let item = CompletionItem::new( let item = CompletionItem::new(
CompletionKind::Attribute, CompletionKind::Attribute,
@ -55,12 +55,12 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
); );
acc.add(item.build()); acc.add(item.build());
}) })
}); }
} }
}; };
} }
const KNOWN_ARCH: [&'static str; 19] = [ const KNOWN_ARCH: [&str; 19] = [
"aarch64", "aarch64",
"arm", "arm",
"avr", "avr",
@ -82,10 +82,9 @@ const KNOWN_ARCH: [&'static str; 19] = [
"x86_64", "x86_64",
]; ];
const KNOWN_ENV: [&'static str; 7] = const KNOWN_ENV: [&str; 7] = ["eabihf", "gnu", "gnueabihf", "msvc", "relibc", "sgx", "uclibc"];
["eabihf", "gnu", "gnueabihf", "msvc", "relibc", "sgx", "uclibc"];
const KNOWN_OS: [&'static str; 20] = [ const KNOWN_OS: [&str; 20] = [
"cuda", "cuda",
"dragonfly", "dragonfly",
"emscripten", "emscripten",
@ -108,5 +107,5 @@ const KNOWN_OS: [&'static str; 20] = [
"windows", "windows",
]; ];
const KNOWN_VENDOR: [&'static str; 8] = const KNOWN_VENDOR: [&str; 8] =
["apple", "fortanix", "nvidia", "pc", "sony", "unknown", "wrs", "uwp"]; ["apple", "fortanix", "nvidia", "pc", "sony", "unknown", "wrs", "uwp"];

View File

@ -15,9 +15,8 @@ pub(super) fn complete_lint(
lints_completions: &[Lint], lints_completions: &[Lint],
) { ) {
if let Some(existing_lints) = super::parse_comma_sep_input(derive_input) { if let Some(existing_lints) = super::parse_comma_sep_input(derive_input) {
for lint_completion in lints_completions for lint_completion in
.into_iter() lints_completions.iter().filter(|completion| !existing_lints.contains(completion.label))
.filter(|completion| !existing_lints.contains(completion.label))
{ {
let mut item = CompletionItem::new( let mut item = CompletionItem::new(
CompletionKind::Attribute, CompletionKind::Attribute,

View File

@ -322,8 +322,8 @@ fn postfix_snippet(
let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label); let mut item = CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label);
item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit); item.detail(detail).kind(CompletionItemKind::Snippet).snippet_edit(cap, edit);
if ctx.original_token.text() == label { if ctx.original_token.text() == label {
let mut relevance = CompletionRelevance::default(); let relevance =
relevance.exact_postfix_snippet_match = true; CompletionRelevance { exact_postfix_snippet_match: true, ..Default::default() };
item.set_relevance(relevance); item.set_relevance(relevance);
} }

View File

@ -51,7 +51,7 @@ pub(crate) fn add_format_like_completions(
if parser.parse().is_ok() { if parser.parse().is_ok() {
for (label, macro_name) in KINDS { for (label, macro_name) in KINDS {
let snippet = parser.into_suggestion(macro_name); let snippet = parser.to_suggestion(macro_name);
postfix_snippet(ctx, cap, dot_receiver, label, macro_name, &snippet).add_to(acc); postfix_snippet(ctx, cap, dot_receiver, label, macro_name, &snippet).add_to(acc);
} }
@ -201,7 +201,7 @@ impl FormatStrParser {
Ok(()) Ok(())
} }
pub(crate) fn into_suggestion(&self, macro_name: &str) -> String { pub(crate) fn to_suggestion(&self, macro_name: &str) -> String {
assert!(self.parsed, "Attempt to get a suggestion from not parsed expression"); assert!(self.parsed, "Attempt to get a suggestion from not parsed expression");
let expressions_as_string = self.extracted_expressions.join(", "); let expressions_as_string = self.extracted_expressions.join(", ");
@ -283,7 +283,7 @@ mod tests {
let mut parser = FormatStrParser::new((*input).to_owned()); let mut parser = FormatStrParser::new((*input).to_owned());
parser.parse().expect("Parsing must succeed"); parser.parse().expect("Parsing must succeed");
assert_eq!(&parser.into_suggestion(*kind), output); assert_eq!(&parser.to_suggestion(*kind), output);
} }
} }
} }

View File

@ -12,10 +12,7 @@ use crate::{
render::RenderContext, render::RenderContext,
}; };
pub(crate) fn render_const<'a>( pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
ctx: RenderContext<'a>,
const_: hir::Const,
) -> Option<CompletionItem> {
ConstRender::new(ctx, const_)?.render() ConstRender::new(ctx, const_)?.render()
} }
@ -50,7 +47,7 @@ impl<'a> ConstRender<'a> {
if let Some(actm) = self.const_.as_assoc_item(db) { if let Some(actm) = self.const_.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) { if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
item.trait_name(trt.name(db).to_string()); item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone()); item.insert_text(name);
} }
} }

View File

@ -12,8 +12,8 @@ use crate::{
CompletionRelevance, CompletionRelevance,
}; };
pub(crate) fn render_variant<'a>( pub(crate) fn render_variant(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>, import_to_add: Option<ImportEdit>,
local_name: Option<hir::Name>, local_name: Option<hir::Name>,
variant: hir::Variant, variant: hir::Variant,

View File

@ -13,8 +13,8 @@ use crate::{
}, },
}; };
pub(crate) fn render_fn<'a>( pub(crate) fn render_fn(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>, import_to_add: Option<ImportEdit>,
local_name: Option<hir::Name>, local_name: Option<hir::Name>,
fn_: hir::Function, fn_: hir::Function,
@ -23,8 +23,8 @@ pub(crate) fn render_fn<'a>(
Some(FunctionRender::new(ctx, None, local_name, fn_, false)?.render(import_to_add)) Some(FunctionRender::new(ctx, None, local_name, fn_, false)?.render(import_to_add))
} }
pub(crate) fn render_method<'a>( pub(crate) fn render_method(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>, import_to_add: Option<ImportEdit>,
receiver: Option<hir::Name>, receiver: Option<hir::Name>,
local_name: Option<hir::Name>, local_name: Option<hir::Name>,

View File

@ -10,8 +10,8 @@ use crate::{
render::RenderContext, render::RenderContext,
}; };
pub(crate) fn render_macro<'a>( pub(crate) fn render_macro(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
import_to_add: Option<ImportEdit>, import_to_add: Option<ImportEdit>,
name: hir::Name, name: hir::Name,
macro_: hir::MacroDef, macro_: hir::MacroDef,
@ -76,12 +76,10 @@ impl<'a> MacroRender<'a> {
fn label(&self) -> String { fn label(&self) -> String {
if self.needs_bang() && self.ctx.snippet_cap().is_some() { if self.needs_bang() && self.ctx.snippet_cap().is_some() {
format!("{}!{}{}", self.name, self.bra, self.ket) format!("{}!{}{}", self.name, self.bra, self.ket)
} else if self.macro_.kind() == hir::MacroKind::Derive {
self.name.to_string()
} else { } else {
if self.macro_.kind() == hir::MacroKind::Derive { self.banged_name()
self.name.to_string()
} else {
self.banged_name()
}
} }
} }

View File

@ -139,7 +139,7 @@ fn visible_fields(
let module = ctx.completion.scope.module()?; let module = ctx.completion.scope.module()?;
let n_fields = fields.len(); let n_fields = fields.len();
let fields = fields let fields = fields
.into_iter() .iter()
.filter(|field| field.is_visible_from(ctx.db(), module)) .filter(|field| field.is_visible_from(ctx.db(), module))
.copied() .copied()
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@ -12,15 +12,15 @@ use crate::{
render::RenderContext, render::RenderContext,
}; };
pub(crate) fn render_type_alias<'a>( pub(crate) fn render_type_alias(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
type_alias: hir::TypeAlias, type_alias: hir::TypeAlias,
) -> Option<CompletionItem> { ) -> Option<CompletionItem> {
TypeAliasRender::new(ctx, type_alias)?.render(false) TypeAliasRender::new(ctx, type_alias)?.render(false)
} }
pub(crate) fn render_type_alias_with_eq<'a>( pub(crate) fn render_type_alias_with_eq(
ctx: RenderContext<'a>, ctx: RenderContext<'_>,
type_alias: hir::TypeAlias, type_alias: hir::TypeAlias,
) -> Option<CompletionItem> { ) -> Option<CompletionItem> {
TypeAliasRender::new(ctx, type_alias)?.render(true) TypeAliasRender::new(ctx, type_alias)?.render(true)
@ -63,7 +63,7 @@ impl<'a> TypeAliasRender<'a> {
if let Some(actm) = self.type_alias.as_assoc_item(db) { if let Some(actm) = self.type_alias.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) { if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
item.trait_name(trt.name(db).to_string()); item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone()); item.insert_text(name);
} }
} }