Commit graph

16574 commits

Author SHA1 Message Date
Maybe Waffle
7ed0871ff6 Fix "needs parens" check in remove_parentheses assist 2022-12-13 00:06:00 +00:00
bors
4596847a88 Auto merge of #13746 - feniljain:fix_extract_function, r=jonas-schievink
fix: make make_body respect comments in extract_function

Possible fix for #13621

### Points to help in review:

- Earlier we were only considering statements in a block expr and hence comments were being ignored, now we handle tokens hence making it aware of comments and then preserving them using `hacky_block_expr_with_comments`

Seems like I am not able to attach output video, github is glitching for it :(
2022-12-12 14:51:03 +00:00
bors
15ff8a5a9f Auto merge of #13715 - feniljain:fix_completions, r=jonas-schievink
fix: breaking snippets on typed incomplete suggestions

Possible fix for #7929

Fix the case where if a user types `&&42.o`, snippet completion was still applying &&Ok(42). Note this was fixed previously on `&&42.` but this still remained a problem for this case

Previous relevant PR: #13517

### Points to help in review:

- The main problem why everything broke on adding an extra `o` was, earlier `dot_receiver` was `42.` which was a `LITERAL` but now `42.o` becomes a `FIELD_EXPR`

- Till now `include_references` was just checking for parent of `LITERAL` and if it was a `REF_EXPR`, but now we consider `FIELD_EXPR` and traverse all of them, finally to reach `REF_EXPR`. If `REF_EXPR` is not found we  just return the original `initial_element`

- We are constructing a new node during `include_references` because if we rely on `dot_receiver` solely we would get `&&42.o` to be replaced with, but we want `&&42` to be replaced with

### Output Video:

https://user-images.githubusercontent.com/49019259/205420166-efbdef78-5b3a-4aef-ab4b-d892dac056a0.mov

Hope everything I wrote makes sense 😅

Also interestingly previous PR's number was `13517` and this PR's number is `13715`, nicee
2022-12-12 14:37:45 +00:00
bors
e7dff7491a Auto merge of #13726 - feniljain:fix_assists, r=jonas-schievink
feat: allow unwrap block in let initializers

Possible fix for #13679

### Points to help in review:

- I just added a parent case for let statements and it seems everything else was in place already, so turned out to be a small fix
2022-12-12 14:06:45 +00:00
bors
3a7215b92e Auto merge of #13732 - rami3l:fix/gen-partial-eq, r=jonas-schievink
fix: add fallback case in generated `PartialEq` impl

Partially fixes #13727.

When generating `PartialEq` implementations for enums, the original code can already generate the following fallback case:

```rs
_ => std::mem::discriminant(self) == std::mem::discriminant(other),
```

However, it has been suppressed in the following example for no good reason:

```rs
enum Either<T, U> {
    Left(T),
    Right(U),
}

impl<T, U> PartialEq for Either<T, U> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Left(l0), Self::Left(r0)) => l0 == r0,
            (Self::Right(l0), Self::Right(r0)) => l0 == r0,
            // _ => std::mem::discriminant(self) == std::mem::discriminant(other),
            // ^ this completes the match arms!
        }
    }
}
```

This PR has removed that suppression logic.

~~Of course, the PR could have suppressed the fallback case generation for single-variant enums instead, but I believe that this case is quite rare and should be caught by `#[warn(unreachable_patterns)]` anyway.~~

After this fix, when the enum has >1 variants, the following fallback arm will be generated :

* `_ => false,` if we've already gone through every case where the variants of `self` and `other` match;
* The original one (as stated above) in other cases.

---

Note: The code example is still wrong after the fix due to incorrect trait bounds.
2022-12-12 13:52:49 +00:00
Jonas Schievink
ed48bd8b9d Fix parsing of _ = x in closure body 2022-12-12 12:57:29 +01:00
Florian Diebold
d3cb032f7e Make assoc_resolutions always have a Substitution 2022-12-10 17:05:33 +01:00
bors
a3ea20a142 Auto merge of #13725 - bvanjoi:resolve-const-triat-impls, r=flodiebold
feat: resolve const for trait impls

Fixed #13694
2022-12-10 13:58:28 +00:00
bvanjoi
7012b50db5 feat: resolve const for trait impls(close #13694) 2022-12-10 20:06:25 +08:00
bors
632f804797 Auto merge of #13750 - lowr:fix/rpit-in-projection, r=flodiebold
fix: normalize projection after discarding free `BoundVar`s in RPIT

Fixes #13307

When we lower the return type of a function, it may contain free `BoundVar`s in `OpaqueType`'s substitution, which would cause panic during canonicalization as part of projection normalization. Those `BoundVar`s are irrelevant in this context and will be discarded, and we should defer projection normalization until then.
2022-12-10 11:30:14 +00:00
bors
518e39bfe6 Auto merge of #13742 - lowr:fix/assoc-type-shorthand-with-gats, r=flodiebold
fix: only shift `BoundVar`s that come from outside lowering context

Fixes #13734

There are some free functions `TyLoweringContext` methods call, which do not know anything about current binders in scope. We need to shift in the `BoundVar`s in substitutions that we get from them (#4952), but not those we get from `TyLoweringContext` methods.
2022-12-10 11:17:18 +00:00
bors
14492043db Auto merge of #13749 - WaffleLapkin:remove_some_redudant_adjustment_hints, r=Veykril
fix: Don't show duplicated adjustment hints for blocks, ifs and matches

Before:
![2022-12-09_21-10](https://user-images.githubusercontent.com/38225716/206761100-5511d91b-2543-4166-aa2c-abdb8bad3613.png)
After:
![2022-12-09_21-22](https://user-images.githubusercontent.com/38225716/206761113-c58dbb5a-8616-4287-a3b4-69c13703294d.png)

----

I want to improve adjustment hints, this is the first step :)
2022-12-09 19:36:05 +00:00
Ryo Yoshida
34b11d9981
fix: normalize projection after discarding free BoundVars in RPIT 2022-12-10 04:23:23 +09:00
Maybe Waffle
7c9a85bc43 fix: Don't show duplicated adjustment hints for blocks, ifs and matches 2022-12-09 18:45:01 +00:00
bors
a0296c2b39 Auto merge of #13745 - Veykril:ty-hint-variant-field, r=Veykril
Show type info on hover of enum variant fields

Small addition to https://github.com/rust-lang/rust-analyzer/pull/13490
2022-12-09 16:59:02 +00:00
Junliang HU
7d466570f4 Add numThreads in config to avoid spawning lots of threads every time 2022-12-09 21:35:06 +08:00
feniljain
d7183fb5d0 fix: make make_body respect comments in extract_function 2022-12-09 18:30:30 +05:30
bors
34e654cd7b Auto merge of #13733 - WaffleLapkin:remove_parens, r=Veykril
feat: Add "Remove redundant parentheses" assist

![Peek 2022-12-08 22-22](https://user-images.githubusercontent.com/38225716/206542898-d6c97468-d615-4c5b-8650-f89b9c0321a0.gif)

Can be quite handy when refactoring :)
2022-12-09 11:42:09 +00:00
Lukas Wirth
e80674e6b3 Show type info on hover of enum variant fields 2022-12-09 10:09:55 +01:00
Maybe Waffle
ba6f0befc8 Simplify remove_parentheses's implementation 2022-12-08 18:54:08 +00:00
Maybe Waffle
8d42439a7d Move precedence handling to crates/syntax 2022-12-08 18:46:30 +00:00
Maybe Waffle
2870b01ec0 Explicitly say that the assist removes *redundant* parentheses 2022-12-08 18:22:57 +00:00
Ryo Yoshida
19e3085481
Only shift BoundVars that come from outside TyLoweringContext 2022-12-08 21:17:13 +09:00
Ryo Yoshida
46e1486a90
Disallow access to free BoundVars outside TyLoweringContext 2022-12-08 20:52:03 +09:00
bors
6e8a54d0f6 Auto merge of #13490 - HKalbasi:layout, r=jonas-schievink
Compute data layout of types

cc #4091

Things that aren't working:
* Closures
* Generators (so no support for `Future` I think)
* Opaque types
* Type alias and associated types which may need normalization

Things that show wrong result:
* ~Enums with explicit discriminant~
* SIMD types
* ~`NonZero*` and similar standard library items which control layout with special attributes~

At the user level, I didn't put much work, since I wasn't confident about what is the best way to present this information. Currently it shows size and align for ADTs, and size, align, offset for struct fields, in the hover, similar to clangd. I used it some days and I feel I liked it, but we may consider it too noisy and move it to an assist or command.
2022-12-07 15:22:03 +00:00
rami3l
57fb18e3bd fix: refine fallback case in generated PartialEq impl 2022-12-07 10:25:17 +08:00
hkalbasi
948a8f030b Add a fixme comment in current_target_data_layout 2022-12-07 02:29:50 +03:30
hkalbasi
05906da0ec use rustc crates instead of copy paste 2022-12-07 01:59:38 +03:30
Maybe Waffle
ab061945a1 Consider expression precedense in remove_parentheses assist 2022-12-06 19:11:24 +00:00
Maybe Waffle
5f79279b48 Add remove_parentheses assist 2022-12-06 16:18:25 +00:00
rami3l
fed74c8b71 fix: add fallback case in generated PartialEq impl 2022-12-06 21:54:53 +08:00
Ryo Yoshida
051c6598be
Resolve macro2's derive helpers in IDE layer
Macro2's generally don't have derive helpers, but currently builtin
derive macros are declared with macro2 syntax, which can have derive
helpers.
2022-12-06 16:01:20 +09:00
Ryo Yoshida
cf54b8c3a4
Parse and collect derive helpers for builtin derive macros 2022-12-06 16:00:46 +09:00
Wilco Kusee
a75bffc729 Increase Chalk fuel from 100 to 1000
The old value was for the old chalk-engine solver, nowadays the newer chalk-recursive solver is used.
The new solver currently uses fuel a bit more quickly, so a higher value is needed.
Running analysis-stats showed that a value of 100 increases the amount of unknown types,
while for a value of 1000 it's staying mostly the same.
2022-12-05 18:13:11 +01:00
Wilco Kusee
fc627e637b Update to Chalk 88 2022-12-05 17:29:23 +01:00
feniljain
4794572e36 feat: allow unwrap block in let initializers 2022-12-05 09:00:16 +05:30
Lukas Wirth
ca1389ef9f Support rustc_has_incoherent_inherent_impls 2022-12-04 20:37:17 +01:00
hkalbasi
f2c9502185 support nonzero* niche optimizations 2022-12-04 00:29:34 +03:30
hkalbasi
86b5b609f1 Compute data layout of types 2022-12-04 00:29:34 +03:30
Ryo Yoshida
de591f08d6
Handle raw identifiers in proc macro server 2022-12-04 00:26:05 +09:00
bors
04a2ac2de2 Auto merge of #13707 - lowr:feat/move-const-to-impl, r=Veykril
Add `move_const_to_impl` assist

Closes #13277

For the initial implementation, this assist:
- only applies to inherent impl. Much as we can *technically* provide this assist for default impl in trait definitions, it'd be complicated to get it right.
- may break code when the const's name collides with an item of a trait the self type implements.

Comments in the code explain those caveats in a bit more detail.
2022-12-03 13:16:22 +00:00
feniljain
ec268c0d6c fix: breaking snippets on typed incomplete suggestions
Fix the case where if a user types `&&42.o`, snippet completion
was still applying &&Ok(42). Note this was fixed previously
on `&&42.` but this still remained a problem for this case
2022-12-03 08:43:13 +05:30
Allan Brondum Rasmussen
30736b54c9 fmt 2022-12-03 01:20:27 +01:00
Allan Brondum Rasmussen
cc4f9db086 remove unneeded test 2022-12-03 00:53:56 +01:00
Allan Brondum Rasmussen
bce3b63700 check reference is a NameRef (and not Name) 2022-12-02 23:50:39 +01:00
Ryo Yoshida
6d4538734e
Add move_const_to_impl assist 2022-12-03 01:22:00 +09:00
Jonas Schievink
335cb26050 Version the inlay hint resolve data 2022-11-29 19:20:32 +01:00
Jonas Schievink
b65b02fd97 Fix signature help not showing up when cursor is between )) or >> 2022-11-29 18:50:21 +01:00
Wilco Kusee
16bf32fcdd Update Chalk to version 87 2022-11-29 15:25:09 +01:00
bors
acd06de16a Auto merge of #13690 - Crauzer:vararg-type, r=Veykril
feat: Implement vararg parameter type inference

This PR implements the "collection" of the `va_list` type into the function parameter types list.
2022-11-29 07:55:57 +00:00
bors
3769cc35fa Auto merge of #13686 - MariaSolOs:test-lenses, r=Veykril
Don't show runnable code lenses in libraries outside of the workspace

Addresses #13664. For now I'm just disabling runnable code lenses since the ones that display the number of references and implementations do work correctly with external code.

Also made a tiny TypeScript change to use the typed `sendNotification` overload.
2022-11-29 07:42:35 +00:00
Maria José Solano
9914d30450 Fix formatting 2022-11-28 19:10:16 -08:00
Crauzer
b3bd5a471e implement vararg type collection from function params 2022-11-29 00:32:13 +01:00
Maria José Solano
2174aca8f8 Check for workspace root in runnable codelens 2022-11-27 10:07:09 -08:00
bors
6d61be8e65 Auto merge of #13681 - lowr:fix/extract-function-tail-expr, r=Veykril
fix: check tail expressions more precisely in `extract_function`

Fixes #13620

When extracting expressions with control flows into a function, we can avoid wrapping tail expressions in `Option` or `Result` when they are also tail expressions of the container we're extracting from (see #7840, #9773). This is controlled by `ContainerInfo::is_in_tail`, but we've been computing it by checking if the tail expression of the range to extract is contained in the container's syntactically last expression, which may be a block that contains both tail and non-tail expressions (e.g. in #13620, the range to be extracted is not a tail expression but we set the flag to true).

This PR tries to compute the flag as precise as possible by utilizing `for_each_tail_expr()` (and also moves the flag to `Function` struct as it's more of a property of the function to be extracted than of the container).
2022-11-27 12:18:42 +00:00
bors
34e2bc6a54 Auto merge of #13611 - yue4u:fix/completion-after-colon, r=yue4u
fix: filter unnecessary completions after colon

close #13597
related: #10173

This PR also happens to fix two extra issues:

1. The test case in https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-completion/src/tests/attribute.rs#L778-L801 was never triggered in previous behavior.

after:

https://user-images.githubusercontent.com/26110087/201476995-56adf955-0fa7-4f75-ab32-28a8e6cb9504.mp4

<del>
2. completions were triggered even in invalid paths, like

```rust
fn main() {
    core:::::$0
}
```

```rust
#[:::::$0]
struct X;
```

</del>

only `:::` is excluded as discussed in https://github.com/rust-lang/rust-analyzer/pull/13611#discussion_r1031845205
2022-11-26 17:55:00 +00:00
yue4u
1ca5cb7ed9 fix: also exclude 2 coloncolon in a row 2022-11-27 02:39:38 +09:00
yue4u
e1de04d60c fix: only special casing 3 colon in a row 2022-11-27 01:53:45 +09:00
Ryo Yoshida
8e03f18e37
fix: check if range contains tail expression 2022-11-27 00:31:02 +09:00
Ryo Yoshida
822c61f559
refactor: remove unnecessary stuff 2022-11-27 00:01:16 +09:00
Lukas Wirth
7bf2a25dfe Encode the variants of HirFileId in a u32 with MSB as the tag 2022-11-25 23:28:35 +01:00
bors
b651646510 Auto merge of #13676 - fasterthanlime:subtree-fix, r=Veykril
Mega-sync from `rust-lang/rust`

This essentially implements `@oli-obk's` suggestion here https://github.com/rust-lang/rust-analyzer/pull/13459#issuecomment-1297285607, with `@eddyb's` help.

This PR is equivalent to 14 syncs (back and forth) between `rust-lang/rust` and `rust-lang/rust-analyzer`.

Working from this list (from bottom to top):

```
(x) a2a1d9954 ⬆️ rust-analyzer
(x) 79923c382 ⬆️ rust-analyzer
(x) c60b1f641 ⬆️ rust-analyzer
(x) 8807fc4cc ⬆️ rust-analyzer
(x) a99a48e78 ⬆️ rust-analyzer
(x) 4f55ebbd4 ⬆️ rust-analyzer
(x) f5fde4df4 ⬆️ rust-analyzer
(x) 459bbb422 ⬆️ rust-analyzer
(x) 65e1dc4d9 ⬆️ rust-analyzer
(x) 3e358a682 ⬆️ rust-analyzer
(x) 31519bb39 ⬆️ rust-analyzer
(x) 8231fee46 ⬆️ rust-analyzer
(x) 22c8c9c40 ⬆️ rust-analyzer
(x) 9d2cb42a4 ⬆️ rust-analyzer
```

(This listed was assembled by doing a `git subtree push`, which made a branch, and looking at the new commits in that branch, picking only those that were `⬆️ rust-analyzer` commits)

We used the following commands to simulate merges in both directions:

```shell
TO_MERGE=22c8c9c40 # taken from the list above, bottom to top
git merge --no-edit --no-ff $TO_MERGE
git merge --no-edit --no-ff $(git -C ../rust log --pretty=format:'%cN | %s | %ad => %P' | rg -m1 -F "$(git show --no-patch --pretty=format:%ad $TO_MERGE)" | tee /dev/stderr | rg '.* => \S+ (\S+)$' --replace '$1')
```

We encountered no merge conflicts that Git wasn't able to solve by doing it this way.

Here's what the commit graph looks like (as shown in the Git Lens VSCode extension):

<img width="1345" alt="image" src="https://user-images.githubusercontent.com/7998310/203984523-7c1a690a-8224-416c-8015-ed6e49667066.png">

This PR closes #13459

## Does this unbreak `rust->ra` syncs?

Yes, here's how we tried:

In `rust-analyzer`:

  * check out `subtree-fix` (this PR's branch)
  * make a new branch off of it: `git checkout -b subtree-fix-merge-test`
  * simulate this PR getting merged with `git merge master`

In `rust`:

  * pull latest master
  * make a new branch: `git checkout -b test-change`
  * mess with rust-analyzer (I added a comment to `src/tools/rust-analyzer/Cargo.toml`)
  * commit
  * run `git subtree push -P src/tools/rust-analyzer ra-local final-sync` (this follows the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html))

This created a `final-sync` branch in `rust-analyzer`.

In `rust-analyzer`:

  * `git merge --no-ff final-sync` (this follows the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html))

Now `git log` in `rust-analyzer` shows this:

```
commit 460128387e46ddfc2b95921b2d7f6e913a3d2b9f (HEAD -> subtree-fix-merge-test)
Merge: 0513fc02a 9ce6a734f
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:28:24 2022 +0100

    Merge branch 'final-sync' into subtree-fix-merge-test

commit 0513fc02a08ea9de952983624bd0a00e98044b36
Merge: 38c98d1ff 6918009fe
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:28:02 2022 +0100

    Merge branch 'master' into subtree-fix-merge-test

commit 9ce6a734f37ef8e53689f1c6f427a9efafe846bd (final-sync)
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:26:26 2022 +0100

    Mess with rust-analyzer just for fun
```

And `git diff 0513fc02a08ea9de952983624bd0a00e98044b36` shows this:

```patch
diff --git a/Cargo.toml b/Cargo.toml
index 286ef1e7d..c9e24cd19 100644
--- a/Cargo.toml
+++ b/Cargo.toml
`@@` -32,3 +32,5 `@@` debug = 0
 # ungrammar = { path = "../ungrammar" }

 # salsa = { path = "../salsa" }
+
+# lol, hi
```

## Does this unbreak `ra->rust` syncs?

Yes, here's how we tried.

From `rust`:

  * `git checkout -b sync-from-ra`
  * `git subtree pull -P src/tools/rust-analyzer ra-local subtree-fix-merge-test` (this is adapted from the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html#performing-the-sync-from-clippy-to-rust-langrust), you would normally use `ra-upstream master` but we're simulating things here)

A commit editor pops up, there was no merge conflicts.

## How do we prevent this from happening again?

Like `@bjorn3` said in https://github.com/rust-lang/rust-analyzer/pull/13459#issuecomment-1293587848

> Whenever syncing from rust-analyzer -> rust you have to immediately sync the merge commit from rust -> rust-analyzer to prevent merge conflicts in the future.

But if we get it wrong again, at least now we have a not-so-painful way to fix it.
2022-11-25 21:27:46 +00:00
Amos Wenger
e96c0b1d53 Merge commit 'a2a1d9954' into HEAD 2022-11-25 13:06:31 +01:00
Amos Wenger
ae43043aab Merge commit '79923c382' into HEAD 2022-11-25 13:06:01 +01:00
Amos Wenger
e070dc5129 Merge commit 'c60b1f641' into HEAD 2022-11-25 13:05:26 +01:00
Amos Wenger
2f65294569 Merge commit '8807fc4cc' into HEAD 2022-11-25 13:04:50 +01:00
Amos Wenger
251b18ac6c Merge commit 'a99a48e78' into HEAD 2022-11-25 13:03:59 +01:00
Amos Wenger
e6540cff74 Merge commit '4f55ebbd4' into HEAD 2022-11-25 13:03:10 +01:00
Amos Wenger
969e25033b Merge commit 'f5fde4df4' into HEAD 2022-11-25 13:02:44 +01:00
Amos Wenger
dec148e6eb Merge commit '459bbb422' into HEAD 2022-11-25 13:02:06 +01:00
Amos Wenger
318fdacaf8 Merge commit '65e1dc4d9' into HEAD 2022-11-25 12:58:18 +01:00
Amos Wenger
ff2b468b55 Merge commit '3e358a682' into HEAD 2022-11-25 12:58:00 +01:00
Amos Wenger
6ac43ecf17 Merge commit '31519bb39' into HEAD 2022-11-25 12:57:38 +01:00
Amos Wenger
2374c0b368 Merge commit '8231fee46' into HEAD 2022-11-25 12:55:08 +01:00
Amos Wenger
db84a00d03 Merge commit '22c8c9c40' into HEAD 2022-11-25 12:13:34 +01:00
Amos Wenger
2566e06da1 Merge commit '8e38833c3674c1be7d81c6069c62e6ed52b18b27' into HEAD 2022-11-25 12:01:49 +01:00
bors
e668eca632 Auto merge of #13647 - nyz93:fix/tuple-to-named-struct, r=Veykril
fix: tuple to named struct inside macros

seems to fix #13634
2022-11-25 09:41:21 +00:00
bors
99daf23e11 Auto merge of #13671 - Veykril:goto-decl, r=Veykril
Improve goto declaration

Closes https://github.com/rust-lang/rust-analyzer/issues/13599

- goto decl now goes to assoc items of trait declarations over the items of trait implementations
- goto decl now goes to the field declaration (opposed to goto def which shows both the field decl and binding created/local being used)
- also adds back the goto definition fallback that seems to have been dropped at some point.
2022-11-25 09:28:39 +00:00
Lukas Wirth
ae0bdffcc9 Go to declaration goes to field declaration in pattern and expression shorthands 2022-11-25 10:27:54 +01:00
Lukas Wirth
3c794a34da Go to declaration goes to assoc items of trait declarations 2022-11-25 10:27:49 +01:00
bors
6918009fea Auto merge of #13638 - DesmondWillowbrook:hover-rest-pat-mvp, r=Veykril
feat: adds hover hint to ".." in record pattern

Hovering on the "rest" pattern in struct destructuring,
```rust
struct Baz {
    a: u32,
    b: u32,
    c: u32,
    d: u32
}

let Baz { a, b, ..$0} = Baz { a: 1, b: 2, c: 3, d: 4 };
```
shows:

```
.., c: u32, d: u32
```

Currently only works with struct patterns.

![image](https://user-images.githubusercontent.com/51814158/202837115-f424cc26-c2d7-4027-8eea-eeb7749ad146.png)
2022-11-25 07:41:05 +00:00
Kartavya Vashishtha
a26aef9055
fix formatting 2022-11-25 12:22:06 +05:30
Kartavya Vashishtha
91e7624de0
add hover tests 2022-11-25 12:20:38 +05:30
Kartavya Vashishtha
e86d451484
fix token method call 2022-11-25 12:20:34 +05:30
Kartavya Vashishtha
132d5ffc7d
add back [] in hover documentation 2022-11-25 12:04:14 +05:30
Kartavya Vashishtha
f64feeb11a
Correct node traversal to look at parent instead
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-11-24 22:32:15 -08:00
bors
76e2e41121 Auto merge of #13652 - jhgg:hir-expand/fix-compile-error-expansion, r=Veykril
hir-expand: fix compile_error! expansion not unquoting strings

expanding `compile_error!` would not properly unquote strings, leading to quite ugly diagnostic messages:

![image](https://user-images.githubusercontent.com/5489149/202893481-2486ede8-c79a-4972-9713-416d6a704064.png)

this fixes it, using the conveniently placed `unquote_str` function, which now makes errors look like:

![image](https://user-images.githubusercontent.com/5489149/202893466-0763efad-9240-4d55-80a6-6c62000d5d2b.png)

additionally, using `unquote_str` has the cool side-effect of *also* handling raw strings, so this fixes a fixme too!
2022-11-24 21:00:48 +00:00
bors
5e3ad5ddf6 Auto merge of #13592 - MihailMihov:trait_impl_assist, r=Veykril
Add assist to generate trait impl's

resolves #13553

This pull request adds a `generate_trait_impl` assist, which generates trait impl's for a type. It is almost the same as the one to generate impl's and I also reduced the trigger range to only outside the `RecordFieldList`. Also moved all the tests into separate test functions. A few of the old tests seemed redundant, so I didn't port them.
2022-11-24 20:44:33 +00:00
bors
fbc0f7a771 Auto merge of #13669 - Veykril:jod-child, r=Veykril
Properly implement Drop for JodGroupChild
2022-11-24 20:31:38 +00:00
Lukas Wirth
c8b6fef70f Properly implement Drop for JodGroupChild 2022-11-24 21:30:15 +01:00
bors
e9f6087965 Auto merge of #13661 - iredelmeier:fix-null-checkonsave-target, r=jonas-schievink
Fix: Handle empty `checkOnSave/target` values

This fixes a regression introduced by #13290, in which failing to set `checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid config.

[Fixes #13660]
2022-11-24 15:52:27 +00:00
bors
63a676eedf Auto merge of #13576 - Bben01:supress_missing_impl_inside_block, r=jonas-schievink
Suppress "Implement default members" inside contained items

Fixes #13561
2022-11-24 15:16:36 +00:00
bors
81d26e730e Auto merge of #13667 - Veykril:detached-files-sysroot, r=Veykril
Handle sysroot config in detached-files workspaces
2022-11-24 09:21:44 +00:00
Lukas Wirth
2300c9de83 Handle sysroot config in detached-files workspaces 2022-11-24 10:21:19 +01:00
Laurențiu Nicola
a2a1d99545 ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
Isobel Redelmeier
b116fe9be0
Fix: Handle empty checkOnSave/target values
This fixes a regression introduced by #13290, in which failing to set
`checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid
config.
2022-11-21 16:40:32 -05:00
Mihail Mihov
469f620b06 Combine generate_impl and generate_trait_impl into a single file 2022-11-21 22:58:43 +02:00
Mihail Mihov
0bd11f8171 Reduce trigger range of generate_impl assist and update tests 2022-11-21 22:27:26 +02:00
Mihail Mihov
ecb15ca717 Add assist to generate trait impl's 2022-11-21 22:27:26 +02:00
Bben01
95b4a7487b Suppress "Implement default members" inside contained items 2022-11-21 22:17:04 +02:00
Jake Heinz
427b63b676 hir-expand: fix compile_error! expansion not unquoting strings 2022-11-20 08:48:27 +00:00
Nyikos Zoltán
23cfe0702d fix: tuple to named struct inside macros
seems to fix #13634
2022-11-19 20:08:01 +01:00
yue4u
7a568f7f95 fix: remove insufficient check for coloncolon 2022-11-20 01:29:02 +09:00
yue
a6d0e342a3
Update crates/ide-completion/src/context.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-11-20 00:58:59 +09:00
Kartavya Vashishtha
29951f9766
fix formatting 2022-11-19 21:23:33 +05:30
Kartavya Vashishtha
87658c8173
refactor hover
change struct_rest_pat to guarentee a HoverResult

Move token and node matching out of struct_rest_pat into hover
2022-11-19 21:22:10 +05:30
bors
38fa47fd79 Auto merge of #13290 - poliorcetics:multiple-targets, r=Veykril
Support multiple targets for checkOnSave (in conjunction with cargo 1.64.0+)

This PR adds support for the ability to pass multiple `--target` flags when using
`cargo` 1.64.0+.

## Questions

I needed to change the type of two configurations options, but I did not plurialize the names to
avoid too much churn, should I ?

## Zulip thread

https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Issue.2013282.20.28supporting.20multiple.20targets.20with.201.2E64.2B.29

## Example

To see it working, on a macOS machine:

```sh
$ cd /tmp
$ cargo new cargo-multiple-targets-support-ra-test
$ cd !$
$ mkdir .cargo
$ echo '
[build]
target = [
    "aarch64-apple-darwin",
    "x86_64-apple-darwin",
]
' > .cargo/config.toml
$ echo '
fn main() {
    #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }

    #[cfg(all(target_arch = "x86_64", target_os = "macos"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }

    #[cfg(all(target_arch = "x86_64", target_os = "windows"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }
}
' > src/main.rs
# launch your favorite editor with the version of RA from this PR
#
# You should see warnings under the first two `let a = ...` but not the third
```

## Screen

![Two panes of a terminal emulator, on the left pane is the main.rs file described above, with warnings for the first two let a = declaration, on the right pane is a display of the .cargo/config.toml, an ls of the current files in the directory and a call to cargo build to show the same warnings as in the editor on the left pane](https://user-images.githubusercontent.com/7951708/192122707-7a00606a-e581-4534-b9d5-b81c92694e8e.png)

Helps with #13282
2022-11-19 13:09:37 +00:00
bors
2d9ed4fd48 Auto merge of #13641 - DesmondWillowbrook:fix-move-format-string, r=Veykril
fix: format expression parsing edge-cases

- Handle positional arguments with formatting options (i.e. `{:b}`). Previously copied `:b` as an argument, producing broken code.

- Handle indexed positional arguments (`{0}`) ([reference](https://doc.rust-lang.org/std/fmt/#positional-parameters)). Previously copied over `0` as an argument.

Note: the assist also breaks when named arguments are used (`"{name}$0", name = 2 + 2` is converted to `"{}"$0, name`. I'm working on fix for that as well.
2022-11-19 12:46:29 +00:00
bvanjoi
a4f071afd5 fix(assists): remove item_const which had default value when implement missing members` 2022-11-19 19:38:53 +08:00
Kartavya Vashishtha
6d4b2b4b17
run cargo fmt 2022-11-19 15:08:32 +05:30
bors
ac60077ee5 Auto merge of #13639 - Veykril:macro-diags, r=Veykril
fix: Fix proc-macro-srv search paths for Arch Linux

Fixes https://github.com/rust-lang/rust-analyzer/issues/13616
2022-11-19 09:33:10 +00:00
Lukas Wirth
dc8254c6ab fix: Fix nested macro diagnostics pointing at macro expansion files 2022-11-19 10:32:32 +01:00
Kartavya Vashishtha
a3f8fd71df
fix: format expression parsing edge-cases
handle positional arg with formatting

handle indexed positional args
2022-11-19 15:00:25 +05:30
Kartavya Vashishtha
8b17681058
fix formatting
and remove unnecessary check
2022-11-19 11:34:49 +05:30
Kartavya Vashishtha
a778203db9
simplify ancestor climbing to not consider macros 2022-11-19 11:17:43 +05:30
Kartavya Vashishtha
0ffb361eb9
feat: adds hover hint to ".." in record pattern
currently only works with struct pattern
2022-11-19 11:10:47 +05:30
Lukas Wirth
52bc15fc1f fix: Fix proc-macro-srv search paths for Arch Linux 2022-11-18 23:32:26 +01:00
bors
791cb87cdf Auto merge of #13633 - Veykril:vscode-full-diagnostics, r=Veykril
feat: Allow viewing the full compiler diagnostic in a readonly textview

![Code_y1qrash9gg](https://user-images.githubusercontent.com/3757771/202780459-f751f65d-2b1b-4dc3-9685-100d65ebf6a0.gif)

Also adds a VSCode only config that replaces the split diagnostic message with the first relevant part of the diagnostic output

![Code_7k4qsMkx5e](https://user-images.githubusercontent.com/3757771/202780346-cf9137d9-eb77-46b7-aed6-c73a2e41e1c7.png)

This only affects diagnostics generated by primary spans and has no effect on other clients than VSCode.

Fixes https://github.com/rust-lang/rust-analyzer/issues/13574
2022-11-18 19:33:38 +00:00
Lukas Wirth
8452844c26 Fix tests checking the data value 2022-11-18 20:15:49 +01:00
Lukas Wirth
073a63b93e feat: Allow viewing the full compiler diagnostic in a readonly textview 2022-11-18 19:56:08 +01:00
bors
bee27eb471 Auto merge of #13632 - Veykril:scip, r=Veykril
Make it more obvious which SCIP features we do not yet emit in code
2022-11-18 10:31:41 +00:00
Lukas Wirth
656d886ca8 Make it more obvious which SCIP features we do not yet emit in code 2022-11-18 11:31:12 +01:00
Jonas Schievink
cd6459e7b3 Make "Remove dbg!()" assist work on selections 2022-11-17 17:39:31 +01:00
Ryo Yoshida
7577c44c65
Update proc-macro-srv tests 2022-11-17 01:42:56 +09:00
Ryo Yoshida
1ad11b5366
fix: resolve inference variable before applying adjustments 2022-11-16 20:01:55 +09:00
bors
0dd0dfb7df Auto merge of #13615 - mati865:miow-update, r=jonas-schievink
Update several crates to bring support for the new Tier 3 Windows tar…

`cargo t` has passed on Windows 11 with both `x86_64-pc-windows-gnu` and `x86_64-pc-windows-gnullvm` targets.
2022-11-15 11:59:27 +00:00
Jonas Schievink
7e77d4e310 Strip comments and attributes off of all trait item completions 2022-11-15 12:41:39 +01:00
Jonas Schievink
15dfeabb96 Fix GAT completion not including generic parameters 2022-11-15 12:05:11 +01:00
Mateusz Mikuła
46417add8d Update several crates to bring support for the new Tier 3 Windows targets 2022-11-13 22:45:09 +01:00
yue4u
f26d5484d8 fix: filter unnecessary completions after colon 2022-11-12 22:33:40 +09:00
bors
45ec315e01 Auto merge of #13607 - Veykril:proc-macro-error, r=Veykril
internal: Add version info to unsupported proc macro abi error

cc https://github.com/rust-lang/rust-analyzer/issues/13589#issuecomment-1311824473
2022-11-11 15:57:30 +00:00
Lukas Wirth
6b4b7d81e4 internal: Add version info to unsupported proc macro abi error 2022-11-11 16:57:05 +01:00
bors
2656303c83 Auto merge of #13606 - Veykril:trait-alias, r=Veykril
fix: Add trait alias grammar to rust.ungram

We already parse them, but the grammar was never updated to reflect that
2022-11-11 14:26:15 +00:00
Lukas Wirth
6674bd898e fix: Add trait alias grammar to rust.ungram 2022-11-11 15:25:15 +01:00
Lukas Wirth
a143ff0248 fix: Fix r-a eagerly showing no discovered workspace errors 2022-11-11 14:36:27 +01:00
Alexis (Poliorcetics) Bourget
0d4737adb6 feat: Support passing multiple targets to cargo (for Rust 1.64.0+) 2022-11-11 14:36:07 +01:00
Alexis (Poliorcetics) Bourget
c6c932d3f3 chore: Align config property 2022-11-11 14:36:07 +01:00
bors
add85397ae Auto merge of #13604 - Veykril:hover-attr, r=Veykril
fix: Fix hover in attributed items not preferring similar kinded tokens
2022-11-11 12:48:48 +00:00
Lukas Wirth
e50712cf2c fix: Fix hover in attributed items not preferring similar kinded tokens 2022-11-11 13:38:07 +01:00
bors
57cc2a6e27 Auto merge of #13602 - lowr:fix/nameres-transitive-visibility, r=Veykril
fix: check visibility of each path segment

Upon path resolution, we have not been checking if every def pointed to by each segment of the path is visible from the original module. This leads to incorrect import resolutions, in particular when one uses glob imports and names collide.

There is decent amount of changes in this PR because:
- some of our tests were not correct in terms of visibility
  - I left several basic nameres tests as-is (with expect test updated) since I thought it would be nice to ensure we don't resolve defs that are not visible.
- `fix_visibility` assist relied on `Semantics::resolve_path()`, which uses the name resolution procedure I'm fixing and wouldn't be able to "see through" the items with strict visibility with this patch

The first commit is the gist of the fix itself.

Fixes #10991
Fixes #11473
Fixes #13252
2022-11-11 12:32:21 +00:00
bors
6f313cef8e Auto merge of #13548 - lowr:fix/tt-punct-spacing, r=Veykril
Fix `tt::Punct`'s spacing calculation

Fixes #13499

We currently set a `tt::Punct`'s spacing to `Spacing::Joint` unless its next token is a trivia (i.e. whitespaces or comment). As I understand it, rustc only [sets `Spacing::Joint` if the next token is an operator](5b3e909075/compiler/rustc_parse/src/lexer/tokentrees.rs (L77-L78)) and we should follow it to guarantee the consistent behavior of proc macros.
2022-11-11 12:19:30 +00:00
Lukas Wirth
e35836eb81 Send status notification if there are no found workspaces 2022-11-11 13:00:22 +01:00
Ryo Yoshida
19306c070d
Fix tests that depended on loose visibility restriction 2022-11-11 20:31:46 +09:00
Ryo Yoshida
e75afebeb2
Resolve invisible defs in fix_visibility assist 2022-11-11 20:31:44 +09:00
Ryo Yoshida
dea49d0826
fix: check visibility of each segment in path resolution 2022-11-11 20:31:37 +09:00
Ryo Yoshida
5b07061011
Test TokenTrees' equality modulo Puncts' spacing 2022-11-10 19:40:40 +09:00
Ryo Yoshida
4f415fc348
Ignore outermost non-delimited Subtree when reversing fixups 2022-11-10 19:22:20 +09:00
Michael Goulet
61c744d4fd Rollup merge of #104211 - lnicola:rust-analyzer-2022-11-09, r=lnicola
⬆️ rust-analyzer

r? ``@ghost``
2022-11-09 21:53:38 -08:00
bors
599142c34a Auto merge of #13590 - Veykril:proc-macro-rustc-src, r=Veykril
internal: Add proc-macro dependency to rustc_private crates
2022-11-09 19:51:20 +00:00
Lukas Wirth
3c35d44f55 Add proc-macro dependency to rustc_private crates 2022-11-09 20:50:18 +01:00
Laurențiu Nicola
79923c382a ⬆️ rust-analyzer 2022-11-09 21:49:10 +02:00
Dylan DPC
a65ca91b84 Rollup merge of #103919 - nnethercote:unescaping-cleanups, r=matklad
Unescaping cleanups

Some code improvements, and some error message improvements.

Best reviewed one commit at a time.

r? ````@matklad````
2022-11-09 19:21:22 +05:30
Jonas Schievink
9be0615bde Don't canonicalize self type when querying FnOnce signature 2022-11-08 18:05:07 +01:00
bors
236c1167cc Auto merge of #13581 - Veykril:unit-struct-compl, r=Veykril
fix: Fix item completions not working properly after unit structs and outline modules

Fixes https://github.com/rust-lang/rust-analyzer/issues/13578
2022-11-08 07:38:13 +00:00
Lukas Wirth
90e2db8126 fix: Fix item completions not working properly after unit structs and outline modules 2022-11-08 08:37:45 +01:00
bors
b8b1951ee8 Auto merge of #13573 - Veykril:invalid-file-range, r=Veykril
internal: error instead of panic on invalid file range

Fixes the panic in https://github.com/rust-lang/rust-analyzer/issues/13170
2022-11-07 16:45:26 +00:00
Lukas Wirth
1cb6ab89ee internal: error instead of panic on invalid file range 2022-11-07 17:45:12 +01:00
bors
0aa0da9dda Auto merge of #13572 - Veykril:cancellable, r=Veykril
internal: Use Cancellable in favor of Result for clarity
2022-11-07 16:22:33 +00:00
Lukas Wirth
fa70b0a86e internal: Use Cancellable in favor of Result for clarity 2022-11-07 17:21:37 +01:00
bors
a27e4dad37 Auto merge of #13571 - Veykril:unique-references, r=Veykril
minor: Deduplicate reference search results

Fixes https://github.com/rust-lang/rust-analyzer/issues/13407
2022-11-07 15:49:54 +00:00
Lukas Wirth
6a06f6f724 Deduplicate reference search results 2022-11-07 16:48:50 +01:00
bors
d1c9775171 Auto merge of #13568 - noritada:fix/len-of-byte-string-with-escaped-newlines, r=Veykril
Fix the length displayed for byte string literals with escaped newlines

This is a fix for the problem I reported earlier: "the length of byte strings containing escaped newlines is displayed two bytes longer when the first escaped character is a newline".

I would appreciate it if you could review the fix.
Many thanks.

Closes #13567
2022-11-07 15:04:40 +00:00
bors
8a633fe986 Auto merge of #13570 - Veykril:dedup-crates-for, r=Veykril
minor: Remove code duplication
2022-11-07 14:52:05 +00:00
Lukas Wirth
b169e1e5de Remove code duplication 2022-11-07 15:49:26 +01:00
Noritada Kobayashi
2340d7059e Add test code for unescaping byte strings 2022-11-07 23:39:02 +09:00
bors
b0e56ef5e8 Auto merge of #13545 - Veykril:adjustment-hints, r=Veykril
Generalize reborrow hints as adjustment hints

Like reborrow hints, these are still mainly useful for teaching/learning

![image](https://user-images.githubusercontent.com/3757771/200073606-b5cd3b95-a9ad-454d-a3c4-d4d89bf45928.png)
2022-11-07 14:38:59 +00:00
Noritada Kobayashi
bdf8547013 Clarify the intent
Thanks to Lukas Wirth for a suggestion.
2022-11-07 22:51:29 +09:00
Lukas Wirth
ffd7bf8bf9 Bump Cargo rust-version fields to latest stable 2022-11-07 12:59:51 +01:00
Lukas Wirth
ee2dd934ca Don't trigger adjustment hints in all inlay hint tests 2022-11-07 12:49:52 +01:00
bors
c0310c1e03 Auto merge of #13565 - Veykril:sysroot, r=Veykril
Update sysroot crates
2022-11-07 11:40:44 +00:00
Noritada Kobayashi
180b4cedec Fix the length displayed for byte string literals with escaped newlines
The length of byte strings containing escaped newlines is displayed two
bytes longer when the first escaped character is a newline.

This is due to a small bug in handling the first escaped newline in
string literals.

Closes #13567
2022-11-07 20:07:16 +09:00
bors
d3d3806565 Auto merge of #12991 - TiddoLangerak:extract-method-from-trait-into-impl-root, r=Veykril
Feat: extracted method from trait impl is placed in existing impl

**Before**

https://user-images.githubusercontent.com/1759192/183872883-3b0eafd2-d1dc-440e-9e66-38e3372f8b64.mp4

**After**

https://user-images.githubusercontent.com/1759192/183875769-87f34c7d-52f0-4dfc-9766-f591ee738ebb.mp4

Previously, when triggering a method extraction from within an impl trait block, then this would always create a new impl block for
the struct, even if there already is one. Now, if there is already an existing trait-less impl block, then it'll put the extracted method in there.

**Caveats**:
- It currently requires the target impl block to be non-empty. This limitation is because the current architecture takes a `node_to_insert_after` as reference for where to insert the extracted function. An empty impl block doesn't have such a reference node, since it's empty. It seems that supporting this requires a much larger and more complex change.
- This is my first contribution in rust, so apologies for any beginner mistakes.
2022-11-07 11:07:12 +00:00
Lukas Wirth
8ad4a1d118 Update sysroot crates 2022-11-07 12:01:12 +01:00
Lukas Wirth
f24fbc2027 rustfmt 2022-11-07 11:58:57 +01:00
Laurențiu Nicola
cff7ab1308 Fix typos 2022-11-07 12:54:12 +02:00
bors
f54c313914 Auto merge of #13547 - Veykril:line-index, r=Veykril
internal: Optimize `apply_document_changes` a bit

cc https://github.com/rust-lang/rust-analyzer/issues/13538
2022-11-07 10:33:13 +00:00
Lukas Wirth
1dcc25a70a internal: Use a process group for flycheck 2022-11-05 16:28:04 +01:00
bors
25b1d6f3f9 Auto merge of #13435 - DropDemBits:assists-format-args-capture-pt3, r=Veykril
Migrate assists to format args captures, part 3

Continuation of https://github.com/rust-lang/rust-analyzer/pull/13379

Migrates:

- `inline_call`
- `inline_local_variable`
- `introduce_named_lifetime`
- `merge_match_arms`
- `move_from_mod_rs`
- `move_guard`
- `move_module_to_file`
- `move_to_mod_rs`
- `number_representation`
- `qualify_method_call`
- `qualify_path`
- `raw_string`
- `remove_dbg`
- `replace_derive_with_manual_impl`
- `replace_or_with_or_else`
- `replace_turbofish_with_explicit_type`
- `unwrap_tuple`
- `wrap_return_type_in_result`
2022-11-05 12:41:23 +00:00
bors
afe8f6b922 Auto merge of #13379 - DropDemBits:ide-assists-format-args-capture, r=Veykril
internal: Migrate `ide_assists::utils` and `ide_assists::handlers` to use format arg captures (part 1)

This not only serves as making future migration to mutable syntax trees easier, it also finds out what needs to be migrated in the first place.

~~Aside from the first commit, subsequent commits are structured to only deal with one file/handler at a time.~~

This is the first of 3 PRs, migrating:

Utils:

- `gen_trait_fn_body`
- `render_snippet`
- `ReferenceConversion`
  - `convert_type`
  - `getter`

Handlers:

- `add_explicit_type`
- `add_return_type`
- `add_turbo_fish`
- `apply_demorgan`
- `auto_import`
- `convert_comment_block`
- `convert_integer_literal`
- `convert_into_to_from`
- `convert_iter_for_each_to_for`
- `convert_let_else_to_match`
- `convert_tuple_struct_to_named_struct`
- `convert_two_arm_bool_match_to_matches_macro`
- `destructure_tuple_binding`
- `extract_function`
- `extract_module`
- `extract_struct_from_enum_variant`
- `extract_type_alias`
- `extract_variable`
- `fix_visibility`
2022-11-05 12:29:06 +00:00
bors
2c37e7d4af Auto merge of #13549 - Veykril:search-fix, r=Veykril
fix: Fix reference searching only accounting substrings instead of whole identifiers

Fixes https://github.com/rust-lang/rust-analyzer/issues/13498
2022-11-05 12:16:18 +00:00
Lukas Wirth
17619de711 fix: Fix reference searching only accounting substrings instead of whole identifiers 2022-11-05 13:00:02 +01:00
Ryo Yoshida
41b0c54c07
Fix tt::Punct's spacing calculation 2022-11-05 19:42:09 +09:00
Ryo Yoshida
b87a23b91b
Rename convertor -> converter 2022-11-05 19:41:08 +09:00
bors
df3877037e Auto merge of #13454 - justinmmott:master, r=flodiebold
Fixed local shadowing the caller's argument issue

fix https://github.com/rust-lang/rust-analyzer/issues/12536
2022-11-05 10:05:52 +00:00
Lukas Wirth
28afe57068 Add tests for LineEndings::normalize 2022-11-05 11:00:17 +01:00
Lukas Wirth
e468a1af35 internal: Optimize apply_document_changes a bit 2022-11-05 10:59:46 +01:00
Nicholas Nethercote
7d2a1ee4fc Remove unescape_byte_literal.
It's easy to just use `unescape_literal` + `byte_from_char`.
2022-11-05 13:56:36 +11:00
Lukas Wirth
d841ad116a Fix up adjustment hints configurations 2022-11-04 22:59:07 +01:00
Lukas Wirth
95d20fccd7 Add adjustment hint tests 2022-11-04 22:40:06 +01:00
Lukas Wirth
c98fc537e6 Generalize reborrow hints as adjustment hints 2022-11-04 21:53:23 +01:00
bors
cd2603299c Auto merge of #13546 - Veykril:unsafe-fn-ptr, r=Veykril
Lower unsafety of fn pointer and fn item types
2022-11-04 20:29:16 +00:00
Lukas Wirth
6f09c72b1b Lower unsafety of fn pointer and fn item types 2022-11-04 21:07:15 +01:00
bors
bbcb77ea6f Auto merge of #13456 - emilio:scip-local-symbol, r=Veykril
scip: Generate symbols for local crates.

Consider something like:

```
// a.rs
pub struct Foo { .. } // Foo is "local 1"

fn something() {
    crate:🅱️:Bar::new() // Bar is "local 1", but of "b.rs"
}

// b.rs
pub struct Bar { .. } // "local 1"
```

Without this there's no way to disambiguate whether "local 1" references "Bar" or "Foo".
2022-11-03 13:58:36 +00:00
bors
6c3ab563de Auto merge of #13527 - unexge:use-let-else-stmt-in-convert-to-guarded-return-assist, r=jonas-schievink
Use let-else statements in `Convert to guarded return` assist

Follow up for https://github.com/rust-lang/rust-analyzer/pull/13516, addresses remaining part of https://github.com/rust-lang/rust-analyzer/issues/13254#issuecomment-1250408527
2022-11-02 11:06:54 +00:00
bors
af1f48deab Auto merge of #13359 - feniljain:feat-must-use-option, r=Veykril
feat: add config for inserting must_use in `generate_enum_as_method`

Should fix #13312

Didn't add a test because I was not sure on how to add test for a specific configuration option, tried to look for the usages for other `AssistConfig` variants but couldn't find any in `tests`. If there is a way to test this, do point me towards it.

I tried to extract the formatting string as a common `template_string` and only have if-else for that, but it didn't compile :(

Also it seems these tests are failing:

```
test config::tests::generate_config_documentation ... FAILED
test config::tests::generate_package_json_config ... FAILED
```

Can you also point me to how to correct these 😅  ( I guess there is some command to automatically generate these? )
2022-11-02 10:50:08 +00:00
feniljain
691ce306df
fix: indentation after inserting #must_use
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-11-02 16:09:12 +05:30
bors
12ced8f9db Auto merge of #13517 - feniljain:fix_completions, r=Veykril
fix: make custom expr prefix completions to understand refs

Possible fix of #7929

While reviewing the postfix completion code I saw that while calling `add_custom_postfix_completions` we were doing it under the part where reference was not taken into consideration, but as we are only adding postfix completions with `Expr` scope ( [source](ba28e19b78/crates/ide-completion/src/completions/postfix.rs (L272)) )

I shifted the `add_custom_postfix_completions` call to part where references are considered

I am not sure if this is the correct fix or I am understanding the problem exactly but this small move seemed to have fixed the issue :)
2022-11-02 10:15:18 +00:00
unexge
62a6cdfe46 Use let-else statements in Convert to guarded return assist 2022-11-01 23:02:10 +00:00
bors
c1305fa5d9 Auto merge of #13525 - jonas-schievink:generic-call-signature, r=jonas-schievink
feat: show signature help when calling generic types implementing `FnOnce`

This queries chalk for the `FnOnce` impl of callees and takes argument and return types from there, making generic `Callable`s available to the IDE. This makes signature help work for them, and potentially allows other features to take generic callables into account in the future.
2022-11-01 17:01:07 +00:00
bors
a8e97bcf3c Auto merge of #13508 - koka831:fix/13492, r=jonas-schievink
fix: async trait method for `unnecessary_async`

Fix https://github.com/rust-lang/rust-analyzer/issues/13492
2022-11-01 16:38:40 +00:00
bors
d90cb1e772 Auto merge of #13516 - unexge:add-convert-match-to-let-else-assist, r=jonas-schievink
Add `Convert match to let-else` assist

Closes https://github.com/rust-lang/rust-analyzer/issues/13254
2022-11-01 16:24:15 +00:00
Jonas Schievink
72d5b456e1 Fix doc test 2022-11-01 17:23:32 +01:00
Jonas Schievink
e110c7889a Revert "Record diverging match arms in InferenceResult"
This reverts commit 319611b738.
2022-11-01 17:18:17 +01:00
Jonas Schievink
9f1bb17a1b Import option in the tests 2022-11-01 17:18:13 +01:00
Jonas Schievink
ecad1a9a6e Create Callables for generic types implementing FnOnce 2022-11-01 16:38:19 +01:00
Laurențiu Nicola
c60b1f6414 ⬆️ rust-analyzer 2022-11-01 11:31:31 +02:00
bors
07f6efc4e7 Auto merge of #13523 - lowr:fix/adjust-expectation-for-if, r=lnicola
fix: disregard type variable expectation for if expressions

Fixes #13522

As [the comment](8142d1f606/crates/hir-ty/src/infer.rs (L1087-L1090)) on `Expectation::adjust_for_branches` explains:

> If the expected type is just a type variable, then don't use an expected type. Otherwise, we might write parts of the type when checking the 'then' block which are incompatible with the 'else' branch.

Note that we already use it in match expressions. I've added tests for them too nevertheless.
2022-10-31 15:39:20 +00:00
Ryo Yoshida
db8c7523f8
fix: disregard type variable expectation for if expressions 2022-11-01 00:15:05 +09:00
feniljain
98125b9f95 fix: make custom expr prefix completions to understand refs 2022-10-30 15:02:17 +05:30
unexge
f0a14346ee Update auto generated tests 2022-10-30 00:00:53 +01:00
unexge
48efc9d303 Add Convert match to let-else assist 2022-10-29 23:45:13 +01:00
unexge
319611b738 Record diverging match arms in InferenceResult 2022-10-29 23:44:34 +01:00
koka
cf90e4f32b
Simplify the procedure
fix: remove unused import
2022-10-30 00:59:20 +09:00
koka
4a7f5cac9d
fix: async trait method for unnecessary_async 2022-10-29 01:14:44 +09:00
Ryo Yoshida
e0f09cd007
Document the ordering constraint on Binders and Substitution 2022-10-28 21:24:59 +09:00
Ryo Yoshida
5c794210bf
Replace expect test for GATs with check_types 2022-10-28 21:24:55 +09:00
Ryo Yoshida
5fc18ad6fa
Lower generic arguments for GATs in associated type bindings 2022-10-27 19:19:01 +09:00
Ryo Yoshida
63cba43b48
Collect generic arguments in associated type bindings 2022-10-27 19:18:59 +09:00
Ryo Yoshida
f233ac447f
Lower generic arguments for associated types in paths 2022-10-27 19:18:57 +09:00
Ryo Yoshida
4dd694371a
Display generic arguments for associated types 2022-10-27 19:18:55 +09:00
Ryo Yoshida
1fe10bff1d
refactor: remove obsolete code 2022-10-27 19:18:51 +09:00
bors
0340b51ff7 Auto merge of #13484 - lnicola:position-encoding, r=lnicola
Switch to upstream `positionEncoding`

Closes #13481

This drops support for the custom extension, but that's probably fine.

Draft because it's not tested yet.
2022-10-26 18:12:47 +00:00
Laurențiu Nicola
8807fc4cc3 ⬆️ rust-analyzer 2022-10-26 17:40:41 +03:00
bors
feefbe7918 Auto merge of #13475 - lowr:fix/lookup-impl-method-trait-ref, r=flodiebold
fix: Test all generic args for trait when finding matching impl

Addresses https://github.com/rust-lang/rust-analyzer/pull/13463#issuecomment-1287816680

When finding matching impl for a trait method, we've been testing the unifiability of self type. However, there can be multiple impl of a trait for the same type with different generic arguments for the trait. This patch takes it into account and tests the unifiability of all type arguments for the trait (the first being the self type) thus enables rust-analyzer to find the correct impl even in such cases.
2022-10-26 12:06:26 +00:00
Ryo Yoshida
67f1d8fe2c
Test all generic args for trait when finding matching impl 2022-10-25 23:28:40 +09:00
Laurențiu Nicola
e93a2bff67 Pin lsp-types 2022-10-25 15:03:35 +03:00
Laurențiu Nicola
956b96a19d Switch to upstream positionEncoding 2022-10-25 14:43:26 +03:00
feniljain
4bf9b9b003 refactor: remove repetitive string interpolation and doc changes 2022-10-24 21:12:31 +05:30
Ryo Yoshida
15d4383053
Let InferenceTable::unify() relate Zip values 2022-10-24 23:28:53 +09:00
bors
53b6d69e93 Auto merge of #13478 - Veykril:fix-flycheck, r=Veykril
fix: Fix standard flycheck command not being executed in the workspace it is being invoked for

Fixes https://github.com/rust-lang/rust-analyzer/issues/13477
2022-10-24 14:08:45 +00:00
Lukas Wirth
fbae83acd0 fix: Fix standard flycheck command not being executed in the workspace it is being invoked for 2022-10-24 16:07:42 +02:00
Lukas Wirth
6a00e14c7a fix: Don't respond with an error when requesting a shutdown while starting 2022-10-24 14:56:58 +02:00
Ryo Yoshida
6afd0f57eb
Refactor: unwrap Option once in the beginning of closure 2022-10-24 21:30:31 +09:00
feniljain
c4bdb8e516 feat: add config for inserting must_use in generate_enum_as_method 2022-10-24 13:18:24 +05:30
Lukas Wirth
859f5594ac Handle multiple projects sharing dependency correctly in once strategy 2022-10-23 18:01:35 +02:00
Lukas Wirth
0f8904ec9c Implement invocation location config 2022-10-22 23:33:03 +02:00
Emilio Cobos Álvarez
8039a07a5e
ide: Generate monikers for local crates. 2022-10-22 19:33:47 +02:00
bors
19efa0b110 Auto merge of #13463 - lowr:fix/builtin-derive-with-const-generics, r=Veykril
Support const generics for builtin derive macro

Fixes #13121

We have been treating every generic parameter as type parameter during builtin derive macro expansion. This patch adds support for const generics in such expansions.
2022-10-22 15:49:00 +00:00
Ryo Yoshida
6459d7f817
Support const generics for builtin derive macro 2022-10-23 00:05:22 +09:00
bors
d3b7e94d0a Auto merge of #13460 - emilio:scip-cleanups, r=Veykril
scip: minor clean-ups

Avoids a couple redundant hash map lookups and so.
2022-10-22 13:46:23 +00:00
Emilio Cobos Álvarez
ec6d72baa1
scip: Rewrite tests to be closer to what we actually do.
It's also less code.
2022-10-22 15:21:31 +02:00
Emilio Cobos Álvarez
bd49d01906
ide: Remove unnecessary continue. 2022-10-22 15:15:10 +02:00
Emilio Cobos Álvarez
7ee72256eb
scip: minor clean-ups
Avoids a couple redundant hash map lookups and so.
2022-10-22 14:14:43 +02:00
Cameron
3dd2f99c49 fix tests 2022-10-22 06:23:23 +01:00
Cameron
5b56d7bd90 remove duplicate mod definition 2022-10-22 05:43:57 +01:00
Cameron
9ea57f19be add wrapping/checked/saturating assist 2022-10-22 05:41:28 +01:00
Justin Mott
e4ef0e5df9 addressed https://github.com/rust-lang/rust-analyzer/issues/12536 2022-10-21 13:28:59 -04:00
Lukas Wirth
de195ff97c fix: Fix DidSaveDocument requests blocking the server on startup 2022-10-20 19:55:04 +02:00
bors
f3cce5feea Auto merge of #13365 - feniljain:master, r=Veykril
feat: add multiple getters mode in `generate_getter`

This commit adds two modes to generate_getter action.
First, the plain old working on single fields.
Second, working on a selected range of fields.

Should partially solve #13246
If this gets approved will create a separate PR for setters version of the same

### Points to help in review:

- `generate_getter_from_record_info` contains code which is mostly taken from assist before refactor
- Same goes for `parse_record_fields`
- There are changes in other assists, as one of the methods in utils named `find_struct_impl` is changed, before it used to accept a single `fn_name`, now it takes a list of function names to check against. All old impls are updated to create a small list to pass their single element.

### Assumptions:

- If any of the fields have an implementation, the action will quit.
2022-10-20 12:07:28 +00:00
feniljain
5bff6c55de feat: add multiple getters mode in generate_getter
This commit adds two modes to generate_getter action.
First, the plain old working on single fields.
Second, working on a selected range of fields.
2022-10-20 16:47:23 +05:30