Commit graph

15827 commits

Author SHA1 Message Date
bors
79a578ae84 Auto merge of #13005 - pocket7878:convert-two-arm-bool-match-to-matches-macro, r=jonas-schievink
feature: Assist to turn match into matches! invocation

Resolves #12510

This PR adds an assist, which convert 2-arm match that evaluates to a boolean into the equivalent matches! invocation.
2022-08-31 13:47:40 +00:00
bors
cf05b7db4d Auto merge of #13051 - DropDemBits:attrs-and-comments-on-enum-variant, r=jonas-schievink
fix: Only move comments when extracting a struct from an enum variant

Motivating example:

```rs
#[derive(Debug, thiserror::Error)]
enum Error {
    /// Some explanation for this error
    #[error("message")]
    $0Woops {
        code: u32
    }
}
```
now becomes
```rs
/// Some explanation for this error
#[derive(Debug, thiserror::Error)]
struct Woops{
    code: u32
}

#[derive(Debug, thiserror::Error)]
enum Error {
    #[error("message")]
    Woops(Woops)
}
```
(the `thiserror::Error` derive being copied and the struct formatting aren't ideal, though those are issues for another day)
2022-08-31 13:34:43 +00:00
Pocket7878
7464b6dbc4 feature: Check if first_arm bool and second_arm bool is inverted or not. 2022-08-31 18:47:45 +09:00
Masato Sogame
5a1b45dcc1 feature: Simplfy branch check logics
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-08-31 18:47:45 +09:00
Pocket7878
a5d2463b1d fix: Simplify logics to allow two-arm enum match. 2022-08-31 18:47:45 +09:00
Pocket7878
4661a60aa9 Add convert_two_arm_bool_match_to_matches_macro ide-assists 2022-08-31 18:47:44 +09:00
bors
d9e22079c4 Auto merge of #12963 - DesmondWillowbrook:clippy-matches-sourcegen, r=Veykril
clippy: make generated code nice to read

Feel free to close if this is too minor.

(For context, I _have_ read the clippy policy in `dev/style.md`)
2022-08-31 08:37:14 +00:00
bors
56d888689b Auto merge of #12793 - lowr:fix/12739, r=Veykril
fix: sort and deduplicate auto traits in trait object types

Fixes #12739

Chalk solver doesn't sort and deduplicate auto traits in trait object types, so we need to handle them ourselves in the lowering phase, just like [`rustc`](880416180b/compiler/rustc_typeck/src/astconv/mod.rs (L1487-L1488)) and [`chalk-integration`](https://github.com/rust-lang/chalk/blob/master/chalk-integration/src/lowering.rs#L575) do.

Quoting from [the Chalk book](https://rust-lang.github.io/chalk/book/types/rust_types.html#dyn-types):

> Note that -- for this purpose -- ordering of bounds is significant. That means that if you create a `dyn Foo + Send` and a `dyn Send + Foo`, chalk would consider them distinct types. The assumption is that bounds are ordered in some canonical fashion somewhere else.

Also, trait object types with more than one non-auto traits were previously allowed, but are now disallowed with this patch.
2022-08-31 08:28:12 +00:00
bors
b6138965cd Auto merge of #13149 - lowr:fix/unescape-raw-ident-module-path, r=Veykril
fix: unescape all occurrences of module name in module resolution

Fixes #13141
2022-08-31 08:15:31 +00:00
bors
ef27641f56 Auto merge of #13154 - Veykril:ty-mac-expander, r=Veykril
Drop the expander borrow in all control flow paths

The change in https://github.com/rust-lang/rust-analyzer/pull/13123
actually re-uses the RefMut borrow instead of dropping it so we need to
drop it manually where required.

Fixes https://github.com/rust-lang/rust-analyzer/issues/13153
2022-08-31 08:07:26 +00:00
Lukas Wirth
5c0e25237c Drop the expander borrow in all control flow paths
The change in https://github.com/rust-lang/rust-analyzer/pull/13123
actually re-uses the RefMut borrow instead of dropping it so we need to
drop it manually where required.
2022-08-31 10:04:01 +02:00
bors
e0e18cc2a7 Auto merge of #13151 - ChayimFriedman2:replace-turbofish-other-type, r=Veykril
Use correct type in "Replace turbofish with type"

And support `?` and `.await` expressions.

Fixes #13148.

The assist can still show up even if the turbofish's type is not used at all, e.g.:
```rust
fn foo<T>() {}
let v = foo::<i32>();
```
2022-08-31 07:47:53 +00:00
Chayim Refael Friedman
bcdacfe501 Support ? and .await in "Replace turbofish with explicit type"
Now that we use type information this is easy.
2022-08-31 01:24:36 +00:00
Chayim Refael Friedman
e5e979906b Use type information to deduce the correct type for "Replace turbofish with explicit type", even when it is not exactly the same as the turbofish type
I implemented that by checking the expressions' type.
This could probably be implemented better by taking the function's return type and substituting the generic parameter with the provided turbofish, but this is more complicated.
2022-08-31 01:07:41 +00:00
Ryo Yoshida
662ab0cd8e
fix: unescape all occurrences of module name in module resolution 2022-08-31 03:51:37 +09:00
DropDemBits
45dac9a3ef Move comments to the extracted struct 2022-08-30 14:47:08 -04:00
bors
989b09d20c Auto merge of #13145 - ChayimFriedman2:unmerge-match-arm, r=jonas-schievink
feat: Add a "Unmerge match arm" assist to split or-patterns inside match expressions

Fixes #13072.

The way I implemented it it leaves the `OrPat` in place even if there is only one pattern now but I don't think something will break because of that, and when more code will be typed we'll parse it again anyway. Removing it (but keeping the child pattern) is hard, I don't know how to do that.
2022-08-30 13:31:37 +00:00
Ryo Yoshida
7ecead23c8
fix: sort and deduplicate auto traits in trait object types 2022-08-30 20:52:42 +09:00
Chayim Refael Friedman
5f132e666d feat: Add a "Unmerge match arm" assist to split or-patterns inside match expressions 2022-08-30 09:42:12 +00:00
bors
f02cd0a41d Auto merge of #13056 - DropDemBits:make-refactors, r=Veykril
internal: Migrate to using format arg captures in `syntax::make`
2022-08-29 16:34:33 +00:00
bors
e8e598f641 Auto merge of #13133 - Veykril:diag-hack, r=Veykril
Move empty diagnostics workaround back into the server

This only touches on the diagnostics in one place instead of multiple as was previously done, since all published diagnostics will go through this code path anyways.

Closes https://github.com/rust-lang/rust-analyzer/issues/13130
2022-08-28 09:56:06 +00:00
Lukas Wirth
9ad0a8c467 Move empty diagnostics workaround back into the server 2022-08-28 11:54:46 +02:00
Lukas Wirth
78a7a816bf minor: Simplify 2022-08-26 19:40:01 +02:00
bors
5c52e05498 Auto merge of #13110 - DesmondWillowbrook:issue-11197, r=jonas-schievink
fix: make "Extract type as type alias" assist work with const generics in array

fixes #11197
2022-08-26 13:35:13 +00:00
bors
ca8093e282 Auto merge of #13116 - Veykril:nohash, r=Veykril
Make use of NoHash hashing for FileId and CrateId

Both of these are mere integers so there is nothing to hash here.

Ideally we would use this for `la_arena::Idx` too, but that doesn't work due to the orphan rule, and `la_arena` is unfortunately a public library so we can't really do much here... Unless we remove the trait restriction but I'd like not to
2022-08-25 19:08:57 +00:00
Lukas Wirth
5b6aefe565 Update test fixtures 2022-08-25 21:07:24 +02:00
Lukas Wirth
0c9375b829 Remove u/i128 hashing overloads from NoHashHasher::Hasher impl 2022-08-25 20:45:35 +02:00
Lukas Wirth
d025c5d8d6 Make use of NoHash hashing for FileId and CrateId 2022-08-25 20:41:49 +02:00
Kartavya Vashishtha
0d7ba13b72
style: run tidy tests 2022-08-25 13:17:50 +05:30
Kartavya Vashishtha
9480b38189
extract const generic in ArrayType 2022-08-25 13:11:51 +05:30
Kartavya Vashishtha
71c15f2a44
add test 2022-08-25 13:11:14 +05:30
bors
e3dc5a588f Auto merge of #13101 - Veykril:sem-tokens, r=jonas-schievink
internal: Re-export standard semantic token types and mods

Should help in preventing future occurences of #13099 by having all token types and mods come through the same place
2022-08-23 16:24:39 +00:00
Lukas Wirth
715e3fc119 Re-export standard semantic token types and mods 2022-08-23 18:06:32 +02:00
bors
1456b80167 Auto merge of #13100 - jonas-schievink:doc-links-on-impl, r=jonas-schievink
fix: Resolve doc links on impl blocks

Fixes https://github.com/rust-lang/rust-analyzer/issues/13089
2022-08-23 15:57:12 +00:00
Jonas Schievink
322e7060de Resolve doc links on impl blocks 2022-08-23 17:50:45 +02:00
Jonas Schievink
5804412869 Register decorator token type to avoid panic 2022-08-23 17:46:29 +02:00
Jonas Schievink
8969655ed6 Allow leading | in more pattern positions 2022-08-23 16:31:59 +02:00
bors
f045f14626 Auto merge of #13084 - Veykril:highlight-config, r=Veykril
Add some more highlighting configurations

The following can be enabled/disabled now in terms of highlighting:
- doc comment injection (enabled by default)
- punctuation highlighting (disabled by default)
- operator highlighting (enabled by default)
- punctuation specialized highlighting (disabled by default)
- operator specialized highlighting (disabled by default)
- macro call bang highlighting (disabled by default)

This PR also changes our `attribute` semantic token type to the `decorator` type which landed upstream (but not yet in lsp-types).

Specialized highlighting is disabled by default, as all clients will have to ship something to map these back to the standard punctuation/operator token (we do this in VSCode via the inheritance mapping for example). This is a lot of maintenance work, and not something every client wants to do, pushing that need to use the user. As this is a rather niche use in the first place this will just be disabled by default.

Punctuation highlighting is disabled by default, punctuation is usually something that can be done by the native syntactic highlighting of the client, so there is no loss in quality. The main reason for this though is that punctuation adds a lot of extra token data that we sent over, a lot of clients struggle with applying this, so disabling this improves the UX for a lot of people. Note that we still highlight punctuations with special meaning as that special entity, (the never type `!` will still be tagged as a builtin type if it occurs as such)

Separate highlighting of the macro call bang `!` is disabled by default, as I think people actually didn't like that change that much, though at the same time I feel like not many people even noticed that change (I prefer it be separate, but that's not enough reason for it to be enabled by default I believe :^) )

cc https://github.com/rust-lang/rust-analyzer/issues/12783 https://github.com/rust-lang/rust-analyzer/issues/13066
2022-08-23 12:39:57 +00:00
bors
631ed2a518 Auto merge of #13092 - Veykril:ref-match-completion, r=Veykril
fix: Fix reference autocompletions using incorrect offsets in macro inputs

Fixes https://github.com/rust-lang/rust-analyzer/issues/13035
2022-08-23 12:30:50 +00:00
Lukas Wirth
6c5d15800e fix: Fix reference autocompletions using incorrect offsets in macro inputs
Fixes https://github.com/rust-lang/rust-analyzer/issues/13035
2022-08-23 14:29:59 +02:00
Lukas Wirth
2a26b054b7 Use lsp-types DECORATOR token type 2022-08-23 14:06:19 +02:00
Lukas Wirth
31fb917d8d Remove unused default semantic modifiers 2022-08-23 14:05:56 +02:00
Lukas Wirth
eadc2673c0 Regen docs 2022-08-23 14:05:56 +02:00
Lukas Wirth
f6f0516603 Add config for macro bang token highlighting, disable by default 2022-08-23 14:05:56 +02:00
Lukas Wirth
b26733f8a0 Change attribute semantic token type to decorator 2022-08-23 14:05:56 +02:00
Lukas Wirth
9700c95ced Make doc comment highlight injection configurable 2022-08-23 14:05:55 +02:00
Lukas Wirth
9a201873b8 Move highlight configuration from protocol into the feature 2022-08-23 14:05:55 +02:00
Lukas Wirth
afc8cfb4d1 Make operator highlighting configurable, disable it by default 2022-08-23 14:05:55 +02:00
Lukas Wirth
16315edaee Make punctuation highlighting configurable, disable it by default 2022-08-23 14:05:55 +02:00
bors
6627b473e2 Auto merge of #13090 - ice1k:master, r=Veykril
Do not substitute `Self` when in same impl block

Fix #13076
2022-08-23 08:08:45 +00:00