diff options
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/attribute.rs | 35 | ||||
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 2 | ||||
-rw-r--r-- | crates/completion/src/render/function.rs | 2 |
3 files changed, 20 insertions, 19 deletions
diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs index 5404145d5..acce2e7e7 100644 --- a/crates/completion/src/completions/attribute.rs +++ b/crates/completion/src/completions/attribute.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | //! This module uses a bit of static metadata to provide completions | 3 | //! This module uses a bit of static metadata to provide completions |
4 | //! for built-in attributes. | 4 | //! for built-in attributes. |
5 | 5 | ||
6 | use itertools::Itertools; | ||
6 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
7 | use syntax::{ast, AstNode, SyntaxKind}; | 8 | use syntax::{ast, AstNode, SyntaxKind}; |
8 | 9 | ||
@@ -162,19 +163,20 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
162 | fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { | 163 | fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { |
163 | if let Ok(existing_derives) = parse_comma_sep_input(derive_input) { | 164 | if let Ok(existing_derives) = parse_comma_sep_input(derive_input) { |
164 | for derive_completion in DEFAULT_DERIVE_COMPLETIONS | 165 | for derive_completion in DEFAULT_DERIVE_COMPLETIONS |
165 | .into_iter() | 166 | .iter() |
166 | .filter(|completion| !existing_derives.contains(completion.label)) | 167 | .filter(|completion| !existing_derives.contains(completion.label)) |
167 | { | 168 | { |
168 | let mut label = derive_completion.label.to_owned(); | 169 | let mut components = vec![derive_completion.label]; |
169 | for dependency in derive_completion | 170 | components.extend( |
170 | .dependencies | 171 | derive_completion |
171 | .into_iter() | 172 | .dependencies |
172 | .filter(|&&dependency| !existing_derives.contains(dependency)) | 173 | .iter() |
173 | { | 174 | .filter(|&&dependency| !existing_derives.contains(dependency)), |
174 | label.push_str(", "); | 175 | ); |
175 | label.push_str(dependency); | 176 | let lookup = components.join(", "); |
176 | } | 177 | let label = components.iter().rev().join(", "); |
177 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label) | 178 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label) |
179 | .lookup_by(lookup) | ||
178 | .kind(CompletionItemKind::Attribute) | 180 | .kind(CompletionItemKind::Attribute) |
179 | .add_to(acc) | 181 | .add_to(acc) |
180 | } | 182 | } |
@@ -264,7 +266,6 @@ struct DeriveCompletion { | |||
264 | 266 | ||
265 | /// Standard Rust derives and the information about their dependencies | 267 | /// Standard Rust derives and the information about their dependencies |
266 | /// (the dependencies are needed so that the main derive don't break the compilation when added) | 268 | /// (the dependencies are needed so that the main derive don't break the compilation when added) |
267 | #[rustfmt::skip] | ||
268 | const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ | 269 | const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ |
269 | DeriveCompletion { label: "Clone", dependencies: &[] }, | 270 | DeriveCompletion { label: "Clone", dependencies: &[] }, |
270 | DeriveCompletion { label: "Copy", dependencies: &["Clone"] }, | 271 | DeriveCompletion { label: "Copy", dependencies: &["Clone"] }, |
@@ -421,14 +422,14 @@ struct Test {} | |||
421 | "#, | 422 | "#, |
422 | expect![[r#" | 423 | expect![[r#" |
423 | at Clone | 424 | at Clone |
424 | at Copy, Clone | 425 | at Clone, Copy |
425 | at Debug | 426 | at Debug |
426 | at Default | 427 | at Default |
427 | at Eq, PartialEq | ||
428 | at Hash | 428 | at Hash |
429 | at Ord, PartialOrd, Eq, PartialEq | ||
430 | at PartialEq | 429 | at PartialEq |
431 | at PartialOrd, PartialEq | 430 | at PartialEq, Eq |
431 | at PartialEq, Eq, PartialOrd, Ord | ||
432 | at PartialEq, PartialOrd | ||
432 | "#]], | 433 | "#]], |
433 | ); | 434 | ); |
434 | } | 435 | } |
@@ -453,12 +454,12 @@ struct Test {} | |||
453 | "#, | 454 | "#, |
454 | expect![[r#" | 455 | expect![[r#" |
455 | at Clone | 456 | at Clone |
456 | at Copy, Clone | 457 | at Clone, Copy |
457 | at Debug | 458 | at Debug |
458 | at Default | 459 | at Default |
459 | at Eq | 460 | at Eq |
461 | at Eq, PartialOrd, Ord | ||
460 | at Hash | 462 | at Hash |
461 | at Ord, PartialOrd, Eq | ||
462 | at PartialOrd | 463 | at PartialOrd |
463 | "#]], | 464 | "#]], |
464 | ) | 465 | ) |
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 2b0924ae5..b9315f6c0 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -147,7 +147,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
147 | .filter_map(|(import_path, definition)| { | 147 | .filter_map(|(import_path, definition)| { |
148 | render_resolution_with_import( | 148 | render_resolution_with_import( |
149 | RenderContext::new(ctx), | 149 | RenderContext::new(ctx), |
150 | ImportEdit { import_path: import_path.clone(), import_scope: import_scope.clone() }, | 150 | ImportEdit { import_path, import_scope: import_scope.clone() }, |
151 | &definition, | 151 | &definition, |
152 | ) | 152 | ) |
153 | }); | 153 | }); |
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index d16005249..316e05b52 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs | |||
@@ -91,7 +91,7 @@ impl<'a> FunctionRender<'a> { | |||
91 | .zip(params_ty) | 91 | .zip(params_ty) |
92 | .flat_map(|(pat, param_ty)| { | 92 | .flat_map(|(pat, param_ty)| { |
93 | let pat = pat?; | 93 | let pat = pat?; |
94 | let name = pat.to_string(); | 94 | let name = pat; |
95 | let arg = name.trim_start_matches("mut ").trim_start_matches('_'); | 95 | let arg = name.trim_start_matches("mut ").trim_start_matches('_'); |
96 | Some(self.add_arg(arg, param_ty.ty())) | 96 | Some(self.add_arg(arg, param_ty.ty())) |
97 | }) | 97 | }) |