diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-11 12:46:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-11 12:46:47 +0000 |
commit | 15a644d6063aac86a5eb387412b96b824c67ded3 (patch) | |
tree | 92894ee2330fe3112f224b7f41d73147cf31c9b1 | |
parent | 41321d96789ed918eebda02ada76758765d19d16 (diff) | |
parent | e179ed6f532e976d50c286c3349f2dddd7de6928 (diff) |
Merge #6816
6816: Use natural trait ordering in derive completion r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/completion/src/completions/attribute.rs | 35 | ||||
-rw-r--r-- | docs/user/generated_diagnostic.adoc | 119 |
2 files changed, 18 insertions, 136 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/docs/user/generated_diagnostic.adoc b/docs/user/generated_diagnostic.adoc deleted file mode 100644 index ec8581a03..000000000 --- a/docs/user/generated_diagnostic.adoc +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | //Generated file, do not edit by hand, see `xtask/src/codegen` | ||
2 | === break-outside-of-loop | ||
3 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L219[diagnostics.rs] | ||
4 | |||
5 | This diagnostic is triggered if `break` keyword is used outside of a loop. | ||
6 | |||
7 | |||
8 | === inactive-code | ||
9 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L98[diagnostics.rs] | ||
10 | |||
11 | This diagnostic is shown for code with inactive `#[cfg]` attributes. | ||
12 | |||
13 | |||
14 | === incorrect-ident-case | ||
15 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L319[diagnostics.rs] | ||
16 | |||
17 | 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]. | ||
18 | |||
19 | |||
20 | === macro-error | ||
21 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L167[diagnostics.rs] | ||
22 | |||
23 | This diagnostic is shown for macro expansion errors. | ||
24 | |||
25 | |||
26 | === mismatched-arg-count | ||
27 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L267[diagnostics.rs] | ||
28 | |||
29 | This diagnostic is triggered if function is invoked with an incorrect amount of arguments. | ||
30 | |||
31 | |||
32 | === missing-match-arm | ||
33 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L162[diagnostics.rs] | ||
34 | |||
35 | This diagnostic is triggered if `match` block is missing one or more match arms. | ||
36 | |||
37 | |||
38 | === missing-ok-in-tail-expr | ||
39 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L187[diagnostics.rs] | ||
40 | |||
41 | This diagnostic is triggered if block that should return `Result` returns a value not wrapped in `Ok`. | ||
42 | |||
43 | Example: | ||
44 | |||
45 | ```rust | ||
46 | fn foo() -> Result<u8, ()> { | ||
47 | 10 | ||
48 | } | ||
49 | ``` | ||
50 | |||
51 | |||
52 | === missing-pat-fields | ||
53 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L113[diagnostics.rs] | ||
54 | |||
55 | This diagnostic is triggered if pattern lacks some fields that exist in the corresponding structure. | ||
56 | |||
57 | Example: | ||
58 | |||
59 | ```rust | ||
60 | struct A { a: u8, b: u8 } | ||
61 | |||
62 | let a = A { a: 10, b: 20 }; | ||
63 | |||
64 | if let A { a } = a { | ||
65 | // ... | ||
66 | } | ||
67 | ``` | ||
68 | |||
69 | |||
70 | === missing-structure-fields | ||
71 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L66[diagnostics.rs] | ||
72 | |||
73 | This diagnostic is triggered if record lacks some fields that exist in the corresponding structure. | ||
74 | |||
75 | Example: | ||
76 | |||
77 | ```rust | ||
78 | struct A { a: u8, b: u8 } | ||
79 | |||
80 | let a = A { a: 10 }; | ||
81 | ``` | ||
82 | |||
83 | |||
84 | === missing-unsafe | ||
85 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L243[diagnostics.rs] | ||
86 | |||
87 | This diagnostic is triggered if operation marked as `unsafe` is used outside of `unsafe` function or block. | ||
88 | |||
89 | |||
90 | === no-such-field | ||
91 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/diagnostics.rs#L39[diagnostics.rs] | ||
92 | |||
93 | This diagnostic is triggered if created structure does not have field provided in record. | ||
94 | |||
95 | |||
96 | === unresolved-extern-crate | ||
97 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L43[diagnostics.rs] | ||
98 | |||
99 | This diagnostic is triggered if rust-analyzer is unable to discover referred extern crate. | ||
100 | |||
101 | |||
102 | === unresolved-import | ||
103 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L67[diagnostics.rs] | ||
104 | |||
105 | This diagnostic is triggered if rust-analyzer is unable to discover imported module. | ||
106 | |||
107 | |||
108 | === unresolved-module | ||
109 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L18[diagnostics.rs] | ||
110 | |||
111 | This diagnostic is triggered if rust-analyzer is unable to discover referred module. | ||
112 | |||
113 | |||
114 | === unresolved-proc-macro | ||
115 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/diagnostics.rs#L131[diagnostics.rs] | ||
116 | |||
117 | This diagnostic is shown when a procedural macro can not be found. This usually means that | ||
118 | procedural macro support is simply disabled (and hence is only a weak hint instead of an error), | ||
119 | but can also indicate project setup problems. | ||