Commit graph

15790 commits

Author SHA1 Message Date
Dorian Scheidt
6130860789 use fn_name instead of name_ref.text() 2022-08-18 18:12:53 -05:00
Dorian Scheidt
d39677c1eb Rename static_method_target -> assoc_fn_target 2022-08-18 18:10:37 -05:00
bors
0a33d04a3d Auto merge of #13053 - lowr:fix/pat-sole-Self, r=Veykril
fix: resolve path `Self` alone in value namespace

Fixes #12968
2022-08-18 11:17:40 +00:00
Ryo Yoshida
dac27679f7
fix: resolve path Self alone in value namespace 2022-08-18 20:12:59 +09:00
bors
5543dd88c9 Auto merge of #13036 - sancho20021:10881-inline_type_alias_uses, r=Veykril
feat: Add an assist for inlining all type alias uses

## Description
`inline_type_alias_uses` assist tries to inline all selected type alias occurrences.

### Currently
Type alias used in `PathType` position are inlined.

### Not supported
- Removing type alias declaration if all uses are inlined.
- Removing redundant imports after inlining all uses in the file.
- Type alias not in `PathType` position, such as:
  - `A::new()`
  - `let x = A {}`
  - `let bits = A::BITS`
  - etc.

## Demonstration

![example](https://user-images.githubusercontent.com/45790125/184905226-9cb8ac81-1439-4387-a13b-e18ad4ecf208.gif)

## Related Issues
Partially fixes #10881
2022-08-18 08:02:37 +00:00
bors
1d36aba57a Auto merge of #13045 - DorianListens:dscheidt/run-test-mod-outside, r=Veykril
feat: Run test mod from anywhere in parent file

The "Run" feature of rust-analyzer is super useful, especially for running
individual tests or test-modules during development.

One common pattern in rust development is to develop tests in the same file as
production code, inside a module (usually called `test` or `tests`) marked with
`#[cfg(test)]`.  Unforunately, this pattern is not well supported by r-a today,
as a test module won't show up as a runnable unless the cursor is inside it.

In my experience, it is quite common to want to run the tests associated with
some production code immediately after editing it, not only after editing the
tests themselves. As such it would be better if test modules were available
from the "Run" menu even when the cursor is outside the test module.

This change updates the filtration logic for runnables in
`handlers::handle_runnables` to special case `RunnableKind::TestMod`, making
test modules available regardless of the cursor location. Other `RunnableKind`s
are unnaffected.

Fixes #9589
2022-08-18 07:54:10 +00:00
bors
1da9156b0d Auto merge of #12982 - jridgewell:into_future, r=Veykril
Implement IntoFuture type inference

One of my projects is using [IntoFuture](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) to make our async code a little less verbose. However, rust-analyzer can't infer the output type of an await expression if the value uses `IntoFuture` to convert into another type. So we're getting `{unknown}` types everywhere since switching.

`foo.await` itself [desugars](e4417cf020/compiler/rustc_ast_lowering/src/expr.rs (L644-L658)) into a `match into_future(foo) {}`, with every `Future` impl getting a [default](e4417cf020/library/core/src/future/into_future.rs (L131-L139)) `IntoFuture` implementation. I'm not sure if we want to disable the old `future_trait` paths, since this only recently [stabilize](https://github.com/rust-lang/rust/pull/98718).
2022-08-18 07:37:47 +00:00
bors
ae57b697e2 Auto merge of #13049 - lowr:fix/bare-dyn-assoc-type, r=Veykril
fix: resolve associated types of bare dyn types

Fixes #13031

We've been dropping the associated type bindings of trait object types that were written without the `dyn` keyword. This patch reuses the lowering logic for `TypeRef::DynTrait` so the associated type bindings are properly lowered.
2022-08-18 07:29:16 +00:00
Ryo Yoshida
12abaf8ddd
fix: resolve associated types of bare dyn types 2022-08-18 07:05:41 +09:00
Dorian Scheidt
85b9568e2d feat: Run test mod from anywhere in parent file
The "Run" feature of rust-analyzer is super useful, especially for running
individual tests or test-modules during development.

One common pattern in rust development is to develop tests in the same file as
production code, inside a module (usually called `test` or `tests`) marked with
`#[cfg(test)]`.  Unforunately, this pattern is not well supported by r-a today,
as a test module won't show up as a runnable unless the cursor is inside it.

In my experience, it is quite common to want to run the tests associated with
some production code immediately after editing it, not only after editing the
tests themselves. As such it would be better if test modules were available
from the "Run" menu even when the cursor is outside the test module.

This change updates the filtration logic for runnables in
`handlers::handle_runnables` to special case `RunnableKind::TestMod`, making
test modules available regardless of the cursor location. Other `RunnableKind`s
are unnaffected.

Fixes #9589
2022-08-17 12:26:07 -05:00
bors
82ff740501 Auto merge of #13044 - dzvon:fix-typo, r=Veykril
fix: a bunch of typos

This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 14:59:02 +00:00
Dezhi Wu
23747419ca fix: a bunch of typos
This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 21:44:58 +08:00
bors
d6412b5866 Auto merge of #13034 - lowr:fix/regression-from-12993, r=lowr
fix: escape keywords used as names in earlier editions

Fixes #13030

There are keywords in Rust 2018+ that you can use as names without escaping when your crate is in Rust 2015 e.g. "try". We need to be consistent on how to keep track of the names regardless of how they are actually written in each crate. This patch attempts at it by taking such names into account and storing them uniformly in their escaped form.
2022-08-17 09:55:14 +00:00
Aleksandr Pak
313b004ef7
fixup! feat: add inline_type_alias_uses assist 2022-08-17 12:50:33 +03:00
Ryo Yoshida
a3409c3a83
fix: escape keywords used as names in earlier editions 2022-08-17 18:46:17 +09:00
bors
dd9ead591e Auto merge of #13043 - Veykril:ide-db-trace, r=Veykril
minor: Change tracing event level in apply_change

This is a rather spammy one, it shouldn't be `info`
2022-08-17 07:34:07 +00:00
Lukas Wirth
557c5b4dc5 minor: Change tracing event level in apply_change 2022-08-17 09:32:25 +02:00
Justin Ridgewell
cebf95718c Find IntoFuture::IntoFuture's poll method 2022-08-16 17:53:10 -04:00
Dorian Scheidt
39d17efde7 feat: Generate static method using Self::assoc() syntax
This change improves the `generate_function` assist to support generating static methods/associated functions using the `Self::assoc()` syntax. Previously, one could generate a static method, but only when specifying the type name directly (like `Foo::assoc()`). After this change, `Self` is supported as well as the type name.

Fixes #13012
2022-08-16 15:37:24 -05:00
Lukas Wirth
1f73cbe839 Revert #12947, trigger workspace switches on all structure changes again 2022-08-16 19:13:10 +02:00
Jonas Schievink
7fb7c248c7 Add .enable suffix 2022-08-16 18:12:15 +02:00
Dominik Gschwind
ad7a1ed8cc
fix: Fix panics on GATs involving const generics
This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.
2022-08-16 17:30:17 +02:00
Aleksandr Pak
6d6356b103
fixup! feat: add inline_type_alias_uses assist 2022-08-16 18:29:22 +03:00
Jonas Schievink
0616cee92b Add a setting for keyword hover popups 2022-08-16 16:51:40 +02:00
Aleksandr Pak
14db080933
feat: add inline_type_alias_uses assist 2022-08-16 17:24:56 +03:00
bors
b6fae56e38 Auto merge of #13028 - yue4u:fix/literal-lookup, r=jonas-schievink
fix: record completion filtering

close #12975
2022-08-16 13:28:00 +00:00
yue4u
91358bd937 fix: format literal lookup 2022-08-16 01:24:21 +09:00
bors
3903243192 Auto merge of #13027 - jonas-schievink:fix-mismatch-with-trailing-empty-macro, r=jonas-schievink
fix: Fix incorrect type mismatch with `cfg_if!` and other macros in expression position

Fixes https://github.com/rust-lang/rust-analyzer/issues/12940

This is a bit of a hack, ideally `MacroStmts` would not exist at all after HIR lowering, but that requires changing how the lowering code works.
2022-08-15 16:06:59 +00:00
Jonas Schievink
8c60813096 Fix lowering of empty macro expressions in trailing position 2022-08-15 18:01:58 +02:00
bors
3561433ef2 Auto merge of #13026 - Veykril:nameres, r=Veykril
internal: Make `resolve_name_in_module` a bit more lazy
2022-08-15 14:49:12 +00:00
Lukas Wirth
88b19cc39b Make resolve_name_in_module a bit more lazy 2022-08-15 16:41:51 +02:00
bors
6d6201299c Auto merge of #13025 - Veykril:simplify2, r=Veykril
Simplify
2022-08-15 14:40:26 +00:00
Lukas Wirth
3f149a63d2 Simplify 2022-08-15 16:40:10 +02:00
Jonas Schievink
dcbe892d7c Add an HIR pretty-printer 2022-08-15 13:51:45 +02:00
bors
bbe5637bbf Auto merge of #13016 - Veykril:vscode-diag-workaround, r=Veykril
Move VSCode diagnostics workaroudn into client code
2022-08-13 18:35:09 +00:00
Lukas Wirth
ec8256dd80 Move VSCode diagnostics workaroudn into client code 2022-08-13 20:30:30 +02:00
bors
306687b640 Auto merge of #13014 - Veykril:simplify, r=Veykril
minor: Simplify `GlobalState::handle_event`
2022-08-13 18:03:56 +00:00
Lukas Wirth
038c36a1f5 Simplify GlobalState::handle_event 2022-08-13 20:03:06 +02:00
Lukas Wirth
72ae308c73 Do not unconditionally succeed RUSTC_WRAPPER checks when run by build scripts
rust-analyzer's RUSTC_WRAPPER unconditionally succeeds `cargo check`
invocations tripping up build scripts using `cargo check` to probe for
successful compilations. To prevent this from happening the RUSTC_WRAPPER
now checks if it's run from a build script by looking for the
`CARGO_CFG_TARGET_ARCH` env var that cargo sets only when running build
scripts.
2022-08-13 12:13:48 +02:00
bors
cee1e157d7 Auto merge of #12993 - lowr:patch/swap-name-and-escaped-name, r=Veykril
Make `Name` hold escaped name

Resolves #12787
Resolves rust-lang/rust#99361

This PR effectively swaps `Name` and `EscapedName` in hir. In other words, it makes `Name` hold and print escaped raw identifiers and introduces another struct `UnescapedName` for cases where you need to print names without "r#" prefix.

My rationale is that it makes it easier for us to format an escaped name into string, which is what we want when we serialize names in general. This is because we format a name into string usually when we are presenting it to the users and arguably they expect its escaped form as that's what they see and write in the source code.

I split the change for `Name` into 3 commits to make it easier to follow but it also made some tests fail in the intermediate commits. I can squash them into a commit after the review if desired. I've also made similar changes for `ModPath` and `EscapedModPath` as it makes them consistent with `Name`.

For reference, there was a brief discussion on this in [a zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/escaping.20.60Name.60s).
2022-08-12 14:53:45 +00:00
bors
696bee3246 Auto merge of #12997 - Veykril:no-such-field, r=Veykril
fix: Fix panic in `no_such_field` when using tuple fields on record structs
2022-08-11 08:42:04 +00:00
Lukas Wirth
1bb58205f0 Fix panic in no_such_field when using tuple fields on record structs 2022-08-11 10:41:30 +02:00
Ryo Yoshida
ba6db3e9b0
Add test for runnables with raw identifiers 2022-08-11 03:41:23 +09:00
Ryo Yoshida
018266a7ff
Make ModPath display escaped path 2022-08-11 03:41:10 +09:00
Ryo Yoshida
8fe73a2240
Make tests pass 2022-08-11 01:16:35 +09:00
Ryo Yoshida
4322cf7f5b
Remove EscapedName 2022-08-11 01:11:18 +09:00
Ryo Yoshida
53ec791dc6
Add UnescapedName and make Name hold escaped name 2022-08-11 01:03:08 +09:00
bors
3eb340fa4d Auto merge of #12989 - lnicola:rm-1-64-abi, r=Veykril
internal: Remove incomplete 1.64 ABI

This no longer works for current nightlies and should not be needed any more, since we can use the toolchain's proc macro server instead.
2022-08-10 14:53:21 +00:00
bors
b1e9bcddc2 Auto merge of #12984 - Veykril:keep-going, r=Veykril
Use `--keep-going` cargo flag when building build scripts

See https://github.com/rust-lang/rust-analyzer/issues/12973#issuecomment-1209159426
2022-08-10 14:43:23 +00:00
bors
e70681f208 Auto merge of #12992 - lowr:fix/type-inference-for-byte-string-pat, r=Veykril
fix: infer byte string pattern as `&[u8]` when matched against slices

Fixes #12630

c.f. [rustc_typeck](1603a70f82/compiler/rustc_typeck/src/check/pat.rs (L388-L404))
2022-08-10 11:05:02 +00:00
Ryo Yoshida
ffc6b42901
fix: infer byte string pattern as &[u8] when matched against slices 2022-08-10 19:17:13 +09:00
Edwin Cheng
c47914c6cf Fixes tests 2022-08-10 16:29:23 +08:00
Edwin Cheng
23e17cd581 Improve insert whitespace in mbe 2022-08-10 16:28:56 +08:00
Lukas Wirth
25d4fbe9da Re-try build script building with --keep-going 2022-08-10 10:23:46 +02:00
Laurențiu Nicola
f4f70c0e0d Remove incomplete 1.64 ABI 2022-08-10 10:49:49 +03:00
Justin Ridgewell
dc3219bb11 Suggest .await when type impls IntoFuture 2022-08-09 16:39:14 -04:00
Lukas Wirth
49d24f639f Recover from missing ellipsis in record literals for path expressions 2022-08-09 18:23:25 +02:00
Lukas Wirth
b3ac58dfb8 Add some more cov_marks 2022-08-09 18:08:05 +02:00
Lukas Wirth
8c9359b072 Fix pattern field completions not working for unions 2022-08-09 17:53:16 +02:00
Lukas Wirth
950de7c3c3 Use --keep-going cargo flag when building build scripts 2022-08-09 14:31:17 +02:00
Justin Ridgewell
5810c8188a Implement IntoFuture type inference 2022-08-08 21:05:56 -04:00
KaDiWa
232176b46a
remove imports that are also in edition 2021's prelude 2022-08-09 01:16:32 +02:00
bors
554f7f889e Auto merge of #12974 - fprasx:master, r=lnicola
Corrected order of printing op and `=`

Fixes https://github.com/rust-lang/rust-analyzer/issues/12971 where `Display` impl for assignment operators does `=+` instead of `+=`
2022-08-08 15:13:20 +00:00
fprasx
e39918f553 Corrected order of printing op and = 2022-08-08 11:05:18 -04:00
bors
79c22d5fb1 Auto merge of #12962 - lowr:patch/parse-last-range-pattern, r=Veykril
Parse range patterns in struct and slice without trailing comma

Resolves #12935

This patch includes the support for range patterns in slices, which is unstable (tracked in https://github.com/rust-lang/rust/issues/67264). If it's not desired I can remove it.
2022-08-08 15:03:39 +00:00
Ryo Yoshida
b14062aaec
Parse range patterns in let statement with type annotation 2022-08-09 00:00:22 +09:00
bors
20d64412c0 Auto merge of #12951 - jonas-schievink:doc-cli-stability, r=Veykril
internal: Document CLI flag stability
2022-08-08 11:56:44 +00:00
bors
3805067bf5 Auto merge of #12905 - HKalbasi:master, r=Veykril
Generate rust type from json

fix #10118

Should this be a diagnostic? I made it a diagnostic because of issue label.
2022-08-08 11:46:22 +00:00
bors
b481b59be5 Auto merge of #12937 - fprasx:master, r=Veykril
Add fixups for incomplete in proc-macros

Partially implements https://github.com/rust-lang/rust-analyzer/issues/12777.

Added support for for loops and match statements.

I couldn't do paths like `crate::foo::` as I wasn't able to add `SyntheticTokens` to the end of `foo::`, they always ended up after `crate::`

This is my first contribution so please don't be shy about letting me know if I've done anything wrong!
2022-08-08 11:37:51 +00:00
bors
b569bbbacc Auto merge of #12942 - lowr:fix/concat-with-char, r=Veykril
fix: make `concat!` work with char

Fixes #12921

- I avoided making `unquote_str()` take char literals as well because it's depended on by another function `parse_string()` that's only supposed to take strings.
- Even with this patch, we don't output `\0` as `\u{0}` which #12921 pointed out ~~, but we're not actually responsible for serializing it but rowan is~~. They are functionally equivalent and I don't think it'd cause any confusion, but we *could* try escaping them before serialization (for reference, `rustc -Zunpretty=expanded`, which `cargo expand` uses under the hood, [makes use of `str::escape_default()`](3830ecaa8d/compiler/rustc_ast/src/util/literal.rs (L161)).
2022-08-08 11:28:42 +00:00
Kartavya Vashishtha
c1eae3d028
make diagnostic function public 2022-08-08 16:45:27 +05:30
Kartavya Vashishtha
196f389a70
try adding diagnostrics for AssocItems 2022-08-08 16:40:29 +05:30
Kartavya Vashishtha
1883d1f141
activate assoc item test 2022-08-07 20:39:11 +05:30
bors
634cfe3d72 Auto merge of #12956 - oxalica:feat/la-arena-apis, r=lnicola
More methods and traits for `la_arena::ArenaMap`

Continue of #12931. Seems that I forgot some methods in the previous PR :(

I also changed `ArenaMap::insert` to return the old value, to match the map-like collection API of std. **So this is a breaking change.**

r? `@lnicola`
2022-08-07 08:50:23 +00:00
Ryo Yoshida
a81c7a2974
Parse range patterns in struct and slice without trailing comma 2022-08-07 17:19:15 +09:00
Laurențiu Nicola
eca6f2e897 Fix test_rainbow_highlighting gate 2022-08-07 09:29:26 +03:00
oxalica
326ffee5b7 Returns the old value for la_arena::ArenaMap::insert 2022-08-07 04:53:23 +08:00
hkalbasi
851f6db7f7 Import serde derives on converting json to struct 2022-08-06 20:12:21 +04:30
Adrian Stanciu
e8a9bc09a3 run stable fmt through rustup 2022-08-06 17:25:02 +03:00
Jonas Schievink
fd00bd4d3b Document CLI flag stability 2022-08-05 15:28:53 +02:00
bors
3792720086 Auto merge of #12947 - Veykril:switch-workspace, r=Veykril
Don't switch workspace on vfs file changes from libraries

When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
2022-08-05 13:13:44 +00:00
bors
97038e55cf Auto merge of #12949 - Veykril:token-pick, r=Veykril
fix: Fix incorrect token pick rankings
2022-08-05 13:06:10 +00:00
Ryo Yoshida
4d5873e92f
minor: align with rustc on escaping characters in macro expansion 2022-08-05 22:01:09 +09:00
Lukas Wirth
6bf674c8e4 fix: Fix incorrect token pick rankings 2022-08-05 14:59:26 +02:00
Lukas Wirth
8aa50e08af Simplify 2022-08-05 14:54:14 +02:00
Lukas Wirth
352d3c6e50 Fix visibilities 2022-08-05 14:28:36 +02:00
Lukas Wirth
d6e78b04d0 feat: Handle operators like their trait functions in the IDE 2022-08-05 14:16:36 +02:00
Lukas Wirth
6a1737242b Don't switch workspace on vfs file changes from libraries
When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
2022-08-05 12:06:42 +02:00
Ryo Yoshida
859d467276
fix: make concat! work with char 2022-08-05 02:58:16 +09:00
fprasx
ab44a81150 Fixed up for loops, added fixme with problem
https://github.com/rust-lang/rust-analyzer/pull/12937#discussion_r937633695
2022-08-04 10:43:09 -04:00
fprasx
d6d8a1c18f Shortened fixup for match, added cases for for
Previously added a blank _ => {} for match statements
2022-08-04 09:28:25 -04:00
bors
0fe3bcfd35 Auto merge of #12808 - Veykril:check-workspace, r=Veykril
feat: Only flycheck workspace that belongs to saved file

Supercedes https://github.com/rust-lang/rust-analyzer/pull/11038

There is still the problem that all the diagnostics are cleared, only clearing diagnostics of the relevant workspace isn't easily doable though I think, will have to dig into that
2022-08-04 12:57:04 +00:00
Lukas Wirth
df7f755e3b Don't flycheck while the workspace is being loaded 2022-08-04 14:56:44 +02:00
Jean santos
5698e51027 tidy formatting 2022-08-04 09:28:34 -03:00
Lukas Wirth
df9d3db82f Trigger flycheck on all transitive dependencies as well 2022-08-04 13:22:15 +02:00
Jean santos
49dac4070c on hover fallback error, adds ast::type as possible node 2022-08-03 17:37:11 -03:00
fprasx
ef2eabbfa8 Tidy formatted 2022-08-03 16:27:43 -04:00
fprasx
d513b4c8ba Added fixup for for loops w/ missing parts 2022-08-03 15:59:17 -04:00
fprasx
5cb3e7a41b Added fixup for match statements w/ missing parts
Passes tests
2022-08-03 15:59:17 -04:00
bors
2bc9a2d9e0 Auto merge of #12933 - Veykril:proc-ignored, r=Veykril
Use an empty expander for ignored non-attribute proc-macros

Identity is the wrong behaviour for anything that's not an attribute here
2022-08-03 16:11:08 +00:00