Commit Graph

27051 Commits

Author SHA1 Message Date
l1nxy
161d3055d1 use tail_expr(). 2024-01-03 09:48:49 +08:00
bors
426d2842c1 Auto merge of #16222 - rosefromthedead:unresolved-assoc-item, r=Veykril
add unresolved-assoc-item assist

I tried to copy from private-assoc-item for this
2024-01-02 15:06:13 +00:00
bors
86e559bf3f Auto merge of #16211 - tetsuharuohzeki:update-lint, r=Veykril
Use Cargo's [workspace.lints.*] to config clippy

This change begin to use [`[workspace.lints.*]`](https://doc.rust-lang.org/cargo/reference/workspaces.html#the-lints-table) that is stabilized since [Rust 1.74](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html).

By this change, we make the configure more readable and simplify `xargo lint` more.
2024-01-02 14:53:22 +00:00
bors
1a0b772a43 Auto merge of #16153 - Veykril:err-msg, r=Veykril
fix: Notify user that linkedProjects is set when failing to discover projects

Fixes https://github.com/rust-lang/rust-analyzer/issues/15171
2024-01-02 14:42:03 +00:00
Lukas Wirth
8136e739f5 fix: Notify user that linkedProjects is set when failing to discover projects 2024-01-02 15:24:21 +01:00
bors
df94a87ea8 Auto merge of #16139 - jimmyhmiller:master, r=Veykril
Make functions in impl have a container name

fixes #16015
2024-01-02 14:08:37 +00:00
bors
7040cef07d Auto merge of #16068 - roife:fix-introduce-named-generic-name-conflicts, r=Veykril
fix: pick up new names when the name conflicts in 'introduce_named_generic'

Improve generation of names for generic parameters in `introduce_named_generics`.

fix #15731.

### Changes

- Modified `for_generic_parameter` function in `suggest_name.rs` to handle conflicts with existing generic parameters and generate unique names accordingly.
- Update `introduce_named_generic` function and pass existing params to `for_generic_parameter`, enabling the detection and handling of name collisions.
2024-01-02 13:58:06 +00:00
bors
f7a29e4e88 Auto merge of #16100 - Young-Flash:assoc_func_quickfix, r=Veykril
feat: add assoc func quickfix for `unresolved_method` diagnostic

![demo](https://github.com/rust-lang/rust-analyzer/assets/71162630/1ea1d8b8-3436-4251-a512-e0f9de01a13c)

close https://github.com/rust-lang/rust-analyzer/issues/13247

EDIT: I think add a demo gif would be helpful to `@lnicola` when he make a release change log :)
2024-01-02 13:46:35 +00:00
bors
76591096fb Auto merge of #16136 - saiintbrisson:fix/completion/a-tad-smarter-with-fns, r=Veykril
fix(completion): make the expected type a tad smarter with `Fn`s

This commit changes how the expected type is calculated when
working with Fn pointers, making the parenthesis stop vanishing
when completing the function name.

I've been bugged by the behavior of parenthesis completion for
a long while now. R-a assumes that the `LetStmt` type is the same
as the function type I've just written. Worse is that all parenthesis
vanish, even from functions that have completely different signatures.
It will now verify if the signature is the same.

While working on this, I noticed that record fields behave the same,
so I also made it prioritize the field type instead of the current
expression when possible, but I'm unsure if this is OK, so input is
appreciated.

ImplTraits as return types will still behave weirdly because lowering
is disallowed at the time it resolves the function types.

![image](https://github.com/rust-lang/rust-analyzer/assets/29989290/c06d6c93-5cac-4ebe-a93b-923017a6ae8c)
![image](https://github.com/rust-lang/rust-analyzer/assets/29989290/31594d82-fa4d-446c-a77e-47e9de1a9a67)
![image](https://github.com/rust-lang/rust-analyzer/assets/29989290/cf33856e-a485-411b-91af-11090d78a44e)
2024-01-02 13:35:42 +00:00
roife
919ecc6c32 Use HashSet to enhance performance in for_unique_generic_name in suggest_name 2024-01-02 21:33:06 +08:00
roife
bc1a5774fd fix: handle with type bounds in existing_params 2024-01-02 21:30:57 +08:00
roife
186553dab8 refactor: extracted the fn handling conflicts in generics and add docs
* Extracted the function `for_unique_generic_name` that handling generics with identical names for reusability.
* Renamed `for_generic_params` to `for_impl_trait_as_generic` for clarity
* Added documentations for `for_impl_trait_as_generic` and `for_unique_generic_name`
2024-01-02 21:30:57 +08:00
roife
e8dc8ccc59 fix: pick up new names when the name exists in 'introduce_named_generic' 2024-01-02 21:30:55 +08:00
Luiz Carvalho
9a36bc393d
fix(completion): render fn type 2024-01-02 10:30:16 -03:00
Young-Flash
91bd59682a fix: make editing range accommodate for macros 2024-01-02 21:30:13 +08:00
Luiz Carvalho
ed216e285d
fix(completion): make the expected type a tad smarter with Fns
This commit changes how the expected type is calculated when working
with Fn pointers, making the parenthesis stop vanishing when completing
the function name.

I've been bugged by the behaviour on parenthesis completion for a long
while now. R-a assumes that the `LetStmt` type is the same as the
function type I've just written. Worse is that all parenthesis vanish,
even from functions that have completely different signatures. It will
now verify if the signature is the same.

While working on this, I noticed that record fields behave the same, so
I also made it prioritize the field type instead of the current
expression when possible, but I'm unsure if this is OK, so input is
appreciated.

ImplTraits as return types will still behave weirdly because lowering is
disallowed at the time it resolves the function types.
2024-01-02 10:28:49 -03:00
Young-Flash
481fab1591 chore: add test case for assoc func fix in unresolved_method diagnostic 2024-01-02 20:53:41 +08:00
Young-Flash
69410bb488 feat: add assoc func quickfix for unresolved_method diagnostic 2024-01-02 20:53:41 +08:00
bors
34df29620a Auto merge of #16112 - roife:rewrite-generate-delete-trait, r=Veykril
fix: rewrite code_action `generate_delegate_trait`

I've made substantial enhancements to the "generate delegate trait" code action in rust-analyzer. Here's a summary of the changes:

#### Resolved the "Can’t find CONST_ARG@158..159 in AstIdMap" error

Fix #15804, fix #15968, fix #15108

The issue stemmed from an incorrect application of PathTransform in the original code. Previously, a new 'impl' was generated first and then transformed, causing PathTransform to fail in locating the correct AST node, resulting in an error. I rectified this by performing the transformation before generating the new 'impl' (using make::impl_trait), ensuring a step-by-step transformation of associated items.

#### Rectified generation of `Self` type

`generate_delegate_trait` is unable to properly handle trait with `Self` type.

Let's take the following code as an example:

```rust
trait Trait {
    fn f() -> Self;
}

struct B {}
impl Trait for B {
    fn f() -> B { B{} }
}

struct S {
    b: B,
}
```

Here, if we implement `Trait` for `S`, the type of `f` should be `() -> Self`, i.e. `() -> S`. However we cannot automatically generate a function that constructs `S`.

To ensure that the code action doesn't generate delegate traits for traits with Self types, I add a function named `has_self_type` to handle it.

#### Extended support for generics in structs and fields within this code action

The former version of `generate_delegate_trait` cannot handle structs with generics properly. Here's an example:

```rust
struct B<T> {
    a: T
}

trait Trait<T> {
    fn f(a: T);
}

impl<T1, T2> Trait<T1> for B<T2> {
    fn f(a: T1) -> T2 { self.a }
}

struct A {}
struct S {
    b$0 : B<A>,
}
```

The former version  will generates improper code:

```rust
impl<T1, T2> Trait<T1, T2> for S {
    fn f(&self, a: T1) -> T1 {
        <B as Trait<T1, T2>>::f( &self.b , a)
    }
}
```

The rewritten version can handle generics properly:

```rust
impl<T1> Trait<T1> for S {
    fn f(&self, a: T1) -> T1 {
        <B<A> as Trait<T1>>::f(&self.b, a)
    }
}
```

See more examples in added unit tests.

I enabled support for generic structs in `generate_delegate_trait` through the following steps (using the code example provided):

1. Initially, to prevent conflicts between the generic parameters in struct `S` and the ones in the impl of `B`, I renamed the generic parameters of `S`.
2. Then, since `B`'s parameters are instantiated within `S`, the original generic parameters of `B` needed removal within `S` (to avoid errors from redundant parameters). An important consideration here arises when Trait and B share parameters in `B`'s impl. In such cases, these shared generic parameters cannot be removed.
3. Next, I addressed the matching of types between `B`'s type in `S` and its type in the impl. Given that some generic parameters in the impl are instantiated in `B`, I replaced these parameters with their instantiated results using PathTransform. For instance, in the example provided, matching `B<A>` and `B<T2>`, where `T2` is instantiated as `A`, I replaced all occurrences of `T2` in the impl with `A` (i.e. apply the instantiated generic arguments to the params).
4. Finally, I performed transformations on each assoc item (also to prevent the initial issue) and handled redundant where clauses.

For a more detailed explanation, please refer to the code and comments. I welcome suggestions and any further questions!
2024-01-02 12:30:19 +00:00
bors
22f189b6bb Auto merge of #16228 - Veykril:arch.md, r=Veykril
minor: Add some more crates to architecture.md
2024-01-02 11:33:53 +00:00
Lukas Wirth
16457abe0e Add some more crates to architecture.md 2024-01-02 12:32:20 +01:00
bors
306defaef4 Auto merge of #16114 - roife:fix-inline-with-self-type, r=Veykril
fix: self type replacement in inline-function

Fix #16113, fix #16091

The problem described in this issue actually involves three bugs.

Firstly, when using `ted` to modify the syntax tree, the offset of nodes on the tree changes, which causes the syntax range information from `hir` to become invalid. Therefore, we need to edit the AST after the last usage for `usages_for_locals`.

The second issue is that when inserting nodes, it's necessary to use `clone_subtree` for duplication because the `ted::replace` operation essentially moves a node.

The third issue is that we should use `ancestors_with_macros` instead of `ancestors` to handle impl definition in macros.

I have fixed the three bugs mentioned above and added unit tests.
2024-01-02 10:53:35 +00:00
bors
792c94621d Auto merge of #16082 - DropDemBits:structured-snippet-migrate-5, r=Veykril
internal: Migrate assists to the structured snippet API, part 5

Continuing from #15874

Migrates the following assists:

- `extract_variable`
- `generate_function`
- `replace_is_some_with_if_let_some`
- `replace_is_ok_with_if_let_ok`
2024-01-02 10:42:16 +00:00
bors
ee0d99d98e Auto merge of #16081 - riverbl:trailing-whitespace, r=Veykril
Don't trim trailing whitespace from doc comments

Don't trim trailing whitespace from doc comments as multiple trailing spaces indicates a hard line break in Markdown.

I'd have liked to add a unit test for `docs_from_attrs`, but couldn't find a reasonable way to get an `&Attrs` object for use in the test.

Fixes #15877.
2024-01-02 10:30:58 +00:00
bors
60fe5fd98d Auto merge of #16049 - dfireBird:followup-callable-fields, r=Veykril
fix: make callable fields not complete in method access no parens case

Follow up PR for #15879

Fixes the callable field completion appearing in the method access with no parens case.
2024-01-02 10:20:31 +00:00
bors
e53a115fe1 Auto merge of #16067 - roife:fix-introduce-named-generic-impl-inside-types, r=Veykril
fix: no code action 'introduce_named_generic' for impl inside types

Fix #15734.

### Changes Made
- Find params in `ancestors` instead of just `parent`
- Added tests (`replace_impl_with_mut` and `replace_impl_inside`)
2024-01-02 10:09:14 +00:00
bors
9f46ff501d Auto merge of #16062 - davidbarsky:david/fix-references-to-removed-settings, r=Veykril
fix: Correct references from `rust-analyzer.cargo.check` to `rust-analyzer.check`

When reading the manual, I noticed that the documentation referenced configurations that have since been renamed. This PR updates those references to their new names.
2024-01-02 09:57:48 +00:00
bors
f1de7d7273 Auto merge of #16011 - ClSlaid:feat/settings/proc-macro/rebuild-on-save, r=Veykril
feat: add proc-macro rebuild on save option

Related: #15033

I need some advice on how to test it.
2024-01-02 09:46:21 +00:00
bors
e461efb636 Auto merge of #15810 - rmehri01:assist_panics_in_macros, r=Veykril
fix: assists panic when trying to edit usage inside macro

When we try to make a syntax node mutable inside a macro to edit it, it seems like the edits aren't properly reflected and will cause a panic when trying to make another syntax node mutable.

This PR changes `bool_to_enum` and `promote_local_to_const` to use the original syntax range instead to edit the original file instead of the macro file. I'm not sure how to do it for `inline_call` with the example I mentioned in the issue, so I've left it out for now.

Fixes #15807
2024-01-02 09:35:08 +00:00
Ryan Mehri
b105e9b342 fix: use original range to deal with macros in promote_local_to_const 2024-01-02 10:33:48 +01:00
Ryan Mehri
9f6a2c4564 fix: use original range to deal with macros in bool_to_enum 2024-01-02 10:33:48 +01:00
Ryan Mehri
b5e0edf427 style: clean up bool_to_enum assist 2024-01-02 10:33:46 +01:00
Ryan Mehri
2034556f81 fix: add test for missing case in bool_to_enum 2024-01-02 10:32:43 +01:00
Lukas Wirth
c99089c2b3
Update crates/rust-analyzer/src/handlers/notification.rs 2024-01-02 10:27:41 +01:00
l1nxy
a3be52cbc0 tidy. 2024-01-01 22:31:04 +08:00
l1nxy
b6a14ce5b8 fix doc test. 2024-01-01 22:11:45 +08:00
l1nxy
edb9ad21bd apply to only has nested if. 2024-01-01 21:53:57 +08:00
bors
a8d935eedc Auto merge of #16226 - Veykril:lsp-server, r=Veykril
internal: Expose whether a channel has been dropped in lsp-server errors

Not the best way to expose this, but this should allow us to give somewhat better errors when the initialization request is malformed, as currently that just results in a channel disconnected error instead of the deserialization error. cc https://github.com/rust-lang/rust-analyzer/issues/15859
2024-01-01 13:13:38 +00:00
Lukas Wirth
3c8dd9e89e Expose whether a channel has been dropped in lsp-server errors 2024-01-01 14:10:46 +01:00
bors
aef441ab3a Auto merge of #16225 - Veykril:status, r=Veykril
minor: Render more crate information in status command
2024-01-01 12:33:31 +00:00
Lukas Wirth
06be1b1f34 minor: Render more crate information in status command 2024-01-01 13:32:04 +01:00
bors
9db515503f Auto merge of #16224 - Veykril:syntax-ctx, r=Veykril
fix: Fix SyntaxContextID using incorrect self IDs

Follow up to https://github.com/rust-lang/rust-analyzer/issues/16200, there was another logical bug there.
2024-01-01 11:56:12 +00:00
Lukas Wirth
0c3fbba3b9 fix: Fix SyntaxContextID using incorrect self IDs 2024-01-01 12:54:30 +01:00
Young-Flash
4eb3d2e279 test: add test case for redundant_assoc_item quickfix 2024-01-01 11:19:12 +08:00
Young-Flash
613774e331 feat: add quickfix for redundant_assoc_item diagnostic 2024-01-01 11:17:06 +08:00
Rose Hudson
5878651e7e add unresolved-assoc-item diagnostic 2023-12-31 17:36:40 +00:00
bors
cf52c4b2b3 Auto merge of #16221 - holly-hacker:fix-16200, r=lnicola
fix: Fix out-of-bounds panic in some macros due to unhandled self_ref

Fixes #16200

I don't fully understand these changes, I just applied and tested the changes suggested in #16200 and they seem to fix the issue on both the repro and my original project.
2023-12-31 14:50:02 +00:00
HoLLy
c13330971d Fix out-of-bounds panic in some macros due to unhandled self_ref 2023-12-31 12:51:43 +01:00
austaras
1b7968a2cb fix: try obligation of IndexMut when infer 2023-12-31 07:19:16 +08:00
bors
e872f5085c Auto merge of #16217 - hurryabit:simplify-apply-change, r=lnicola
internal: Simplify implementation of apply_document_changes

While reading through the code base, I stumbled across a piece of code that I found hard to read despite its simple purpose. This is my attempt at making the code easier to understand for future readers.

I won't be offended if this is too minor and not worth your time.
2023-12-30 19:43:04 +00:00