Commit graph

30229 commits

Author SHA1 Message Date
Hamir Mahal
7fa555f8ba
fix: formatting in handlers/unresolved_method.rs 2024-05-30 16:39:41 -07:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
bors
b32f181f47 Auto merge of #17258 - maxwase:code-assist-async-sugar, r=Veykril
Add `toggle_async_sugar` assist code action

Implement code action for sugaring and de-sugaring asynchronous functions.

This code action does not import `Future` trait when de-sugaring and does not touch function boby, I guess this can be implemented later if needed. This action also does not take into consideration other bounds because IMO it's usually "let me try to use sugared version here".

Feel free to request changes, that's my first code action implementation 😄

Closes #17010
Relates to #16195
2024-05-27 16:40:04 +00:00
bors
f59ca41f23 Auto merge of #17253 - ThouCheese:master, r=Veykril
Implement assist to switch between doc and normal comments

Hey first PR to rust-analyzer to get my feet wet with the code base. It's an assist to switch a normal comment to a doc comment and back, something I've found myself doing by hand a couple of times.

I shamelessly stole `relevant_line_comments` from `convert_comment_block`, because I didn't see any inter-assist imports happening in the files I peeked at so I thought this would be preferable.
2024-05-27 16:27:23 +00:00
bors
16fd9aa373 Auto merge of #17291 - kilpkonn:master, r=Veykril
Fix `data_constructor` ignoring generics for struct

Previously didn't work for structs with generics due to `field.ty()` having placeholders in type.
_Enums were handeled correctly already._

Also renamed `type_constructor -> data_constructor` as this is more correct name for it
2024-05-27 16:15:10 +00:00
bors
71a816a90f Auto merge of #17296 - mathew-horner:no-clone-target, r=Veykril
Avoid clone when constructing runnable label.

I stumbled across this when reading this code. This seems like an unnecessary allocation (though likely small?)
2024-05-26 09:11:55 +00:00
bors
8c18cbc29c Auto merge of #17295 - 0xJonas:fix_passing_env_vars_to_cpptools, r=Veykril
Use correct format for setting environment variables when debugging with cpptools

The RA VSCode extension uses an incorrect format for the environment variables in the `launch.json` when debugging with the C/C++ Extension. This extension uses a different format than CodeLLDB or NativeDebug, which means that the environment variables are not actually set for the debuggee.

What it currently looks like:
```json
"env": {
  "NAME": "VALUE"
}
```

What the C/C++ extension expects:
```json
"environment": [
  { "name": "NAME", "value": "VALUE" }
]
```

For reference: https://code.visualstudio.com/docs/cpp/launch-json-reference#_environment
2024-05-26 08:59:22 +00:00
Jonas Rinke
2616b7e045 Removed return 2024-05-25 22:42:39 +02:00
Mathew Horner
333bedd70f
Avoid clone when constructing runnable label. 2024-05-25 15:00:15 -05:00
Jonas Rinke
84ab0d83d5 Formatting 2024-05-25 17:08:17 +02:00
Jonas Rinke
cb28175d22 Semicolon 2024-05-25 17:04:48 +02:00
Jonas Rinke
aaa7e3a3c4 Use correct format for setting environment variables when debugging with cpptools 2024-05-25 16:53:01 +02:00
Tavo Annus
0f6842700f Fix data_constructor ignoring generics for struct 2024-05-25 13:09:26 +03:00
Luuk Wester
9e5ff0dce7 remove nested match with and_then 2024-05-24 22:57:35 +02:00
Luuk Wester
f5d740aa3d add test for every keyword, fix bug 2024-05-24 22:41:49 +02:00
Luuk Wester
2400673ca6 cosmetic and performance fixes, and drop support for adding //! comments anywhere, except
for at the top of files.
2024-05-24 21:56:55 +02:00
bors
a55e8bf09c Auto merge of #17275 - roife:fix-issue-17012, r=Veykril
Fix inconsistent cwd of `run` and `debug` command in client

Fix #17012. Also related to #13022 and #15993.

When the `kind` of runnable is `bin`, Cargo would use the workspace root as the cwd for the `run` command; otherwise, Cargo defaults to the package root as the cwd for `run`.

Initially, r-a assumed the workspace root as the cwd for all runnables in `debug` command, which led to issue #13022. In this case, during unit testing, the `run` command would use the package root while `debug` would use the workspace root, causing inconsistency.

PR #15993 addressed this problem by using the package root as the cwd for `debug` command. However, it also resulted in an inconsistency: when executing the `run` command within the main fn of a package (whose target is `bin`), Cargo would use the workspace root, whereas `debug` would use the package root, leading to issue #17012.

The preferable approach is to determine the cwd based on the runnable's type. To resolve this, this PR introduces a new `cwd` field within `CargoRunnable`, allowing r-a to decide the appropriate cwd depending on the specific kind of the runnable.
2024-05-24 17:43:35 +00:00
maxwase
61f8ef5d57 Review fixes: Assist scope, trait qualify 2024-05-24 02:17:44 +03:00
maxwase
624f99b4b9 Review fixes: Split into 2, check tuple fields 2024-05-24 01:10:18 +03:00
maxwase
2657078573 Add toggle_async_sugar assist code action 2024-05-24 01:08:21 +03:00
roife
a8031e33fd tests: update test for runnables 2024-05-24 03:53:38 +08:00
roife
ef59b49f7e Update docs 2024-05-24 03:53:36 +08:00
roife
f4d3547bc6 Use cwd from runnable.args for debugger 2024-05-24 03:51:05 +08:00
roife
89843ba083 Revert "Debug use cargo workspace root as cwd. fixes #13022"
This reverts commit 4ca86edac9.
2024-05-24 03:51:05 +08:00
roife
c43d59c709 Add cwd to CargoRunnable 2024-05-24 03:51:04 +08:00
bors
f6fc109fcb Auto merge of #17287 - Veykril:sysroot-encode-empty, r=Veykril
Allow sysroots to only consist of the source root dir

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

This PR encodes the `None` case of an optional sysroot into `Sysroot` itself. This simplifies a lot of things and allows us to have sysroots that consist of nothing, only standard library sources, everything but the standard library sources or everything. This makes things a lot more flexible. Additionally, this removes the workspace status bar info again, as it turns out that that can be too much information for the status bar to handle (this is better rendered somewhere else, like in the status view).
2024-05-23 18:13:47 +00:00
Lukas Wirth
bd37e2790b Allow sysroots to only consist of the source root dir 2024-05-23 20:12:31 +02:00
bors
f372a8a117 Auto merge of #17284 - Veykril:doc-links, r=Veykril
fix: Use correct toolchain channel when generating builtin type doc links
2024-05-23 08:55:08 +00:00
Lukas Wirth
5717622c95 Use correct toolchain channel when generating builtin type doc links 2024-05-23 10:42:15 +02:00
bors
dec43b6cb3 Auto merge of #17174 - Kohei316:fix-infer-async-block-with-tail-return-expr, r=Veykril
Fix: infer type of async block with tail return expr

Fixes #17106
The `infer_async_block` method calls the `infer_block` method internally, which returns the never type without coercion when `tail_expr` is `None` and `ctx.diverges` is `Diverges::Always`.This is the reason for the bug in this issue.
cfce2bb46d/crates/hir-ty/src/infer/expr.rs (L1411-L1413)

This PR solves the bug by adding a process to coerce after calling `infer_block` method.

This code passes all the tests, including tests I added for this isuue, however, I am not sure if this solution is right. I think that this solution is an ad hoc solution. So, I would appreciate to have your review.
I apologize if I'm off the mark, but `infer_async_block` method should be rewritten to share code with the process of infering type of `expr::Closure` instead of the `infer_block` method. That way it will be closer to the infer process of rustc.
2024-05-23 08:42:09 +00:00
Lukas Wirth
ac3b2d4b54
Update crates/hir-ty/src/infer/expr.rs 2024-05-23 10:36:57 +02:00
bors
e3e22c67e0 Auto merge of #17140 - harrysarson:harry-unused-self, r=Veykril
handle {self} when removing unused imports

Fixes #17139

On master

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner::{self, X}$0;

    fn f() {
        let y = inner::Y();
    }
}
```

becomes

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner:self;

    fn f() {
        let y = inner::Y();
    }
}
```

with this fix it instead becomes

```

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner;

    fn f() {
        let y = inner::Y();
    }
}
```
2024-05-23 08:30:10 +00:00
bors
653b69eb42 Auto merge of #17270 - davidbarsky:david/fix-completions-from-associated-types, r=Veykril
fix: ensure implied bounds from associated types are considered in autocomplete

closes: #16989

rust-analyzer needs to consider implied bounds from associated types in order to get all methods suggestions people expect. A pretty easy way to do that is to keep the `candidate_trait_id`'s receiver if it matches `TyFingerprint::Unnameable`.  When benchmarking this change, I didn't notice a meaningful difference in autocomplete latency.

(`TyFingerprint::Unnameable` corresponds to `TyKind::AssociatedType`, `TyKind::OpaqueType`, `TyKind::FnDef`, `TyKind::Closure`, `TyKind::Coroutine`, and `TyKind::CoroutineWitness`.)
2024-05-22 20:38:28 +00:00
David Barsky
a0d3a81a19 fix: ensure implied bounds from associated types are considered in autocomplete 2024-05-22 16:16:20 -04:00
bors
d4da3f925c Auto merge of #17251 - roife:fix-issue-17057, r=Veykril
fix: resolve extern prelude for local mods in block modules

fix https://github.com/rust-lang/rust-analyzer/issues/17057, https://github.com/rust-lang/rust-analyzer/issues/17032.

We should use `ModuleOrigin` to check if the current module is a pseudo-module introduced by blocks (where names might be shadowed), rather than checking `block_def_map`.
2024-05-22 20:11:24 +00:00
bors
870ad35245 Auto merge of #17252 - davidbarsky:david/refactor-standalone-bools-into-struct, r=Veykril
internal: refactor `prefer_no_std`/`prefer_prelude` bools into a struct

I noticed that there's a large number of functions/arguments during an unrelated change that take two booleans and realized they're _probably_ better off being in a single struct—less error-prone, etc.

Feel free to suggest a better name than `ImportPathConfig`/close this entirely! I can also make these args enums; just hopefully making this a little more misuse-resistant.
2024-05-22 19:59:04 +00:00
Lukas Wirth
3a7dcf91c4 Simplify 2024-05-22 21:57:44 +02:00
David Barsky
b75301cec8 internal: refactor prefer_no_std/prefer_prelude bools into a struct 2024-05-22 20:46:30 +02:00
roife
d9cc159b26 fix: check pseudo-block by local_id instead of ModuleOrigin 2024-05-23 02:39:53 +08:00
bors
6a16749eb0 Auto merge of #17277 - Veykril:find-path-fixes, r=Veykril
fix: Various find path fixes

Fixes https://github.com/rust-lang/rust-analyzer/issues/17271
2024-05-22 18:22:32 +00:00
bors
42a8500ebf Auto merge of #17279 - Veykril:format_args-escape, r=Veykril
fix: Fix format_args lowering passing incorrect parameters to `rustc_parse_format`
2024-05-22 14:12:22 +00:00
Lukas Wirth
4f17d07e69 fix: Fix format_args lowering passing incorrect parameters to rustc_parse_format 2024-05-22 16:11:06 +02:00
bors
2dc22c658a Auto merge of #17248 - mladedav:dm/delay-clear, r=Veykril
Clear diagnostics only after new ones were received

Closes #15934

This adds a flag inside the global state which controls when old diagnostics are cleared. Now, old diagnostics should be cleared only after at least one new diagnostic is available.
2024-05-22 13:01:08 +00:00
bors
daf66ad8eb Auto merge of #17268 - Veykril:signatures, r=Veykril
feat: More callable info

With this PR we retain more info about callables other than functions, allowing for closure parameter type inlay hints to be linkable as well as better signature help around closures and `Fn*` implementors.
2024-05-22 12:48:17 +00:00
Lukas Wirth
760ad445e2 Update assists test fixtures 2024-05-22 14:46:33 +02:00
Lukas Wirth
ca06b090d7 expectify find_path tests 2024-05-22 14:05:24 +02:00
Lukas Wirth
c88b421853 fix: Fix general find-path inconsistencies 2024-05-22 14:05:24 +02:00
roife
48dc20f80d test: add tests for extern preludes resolving in local mods 2024-05-21 20:35:55 +08:00
bors
21ec8f5238 Auto merge of #17259 - lnicola:sync-from-rust, r=lnicola
internal: Sync from downstream
2024-05-19 08:28:03 +00:00
Laurențiu Nicola
5a12cfcee0 Bump rustc crates 2024-05-19 11:22:58 +03:00