Skip to content

Commit 15a644d

Browse files
bors[bot]matklad
andauthored
Merge #6816
6816: Use natural trait ordering in derive completion r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 41321d9 + e179ed6 commit 15a644d

File tree

2 files changed

+18
-136
lines changed

2 files changed

+18
-136
lines changed

crates/completion/src/completions/attribute.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module uses a bit of static metadata to provide completions
44
//! for built-in attributes.
55
6+
use itertools::Itertools;
67
use rustc_hash::FxHashSet;
78
use syntax::{ast, AstNode, SyntaxKind};
89

@@ -162,19 +163,20 @@ const ATTRIBUTES: &[AttrCompletion] = &[
162163
fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) {
163164
if let Ok(existing_derives) = parse_comma_sep_input(derive_input) {
164165
for derive_completion in DEFAULT_DERIVE_COMPLETIONS
165-
.into_iter()
166+
.iter()
166167
.filter(|completion| !existing_derives.contains(completion.label))
167168
{
168-
let mut label = derive_completion.label.to_owned();
169-
for dependency in derive_completion
170-
.dependencies
171-
.into_iter()
172-
.filter(|&&dependency| !existing_derives.contains(dependency))
173-
{
174-
label.push_str(", ");
175-
label.push_str(dependency);
176-
}
169+
let mut components = vec![derive_completion.label];
170+
components.extend(
171+
derive_completion
172+
.dependencies
173+
.iter()
174+
.filter(|&&dependency| !existing_derives.contains(dependency)),
175+
);
176+
let lookup = components.join(", ");
177+
let label = components.iter().rev().join(", ");
177178
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label)
179+
.lookup_by(lookup)
178180
.kind(CompletionItemKind::Attribute)
179181
.add_to(acc)
180182
}
@@ -264,7 +266,6 @@ struct DeriveCompletion {
264266

265267
/// Standard Rust derives and the information about their dependencies
266268
/// (the dependencies are needed so that the main derive don't break the compilation when added)
267-
#[rustfmt::skip]
268269
const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[
269270
DeriveCompletion { label: "Clone", dependencies: &[] },
270271
DeriveCompletion { label: "Copy", dependencies: &["Clone"] },
@@ -421,14 +422,14 @@ struct Test {}
421422
"#,
422423
expect![[r#"
423424
at Clone
424-
at Copy, Clone
425+
at Clone, Copy
425426
at Debug
426427
at Default
427-
at Eq, PartialEq
428428
at Hash
429-
at Ord, PartialOrd, Eq, PartialEq
430429
at PartialEq
431-
at PartialOrd, PartialEq
430+
at PartialEq, Eq
431+
at PartialEq, Eq, PartialOrd, Ord
432+
at PartialEq, PartialOrd
432433
"#]],
433434
);
434435
}
@@ -453,12 +454,12 @@ struct Test {}
453454
"#,
454455
expect![[r#"
455456
at Clone
456-
at Copy, Clone
457+
at Clone, Copy
457458
at Debug
458459
at Default
459460
at Eq
461+
at Eq, PartialOrd, Ord
460462
at Hash
461-
at Ord, PartialOrd, Eq
462463
at PartialOrd
463464
"#]],
464465
)

docs/user/generated_diagnostic.adoc

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)