Commit graph

16025 commits

Author SHA1 Message Date
unexge
89107d5469 Emit unconfigured code diagnostics for fields 2022-09-26 19:04:57 +01:00
Noah Santschi-Cooney
651c586035
formatting 2022-09-26 18:35:06 +01:00
Noah Santschi-Cooney
60b432b7e9
fix model tests 2022-09-26 18:18:12 +01:00
Noah Santschi-Cooney
aa093f5a58
Fix PackageInformation having the crate name instead of package name 2022-09-26 17:31:38 +01:00
bors
1a24003eb6 Auto merge of #13248 - harudagondi:unwrap-tuple, r=Veykril
Feature: Add assist to unwrap tuple declarations

> Implement #12923 for only tuples.
>
> Does not implement unwrapping for structs, as mentioned in the issue.

Add assist to unwrap tuples declarations to separate declarations.

```rust
fn main() {
	$0let (foo, bar, baz) = (1.0, "example", String::new())
}
```

becomes:

```rust
fn main() {
	let foo = 1.0;
	let bar = "example";
	let baz = String::new();
}
```

## Changelog

### Feature

- Added assist to unwrap tuple declarations.
2022-09-26 09:35:59 +00:00
Lukas Wirth
7929e9c56b Remove obsolete in-rust-tree feature from sourcegen 2022-09-26 11:34:30 +02:00
bors
1f929659ac Auto merge of #13209 - lowr:feat/inference-for-generator, r=Veykril
feat: type inference for generators

This PR implements basic type inference for generator and yield expressions.

Things not included in this PR:
- Generator upvars and generator witnesses are not implemented. They are only used to determine auto trait impls, so basic type inference should be fine without them, but method resolutions with auto trait bounds may not be resolved correctly.

Open questions:
- I haven't (yet) implemented `HirDisplay` for `TyKind::Generator`, so generator types are just shown as "{{generator}}" (in tests, inlay hints, hovers, etc.), which is not really nice. How should we show them?
- I added moderate amount of stuffs to minicore. I especially didn't want to add `impl<T> Deref for &T` and `impl<T> Deref for &mut T` exclusively for tests for generators; should I move them into the test fixtures or can they be placed in minicore?

cc #4309
2022-09-26 09:28:41 +00:00
Lukas Wirth
73f6af54c1 Use the sysroot proc-macro server for analysis-stats 2022-09-24 22:04:17 +02:00
Lukas Wirth
0231d19f3f Fix diagnostics not working in enum variant bodies 2022-09-24 03:07:05 +02:00
Lukas Wirth
7ec9ffa325 Properly support IDE functionality in enum variants 2022-09-24 02:33:59 +02:00
Lukas Wirth
f57cd838d8 Don't run proc-macro-srv tests on the rust-analyzer repo
proc-macro ABI breakage still affects the tests when a new stable version
releases. Ideally we'd still be able to run the tests on the rust-analyzer
repo without having to update the proc-macro ABI, but for now just to
unblock CI we will ignore them here, as they are still run in upstream.
2022-09-24 00:08:28 +02:00
Lukas Wirth
729a9eb5d0 Fix find_path using the wrong module for visibility calculations 2022-09-22 17:56:58 +02:00
Ryo Yoshida
9ede5f0735
Implement HirDisplay for TyKind::Generator 2022-09-21 22:04:55 +09:00
harudagondi
c2dc32c48e return None instead of assert 2022-09-21 09:11:02 +08:00
Lukas Wirth
9bf386f4c0 Fix default enum representation not being isize 2022-09-20 17:50:13 +02:00
Lukas Wirth
2119c1f351 Fix using incorrect type for variants in DefWithBody::body_type 2022-09-20 17:29:35 +02:00
Lukas Wirth
b25f0ba15b Properly set the enum variant body expected type 2022-09-20 17:15:48 +02:00
Lukas Wirth
9f233cd5d2 Parse more repr options 2022-09-20 17:12:27 +02:00
Lukas Wirth
6d0d051628 Simplify 2022-09-20 17:12:10 +02:00
bors
817a6a8609 Auto merge of #12966 - OleStrohm:master, r=Veykril
feat: Display the value of enum variant on hover

fixes #12955

This PR adds const eval support for enums, as well as showing their value on hover, just as consts currently have.

I developed these two things at the same time, but I've realized now that they are separate. However since the hover is just a 10 line change (not including tests), I figured I may as well put them in the same PR. Though if you want them split up into "enum const eval support"  and "show enum variant value on hover", I think that's reasonable too.

Since this adds const eval support for enums this also allows consts that reference enums to have their values computed now too.

The const evaluation itself is quite rudimentary, it doesn't keep track of the actual type of the enum, but it turns out that Rust doesn't actually either, and `E::A as u8` is valid regardless of the `repr` on `E`.

It also doesn't really care about what expression the enum variant contains, it could for example be a string, despite that not being allowed, but I guess it's up to the `cargo check` diagnostics to inform of such issues anyway?
2022-09-20 14:01:16 +00:00
bors
09600a3a5b Auto merge of #13268 - Veykril:simplify, r=Veykril
Simplify
2022-09-20 12:35:18 +00:00
Lukas Wirth
027bfd68ba Fix operator highlighting tags applying too broadly 2022-09-20 14:33:44 +02:00
Lukas Wirth
7e8eac3fd7 Simplify 2022-09-20 14:33:18 +02:00
Ryo Yoshida
9845e37f58
Ensure at least one trait bound in TyKind::DynTy 2022-09-20 04:37:34 +09:00
OleStrohm
f87ad8df05 Added FIXME for the repr type of the enum 2022-09-19 19:26:35 +01:00
DidiBear
cdc362e6cc
docs(inlay-hints): remove reference to Toggle inlay hints 2022-09-19 12:00:58 -04:00
bors
4f2c86e86e Auto merge of #13260 - Veykril:simplify, r=Veykril
Simplify
2022-09-19 15:32:45 +00:00
Lukas Wirth
a6c067c06d Simplify 2022-09-19 17:31:08 +02:00
bors
bc6d574662 Auto merge of #13259 - Veykril:cargo-config-simplify, r=Veykril
Simplify feature representation in CargoConfig
2022-09-19 14:53:06 +00:00
Lukas Wirth
d9f5709609 Simplify feature representation in CargoConfig 2022-09-19 16:52:44 +02: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
Lukas Wirth
a9f103e2fa Fix prelude injection 2022-09-15 12:12:22 +02: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
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
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
bors
352a5b8625 Auto merge of #13212 - Veykril:no-std-config, r=Veykril
Add config to unconditionally prefer core imports over std

Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-12 11:51:31 +00:00
Borys Minaiev
32603baac3 Remove redundant 'resolve_obligations_as_possible' call 2022-09-12 11:03:44 +01:00
Mathew Horner
8a2803d9ae Allow configuration of annotation location.
Previously, annotations would only appear above the name of an item (function signature, struct declaration, etc).

Now, rust-analyzer can be configured to show annotations either above the name or above the whole item (including doc comments and attributes).
2022-09-11 22:40:33 -05:00
Kartavya Vashishtha
fb5ae9906b
suggest ExtractRefactor if no expressions found
Added `Ident` variant to arg enum.
2022-09-11 10:39:25 +05:30
Kartavya Vashishtha
a5cbee4d11
remove false positive 2022-09-10 21:04:25 +05:30
Kartavya Vashishtha
cc7200891b
new lint: move_format_string_arg
The name might need some improving.

extract 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-10 20:13:46 +05:30
Kartavya Vashishtha
2584d48508
wip 2022-09-10 20:13:46 +05:30
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
Stanislav
f7f4792f4f fixes 2022-09-09 20:58:06 +03:00
Ryo Yoshida
aeeb9e08b2
Add TyBuilder method to build Substitution for generator 2022-09-09 16:49:09 +09:00
Ryo Yoshida
ba64c93a44
Lower generator expression to HIR 2022-09-09 16:47:32 +09:00
Peh
bd3feea8bc fix: removed swap file 2022-09-08 22:44:10 +01:00
Peh
c7fefd5223 fix: add semicolon completion to mod 2022-09-08 22:37:31 +01:00
Stanislav
0240294759 fix comment round 2 2022-09-08 22:47:39 +03:00
Stanislav
1764c42518 fix comment 2022-09-08 22:36:36 +03:00
bors
4e1a3da8f2 Auto merge of #13158 - jonas-schievink:inlayhint-links, r=jonas-schievink
feat: make clicking a closing brace inlay hint go to the opening brace
2022-09-08 16:38:40 +00:00
Jonas Schievink
c4eadab016
Update crates/rust-analyzer/src/to_proto.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-08 18:33:53 +02:00
Jonas Schievink
064c9ef9e2 Make clicking closing brace hint go to the opening brace 2022-09-08 17:25:28 +02:00
Stanislav
9f6553e1d6 add config for import filtering 2022-09-08 01:53:20 +03:00
Joseph Ryan
5d126a18b4 Use proc-macro-srv from sysroot in rust-project.json 2022-09-06 18:27:17 -07:00
Stanislav
eba54c2fc9 pretty solition works 2022-09-07 04:09:25 +03:00
Stanislav
92d54f9b30 typo and draft 2022-09-07 03:24:55 +03:00
Stanislav
bd0eeb3f04
Update crates/ide/src/references.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-07 03:01:06 +03:00
bors
6dfd8aebdf Auto merge of #13192 - lowr:fix/dyn-sort-all-bounds, r=Veykril
fix: sort all bounds on trait object types

Fixes #13181

#12793 allowed different ordering of trait bounds in trait object types but failed to account for the ordering of projection bounds. I opted for sorting all the bounds at once rather than splitting them into `SmallVec`s so it's easier to do the same thing for other bounds when we have them.
2022-09-05 11:24:54 +00:00
bors
5be2e6574d Auto merge of #13185 - ChayimFriedman2:insert-ws-in-static-const-macro, r=Veykril
fix: Insert whitespaces into static & const bodies if they are expanded from macro on hover

Partially fixes #13143.

To resolve the other part we need to expand macros in unevaluated static & const bodies, and I'm not sure we want to. If for example it includes a call to `assert!()`, expanding it will lead to worse hover.
2022-09-05 11:10:40 +00:00