Commit Graph

23157 Commits

Author SHA1 Message Date
bors
187bee0bb1 Auto merge of #13257 - rust-lang:revert-13147-fix/dyn-ty-inherent-methods, r=lnicola
fix: Fix a crash introduced in #13147

Reverts rust-lang/rust-analyzer#13147

https://github.com/rust-lang/rust-analyzer/actions/runs/3041499441/jobs/4898678721#step:18:62
2022-09-19 09:46:21 +00:00
Laurențiu Nicola
e54f61dbdb Try to fix crash introduced in #13147 2022-09-19 12:45:38 +03:00
bors
39eaf7864c Auto merge of #13253 - Veykril:simplify, r=Veykril
Simplify
2022-09-18 17:52:21 +00:00
Lukas Wirth
0d9f97166b Simplify 2022-09-18 19:44:38 +02:00
bors
11bf2e7ffb Auto merge of #13058 - dpaoliello:extraenv, r=Veykril
Add a new configuration settings to set env vars when running cargo, rustc, etc. commands: cargo.extraEnv and checkOnSave.extraEnv

It can be extremely useful to be able to set environment variables when rust-analyzer is running various cargo or rustc commands (such as `cargo check`, `cargo --print cfg` or `cargo metadata`): users may want to set custom `RUSTFLAGS`, change `PATH` to use a custom toolchain or set a different `CARGO_HOME`.

There is the existing `server.extraEnv` setting that allows env vars to be set when the rust-analyzer server is launched, but using this as the recommended mechanism to also configure cargo/rust has some drawbacks:
- It convolutes configuring the rust-analyzer server with configuring cargo/rustc (one may want to change the `PATH` for cargo/rustc without affecting the rust-analyzer server).
- The name `server.extraEnv` doesn't indicate that cargo/rustc will be affected but renaming it to `cargo.extraEnv` doesn't indicate that the rust-analyzer server would be affected.
- To make the setting useful, it needs to be dynamically reloaded without requiring that the entire extension is reloaded. It might be possible to do this, but it would require the client communicating to the server what the overwritten env vars were at first launch, which isn't easy to do.

This change adds two new configuration settings: `cargo.extraEnv` and `checkOnSave.extraEnv` that can be used to change the environment for the rust-analyzer server after launch (thus affecting any process that rust-analyzer invokes) and the `cargo check` command respectively. `cargo.extraEnv` supports dynamic changes by keeping track of the pre-change values of environment variables, thus it can undo changes made previously before applying the new configuration (and then requesting a workspace reload).
2022-09-18 17:43:46 +00:00
bors
932e63b5d4 Auto merge of #13239 - mdx97:mathew/fix-add-reference-for-macros, r=Veykril
Fix add reference action on macros.

Before we were using the range of the corresponding expression node in the macro expanded file, which is obviously incorrect as we are setting the text in the original source.

For some reason, the test I added is failing and I haven't found a way to fix it. Does anyone know why `check_fix` wouldn't work with macros? Getting this error:

```text
thread 'handlers::type_mismatch::tests::test_add_reference_to_macro_call' panicked at 'no diagnostics', crates/ide-diagnostics/src/handlers/type_mismatch.rs:317:9
```

closes #13219
2022-09-17 11:23:05 +00:00
harudagondi
ed0cf1c5fa Add functionality to unwrap tuple declarations 2022-09-17 15:57:45 +08:00
Mathew Horner
a65ca20210 Fix tests by using primitive rather than String. 2022-09-16 16:56:19 -05:00
bors
b6e3f41c2a Auto merge of #13243 - Veykril:search-memchr, r=Veykril
Use memmem when searching for usages in ide-db

We already have this dependency, so there is no reason not to use it as it is generally faster than std in our use case.
2022-09-16 14:28:12 +00:00
Lukas Wirth
b73fa0be9c Use memmem when searching for usages in ide-db 2022-09-16 16:26:54 +02:00
bors
870bfc7e3b Auto merge of #13242 - Veykril:completion-alias, r=Veykril
Complete variants and assoc items in path pattern through type aliases
2022-09-16 14:12:26 +00:00
Lukas Wirth
ad17ba12d1 Complete variants and assoc items in path pattern through type aliases 2022-09-16 16:11:58 +02:00
Mathew Horner
e7abf34c19 Fix add reference action on macros. 2022-09-15 20:25:29 -05:00
bors
6b163c301f Auto merge of #13235 - Veykril:prelude-handling, r=Veykril
Fix prelude injection

Fixes the regression of unknown types introduced in https://github.com/rust-lang/rust-analyzer/pull/13175
2022-09-15 10:13:11 +00:00
Lukas Wirth
a9f103e2fa Fix prelude injection 2022-09-15 12:12:22 +02:00
bors
2b61be2975 Auto merge of #13232 - jplatte:mbe-refactor, r=Veykril
Refactor macro-by-example code

I had a look at the MBE code because of #7857. I found some easy readability wins, that might also _marginally_ improve perf.
2022-09-14 22:39:31 +00:00
Jonas Platte
c4a87ee0ce
mbe: Remove unneeded unwrap 2022-09-14 23:49:08 +02:00
Jonas Platte
d6f0fd04ee
mbe: Remove unnecessary reference to usize 2022-09-14 23:42:11 +02:00
Jonas Platte
54305545a5
mbe: Remove Vec reference in container 2022-09-14 23:35:12 +02:00
Jonas Platte
b6aed7914d
mbe: Remove double reference in container 2022-09-14 23:30:44 +02:00
Jonas Platte
f7f6d2870f
mbe: Use extend instead of push in loop 2022-09-14 23:26:24 +02:00
Jonas Platte
5e2f9e322f
mbe: Return Bindings from build_inner 2022-09-14 23:22:38 +02:00
Daniel Paoliello
c407cc554e Add cargo.extraEnv setting 2022-09-13 11:29:14 -07:00
bors
dbb8fedf8b Auto merge of #13221 - mdx97:mdx97/annotations-above-whole-item, r=Veykril
Allow configuration of annotation location.

I've added the ability to configure where lens annotations render relevant to the item they describe. Previously, these would render directly above the line the item is declared on. Now, there is the ability to render these annotations above the entire item (including doc comments, and attributes).

The names of the config options are up for debate, I did what seemed best to me but if anyone has better ideas let me know.

This is my first contribution so if I've missed anything please let me know.

Here's a preview of what the new option looks like:

<img width="577" alt="Screen Shot 2022-09-11 at 10 39 51 PM" src="https://user-images.githubusercontent.com/33100798/189570298-b4fcbf9c-ee49-4b79-aae6-1037ae4f26af.png">

closes https://github.com/rust-lang/rust-analyzer/issues/13218
2022-09-13 15:09:53 +00:00
bors
ba15f75c39 Auto merge of #13225 - lowr:fix/hir-proj-normalization, r=Veykril
fixup: remove unnecessary `Option`

Fixup for #13223, two things:

- `normalize_projection_query()` (and consequently `HirDatabase::normalize_projection()`) never returns `None` (well, it used to when I first wrote it...), so just return `Ty` instead of `Option<Ty>`
- When chalk cannot normalize projection uniquely, `normalize_trait_assoc_type()` used to return `None` before #13223, but not anymore because of the first point. I restored the behavior so its callers work as before.
2022-09-13 14:52:58 +00:00
bors
125d43cb2c Auto merge of #13227 - Veykril:core-pref, r=Veykril
Restructure `find_path` into a separate functions for modules and non-module items

Follow up to https://github.com/rust-lang/rust-analyzer/pull/13212
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc

This PR turned into a slight rewrite, so it unfortunately does a few more things that I initially planned to (including a bug fix for enum variant paths)
2022-09-13 13:16:57 +00:00
Lukas Wirth
a8ecaa1979 Restructure find_path into a separate functions for modules and non-module items
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc
2022-09-13 15:15:27 +02:00
bors
482a992439 Auto merge of #13228 - Veykril:ref-import-filtering, r=Veykril
Move reference imports filtering into to_proto layer

Follow up to https://github.com/rust-lang/rust-analyzer/pull/13186
2022-09-13 12:59:20 +00:00
Lukas Wirth
cadb01c315 Move reference imports filtering into to_proto layer 2022-09-13 14:58:50 +02:00
Mathew Horner
f57c15f3e9 Address comments and fix build. 2022-09-12 16:34:13 -05:00
OleStrohm
3931e55aee Fixed lints 2022-09-12 21:27:19 +01:00
OleStrohm
177ec82a41 Rebased 2022-09-12 21:02:30 +01:00
OleStrohm
5313bd1984 Cleaned up code based on feedback 2022-09-12 20:20:45 +01:00
OleStrohm
301b8894ea Added more consteval tests and fixed consteval result 2022-09-12 20:20:45 +01:00
OleStrohm
ad0a6bf1a3 Added consteval tests 2022-09-12 20:20:43 +01:00
OleStrohm
2f84b6e2e5 Almost there 2022-09-12 20:20:22 +01:00
OleStrohm
b63234e20b Cleaned up code 2022-09-12 20:19:49 +01:00
OleStrohm
e28046c673 Removed unnecessary TODO 2022-09-12 20:19:19 +01:00
OleStrohm
997fc46efa Implemented basic enum const eval 2022-09-12 20:19:13 +01:00
Ryo Yoshida
4b5a66e0bc
Add tests for type inference for generators 2022-09-13 02:43:07 +09:00
Ryo Yoshida
447596cccc
Implement RustIrDatabase::generator_datum() 2022-09-13 02:43:05 +09:00
Ryo Yoshida
77c40f878d
Implement type inference for generator and yield expressions 2022-09-13 02:42:52 +09:00
Ryo Yoshida
d223c28c7d
Remove unnecessary Option 2022-09-13 02:20:35 +09:00
bors
f64c95600c Auto merge of #13216 - DesmondWillowbrook:move_format_string_arg, r=DesmondWillowbrook
New assist: move_format_string_arg

The name might need some improving.

```rust
fn main() {
    print!("{x + 1}");
}
```
to
```rust
fn main() {
    print!("{}"$0, x + 1);
}
```

fixes #13180

ref to #5988 for similar work

* extracted `format_like`'s parser to it's own module in `ide-db`
* reworked the parser's API to be more direct
* added assist to extract expressions in format args
2022-09-12 15:50:42 +00:00
bors
b1a4ba3e84 Auto merge of #13223 - lowr:fix/hir-proj-normalization, r=flodiebold
fix: handle lifetime variables in projection normalization

Fixes #12674

The problem is that we've been skipping the binders of normalized projections assuming they should be empty, but the assumption is unfortunately wrong. We may get back lifetime variables and should handle them before returning them as normalized projections. For those who are curious why we get those even though we treat all lifetimes as 'static, [this comment in chalk](d875af0ff1/chalk-solve/src/infer/unify.rs (L888-L908)) may be interesting.

I thought using `InferenceTable` would be cleaner than the other ways as it already has the methods for canonicalization, normalizing projection, and resolving variables, so moved goal building and trait solving logic to a new `HirDatabase` query. I made it transparent query as the query itself doesn't do much work but the eventual call to `HirDatabase::trait_solve_query()` does.
2022-09-12 14:24:57 +00:00
Ryo Yoshida
efb56160c9
fix: handle lifetime variables in projection normalization 2022-09-12 22:52:58 +09:00
bors
b54d22d96a Auto merge of #13215 - Veykril:toggle-inlay, r=Veykril
Remove the toggleInlayHints command from VSCode

Inlay hints are no longer something specifc to r-a as it has been upstreamed into the LSP, we don't have a reason to give the config for this feature special treatment in regards to toggling. There are plenty of other options out there in the VSCode marketplace to create toggle commands/hotkeys for configurations in general which I believe we should nudge people towards instead.
2022-09-12 13:45:25 +00:00
Kartavya Vashishtha
54e9324e93
Update crates/ide-assists/src/handlers/move_format_string_arg.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-12 05:45:11 -07:00
bors
7a704f2cc7 Auto merge of #13147 - lowr:fix/dyn-ty-inherent-methods, r=Veykril
fix: handle trait methods as inherent methods for trait-related types

Fixes #10677

When resolving methods for trait object types and placeholder types that are bounded by traits, we need to count the methods of the trait and its super traits as inherent methods. This matters because these trait methods have higher priority than the other traits' methods.

Relevant code in rustc: [`assemble_inherent_candidates_from_object()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L783-L792)) for trait object types, [`assemble_inherent_candidates_from_param()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L838-L847)) for placeholder types. Notice the second arg of `push_candidate()` is `is_inherent`.
2022-09-12 12:19:14 +00:00
bors
e38dfe5536 Auto merge of #13186 - enomado:master, r=Veykril
Filter imports on find-all-references

Attempt to #13184
2022-09-12 12:09:57 +00:00