6816: Use natural trait ordering in derive completion r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-12-11 12:46:47 +00:00 committed by GitHub
commit 15a644d606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 136 deletions

View file

@ -3,6 +3,7 @@
//! This module uses a bit of static metadata to provide completions //! This module uses a bit of static metadata to provide completions
//! for built-in attributes. //! for built-in attributes.
use itertools::Itertools;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use syntax::{ast, AstNode, SyntaxKind}; use syntax::{ast, AstNode, SyntaxKind};
@ -162,19 +163,20 @@ const ATTRIBUTES: &[AttrCompletion] = &[
fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) {
if let Ok(existing_derives) = parse_comma_sep_input(derive_input) { if let Ok(existing_derives) = parse_comma_sep_input(derive_input) {
for derive_completion in DEFAULT_DERIVE_COMPLETIONS for derive_completion in DEFAULT_DERIVE_COMPLETIONS
.into_iter() .iter()
.filter(|completion| !existing_derives.contains(completion.label)) .filter(|completion| !existing_derives.contains(completion.label))
{ {
let mut label = derive_completion.label.to_owned(); let mut components = vec![derive_completion.label];
for dependency in derive_completion components.extend(
derive_completion
.dependencies .dependencies
.into_iter() .iter()
.filter(|&&dependency| !existing_derives.contains(dependency)) .filter(|&&dependency| !existing_derives.contains(dependency)),
{ );
label.push_str(", "); let lookup = components.join(", ");
label.push_str(dependency); let label = components.iter().rev().join(", ");
}
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label) CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label)
.lookup_by(lookup)
.kind(CompletionItemKind::Attribute) .kind(CompletionItemKind::Attribute)
.add_to(acc) .add_to(acc)
} }
@ -264,7 +266,6 @@ struct DeriveCompletion {
/// Standard Rust derives and the information about their dependencies /// Standard Rust derives and the information about their dependencies
/// (the dependencies are needed so that the main derive don't break the compilation when added) /// (the dependencies are needed so that the main derive don't break the compilation when added)
#[rustfmt::skip]
const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[
DeriveCompletion { label: "Clone", dependencies: &[] }, DeriveCompletion { label: "Clone", dependencies: &[] },
DeriveCompletion { label: "Copy", dependencies: &["Clone"] }, DeriveCompletion { label: "Copy", dependencies: &["Clone"] },
@ -421,14 +422,14 @@ struct Test {}
"#, "#,
expect![[r#" expect![[r#"
at Clone at Clone
at Copy, Clone at Clone, Copy
at Debug at Debug
at Default at Default
at Eq, PartialEq
at Hash at Hash
at Ord, PartialOrd, Eq, PartialEq
at PartialEq at PartialEq
at PartialOrd, PartialEq at PartialEq, Eq
at PartialEq, Eq, PartialOrd, Ord
at PartialEq, PartialOrd
"#]], "#]],
); );
} }
@ -453,12 +454,12 @@ struct Test {}
"#, "#,
expect![[r#" expect![[r#"
at Clone at Clone
at Copy, Clone at Clone, Copy
at Debug at Debug
at Default at Default
at Eq at Eq
at Eq, PartialOrd, Ord
at Hash at Hash
at Ord, PartialOrd, Eq
at PartialOrd at PartialOrd
"#]], "#]],
) )

View file

@ -1,119 +0,0 @@
//Generated file, do not edit by hand, see `xtask/src/codegen`
=== break-outside-of-loop
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L219[diagnostics.rs]
This diagnostic is triggered if `break` keyword is used outside of a loop.
=== inactive-code
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L98[diagnostics.rs]
This diagnostic is shown for code with inactive `#[cfg]` attributes.
=== incorrect-ident-case
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L319[diagnostics.rs]
This diagnostic is triggered if item name doesn't follow https://doc.rust-lang.org/1.0.0/style/style/naming/README.html[Rust naming convention].
=== macro-error
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L167[diagnostics.rs]
This diagnostic is shown for macro expansion errors.
=== mismatched-arg-count
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L267[diagnostics.rs]
This diagnostic is triggered if function is invoked with an incorrect amount of arguments.
=== missing-match-arm
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L162[diagnostics.rs]
This diagnostic is triggered if `match` block is missing one or more match arms.
=== missing-ok-in-tail-expr
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L187[diagnostics.rs]
This diagnostic is triggered if block that should return `Result` returns a value not wrapped in `Ok`.
Example:
```rust
fn foo() -> Result<u8, ()> {
10
}
```
=== missing-pat-fields
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L113[diagnostics.rs]
This diagnostic is triggered if pattern lacks some fields that exist in the corresponding structure.
Example:
```rust
struct A { a: u8, b: u8 }
let a = A { a: 10, b: 20 };
if let A { a } = a {
// ...
}
```
=== missing-structure-fields
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L66[diagnostics.rs]
This diagnostic is triggered if record lacks some fields that exist in the corresponding structure.
Example:
```rust
struct A { a: u8, b: u8 }
let a = A { a: 10 };
```
=== missing-unsafe
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L243[diagnostics.rs]
This diagnostic is triggered if operation marked as `unsafe` is used outside of `unsafe` function or block.
=== no-such-field
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L39[diagnostics.rs]
This diagnostic is triggered if created structure does not have field provided in record.
=== unresolved-extern-crate
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L43[diagnostics.rs]
This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate.
=== unresolved-import
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L67[diagnostics.rs]
This diagnostic is triggered if rust-analyzer is unable to discover imported module.
=== unresolved-module
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L18[diagnostics.rs]
This diagnostic is triggered if rust-analyzer is unable to discover referred module.
=== unresolved-proc-macro
**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L131[diagnostics.rs]
This diagnostic is shown when a procedural macro can not be found. This usually means that
procedural macro support is simply disabled (and hence is only a weak hint instead of an error),
but can also indicate project setup problems.