Commit graph

15751 commits

Author SHA1 Message Date
bors
2f02ea03b0 Auto merge of #13041 - DorianListens:dscheidt/gen-fn-self-assoc-2, r=Veykril
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-19 10:57:02 +00:00
bors
62c3107065 Auto merge of #13061 - ice1k:master, r=Veykril
feat: Improved inline_call to replace `Self`

Fixes #13060
2022-08-19 10:47:15 +00:00
bors
a2ad3d0669 Auto merge of #13064 - Veykril:rustfmt-err, r=Veykril
Log rustfmt parsing errors as warnings

We unconditionally pass an edition parameter to rustfmt, for some crates
this might fail rustfmt so instead of swallowing the error, at least Log
it on a level that is logged by default so users won't be completely
confused about it.
See for context https://github.com/rust-lang/rust-analyzer/issues/10209

Closes https://github.com/rust-lang/rust-analyzer/issues/10209
2022-08-19 07:23:01 +00:00
Lukas Wirth
638755a771 Log rustfmt parsing errors as warnings
We unconditionally pass an edition parameter to rustfmt, for some crates
this might fail rustfmt so instead of swallowing the error, at least Log
it on a level that is logged by default so users won't be completely
confused about it.
See for context https://github.com/rust-lang/rust-analyzer/issues/10209

Closes https://github.com/rust-lang/rust-analyzer/issues/10209
2022-08-19 09:22:34 +02:00
Lukas Wirth
45b7b6a60a Implement lsp extension for cancelling running flychecks 2022-08-19 08:54:53 +02:00
ice1000
5a6c51ebb8 fix: use functional programming 2022-08-19 01:22:43 +00:00
ice1000
b6fe46055b feat: Improved inline_call to replace Self 2022-08-19 01:06:00 +00:00
Dorian Scheidt
48ea3825b8 Introduce and use get_fn_target_info 2022-08-18 18:39:42 -05:00
Dorian Scheidt
d8e7419c64 Generate and use TargetInfo::new 2022-08-18 18:32:35 -05:00
Dorian Scheidt
2e4a4f1a9c Cleanup inline 2022-08-18 18:28:43 -05:00
Dorian Scheidt
96c04c5e1c inline assoc_fn_target 2022-08-18 18:28:14 -05:00
Dorian Scheidt
2086c48cff Remove mut out params via assoc_fn_target_info 2022-08-18 18:26:54 -05:00
Dorian Scheidt
e27af5fae3 Reorder args with flip_comma 2022-08-18 18:21:58 -05:00
Dorian Scheidt
e513d7b504 Replace tuple with TargetInfo struct 2022-08-18 18:20:06 -05:00
Dorian Scheidt
30eabeb95d extract fn_target_info 2022-08-18 18:14:51 -05:00
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
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