Commit Graph

712 Commits

Author SHA1 Message Date
Lukas Wirth
8a5829cf28 Re-order mod declarations 2024-01-27 11:02:34 +01:00
r0cky
1a9ef233b7 Remove unused codes 2024-01-21 12:56:23 +08:00
bors
d4926c10b2 Auto merge of #16405 - dfireBird:guarded-return-for-loop, r=lnicola
fix: Include `for` construct in convert to guarded return conditions
2024-01-20 16:13:31 +00:00
dfireBird
721e79035d
include for in convert to guarded return assist 2024-01-20 19:26:50 +05:30
bors
0c764216d5 Auto merge of #16396 - Young-Flash:fix_marco, r=Veykril
fix panic with reference in macro

it panic at `builder.make_mut(segment)`, where segment is from macro expand. And the usage reference in orginal macro call isn't a `PathSegment` so we can't update it in `apply_references`, I can't find a way to deal with it properly so here just filter out the reference in macro. LMK if there are better way to fix this

try to close https://github.com/rust-lang/rust-analyzer/issues/16328
2024-01-20 08:12:44 +00:00
Young-Flash
f9b5e0d219 minor: use reference.range to get original range 2024-01-20 14:43:42 +08:00
Johann Hemmann
b1a0c9ac40 single_match 2024-01-19 18:31:15 +01:00
Johann Hemmann
71d4dba960 redundant_pattern_matching 2024-01-19 17:31:01 +01:00
Johann Hemmann
3cf1358eb8 question_mark 2024-01-19 17:31:01 +01:00
Johann Hemmann
6738edc259 ptr_arg 2024-01-19 17:31:01 +01:00
Johann Hemmann
e6f9f4c0e4 nonminimal_bool 2024-01-19 17:31:01 +01:00
Johann Hemmann
add40c8660 match_like_matches_macro 2024-01-19 17:31:01 +01:00
Johann Hemmann
b5eca5f2fc collapsible_if 2024-01-19 17:31:00 +01:00
bors
85c9a83262 Auto merge of #16398 - Urhengulas:satisfy-clippy, r=Veykril
`cargo clippy --fix`

This PR is the result of running `cargo clippy --fix && cargo fmt` in the root of the repository. I did not manually review all the changes, but just skimmed through a few of them. The tests still pass, so it seems fine.
2024-01-19 09:43:35 +00:00
davidsemakula
67c1c2bd14 update merge item assist implementation for "one" import granularity 2024-01-18 17:26:53 +03:00
Johann Hemmann
fad4fa163c cargo clippy --fix 2024-01-18 13:59:49 +01:00
Young-Flash
0bf986d718 add test case with marco reference 2024-01-18 17:43:44 +08:00
Young-Flash
bd26403130 fix panic with reference in macro 2024-01-18 17:43:15 +08:00
davidsemakula
7db4117156 respect "one" import granularity config in merge imports assist 2024-01-18 01:44:57 +03:00
davidsemakula
4f176b3f7f update import granularity config and docs 2024-01-18 01:44:57 +03:00
bors
f4fec4ff65 Auto merge of #16378 - roife:fix/issue-15470, r=Veykril
fix: better handling of SelfParam in assist 'inline_call'

fix #15470.

The current `inline_call` directly translates `&self` into `let ref this = ...;` and `&mut self` into `let ref mut this = ...;`. However, it does not handle some complex scenarios.

This PR addresses the following transformations (assuming the receiving object is `obj`):

- `self`: `let this = obj`
- `mut self`: `let mut this = obj`
- `&self`: `let this = &obj`
- `&mut self`
  + If `obj` is `let mut obj = ...`, use a mutable reference: `let this = &mut obj`
  + If `obj` is `let obj = &mut ...;`, perform a reborrow: `let this = &mut *obj`
2024-01-17 08:43:13 +00:00
roife
920e99aacb test: add tests for variant kinds of SelfParam in inline_call 2024-01-17 14:19:57 +08:00
roife
d48498f360 fix: better handling of SelfParam in inline_call 2024-01-17 13:49:07 +08:00
roife
7c94c29648 fix: make let_stmts inserted in inline_call correctly indented 2024-01-16 21:42:29 +08:00
Lukas Wirth
384488c157 feat: Hover for literals showing additional value information 2024-01-16 14:28:47 +01:00
bors
0a8c7841e0 Auto merge of #16352 - davidsemakula:rustfmt-import-sort-algo, r=Veykril
internal: Follow rustfmt's algorithm for ordering imports when ordering and merging use trees

Updates use tree ordering and merging utilities to follow rustfmt's algorithm for ordering imports.
The [rustfmt implementation](6356fca675/src/imports.rs) was used as reference.
2024-01-16 11:23:03 +00:00
Moritz Hedtke
f937673ce2 fix: rename generator to coroutine
Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
2024-01-15 12:24:47 +01:00
davidsemakula
22ae5f49ba order merged use trees 2024-01-12 17:05:23 +03:00
bors
d5366b5c19 Auto merge of #16265 - Patryk27:suggest-pub-crate-imports, r=Veykril
fix: Acknowledge `pub(crate)` imports in import suggestions

rust-analyzer has logic that discounts suggesting `use`s for private imports, but that logic is unnecessarily strict - for instance given this code:

```rust
mod foo {
    pub struct Foo;
}

pub(crate) use self::foo::*;

mod bar {
    fn main() {
        Foo$0;
    }
}
```

... RA will suggest to add `use crate::foo::Foo;`, which not only makes the code overly verbose (especially in larger code bases), but also is disjoint with what rustc itself suggests.

This commit adjusts the logic, so that `pub(crate)` imports are taken into account when generating the suggestions; considering rustc's behavior, I think this change doesn't warrant any extra configuration flag.

Note that this is my first commit to RA, so I guess the approach taken here might be suboptimal - certainly feels somewhat hacky, maybe there's some better way of finding out the optimal import path 😅
2024-01-11 09:54:22 +00:00
Patryk Wychowaniec
76aaf17794
Suggest pub(crate) imports
rust-analyzer has logic that discounts suggesting `use`s for private
imports, but that logic is unnecessarily strict - for instance given
this code:

```rust
mod foo {
    pub struct Foo;
}

pub(crate) use self::foo::*;

mod bar {
    fn main() {
        Foo$0;
    }
}
```

... RA will suggest to add `use crate::foo::Foo;`, which not only makes
the code overly verbose (especially in larger code bases), but also is
disjoint with what rustc itself suggests.

This commit adjusts the logic, so that `pub(crate)` imports are taken
into account when generating the suggestions; considering rustc's
behavior, I think this change doesn't warrant any extra configuration
flag.

Note that this is my first commit to RA, so I guess the approach taken
here might be suboptimal - certainly feels somewhat hacky, maybe there's
some better way of finding out the optimal import path 😅
2024-01-10 18:21:16 +01:00
bors
1c9bb31970 Auto merge of #16209 - l1nxy:add-merge-nested-if, r=Veykril
feat: assist to merge nested if

resolve: #16095
2024-01-10 09:18:05 +00:00
roife
d327f3036c Add test 'comments_in_block_expr' in in 'extract_function' 2024-01-10 15:00:58 +08:00
roife
bc54775c9d Preserve comments for extracted block expr in 'extract_function' assist 2024-01-10 15:00:35 +08:00
bors
51ac6de6f3 Auto merge of #16277 - roife:fix-issue16276, r=Veykril
Resolve panic in `generate_delegate_methods`

Fixes #16276

This PR addresses two issues:

1. When using `PathTransform`, it searches for the node corresponding to the `path` in the `source_scope` during `make::fn_`. Therefore, we need to perform the transform before `make::fn_` (similar to the problem in issue #15804). Otherwise, even though the tokens are the same, their offsets (i.e., `span`) differ, resulting in the error "Can't find CONST_ARG@xxx."

2. As mentioned in the first point, `PathTransform` searches for the node corresponding to the `path` in the `source_scope`. Thus, when transforming paths, we should update nodes from right to left (i.e., use **reverse of preorder** (right -> left -> root) instead of **postorder** (left -> right -> root)). Reasons are as follows:

    In the red-green tree (rowan), we do not store absolute ranges but instead store the length of each node and dynamically calculate offsets (spans). Therefore, when modifying the left-side node (such as nodes are inserted or deleted), it causes all right-side nodes' spans to change. This, in turn, leads to PathTransform being unable to find nodes with the same paths (due to different spans), resulting in errors.
2024-01-09 15:52:34 +00:00
bors
da6f7e2c7b Auto merge of #16275 - davidsemakula:ast-path-segments, r=Veykril
fix: Fix `ast::Path::segments` implementation

calling `ast::Path::segments` on a qualifier currently returns all the segments of the top path instead of just the segments of the qualifier.

The issue can be summarized by the simple failing test below:
```rust
#[test]
fn path_segments() {
    //use ra_ap_syntax::ast;
    let path: ast::Path = ...; // e.g. `ast::Path` for "foo::bar::item".

    let path_segments: Vec<_> = path.segments().collect();
    let qualifier_segments: Vec<_> = path.qualifier().unwrap().segments().collect();
    assert_eq!(path_segments.len(), qualifier_segments.len() + 1); // Fails because `LHS = RHS`.
}
```

This PR:
- Fixes the implementation of `ast::Path::segments`
- Fixes `ast::Path::segments` callers that either implicitly relied on behavior of previous implementation or exhibited other "wrong" behavior directly related to the result of `ast::Path::segments` (all callers have been reviewed, only one required modification)
- Removes unnecessary (and now unused) `ast::Path::segments` alternatives
2024-01-09 15:41:48 +00:00
bors
6ce3f44597 Auto merge of #16298 - riverbl:exclusive-range-hint, r=Veykril
feat: Add inlay hint for exclusive ranges

Adds an inlay hint containing a '<' character to exclusive range expressions and patterns that specify an upper bound.

![2024-01-07-095056_257x415_scrot](https://github.com/rust-lang/rust-analyzer/assets/94326797/d6bbc0de-52a5-4af4-b53c-a034749b6cab)

Inspired by [this comment](https://github.com/rust-lang/rust/issues/37854#issuecomment-1865124907) noting that IntelliJ Rust has this feature.
2024-01-07 10:21:39 +00:00
riverbl
3c378b9c70 Add inlay hint for exclusive ranges
Adds an inlay hint containing a '<' character to exclusive range expressions and patterns that specify an upper bound.
2024-01-07 09:33:56 +00:00
Matthias Krüger
3fb2cd2002 autofix remaining perf findings 2024-01-07 01:20:20 +01:00
Matthias Krüger
196650dfaf don't to_string() format args 2024-01-07 01:11:57 +01:00
Matthias Krüger
476e10e961 remove redundant clones 2024-01-07 00:17:48 +01:00
roife
ba952e65ff Transform paths before make::fn_ 2024-01-06 20:09:51 +08:00
davidsemakula
6403dbf011 fix ast::Path::segments callers that implicitly relied on behavior of previous implementation 2024-01-06 12:52:33 +03:00
bors
2271b82007 Auto merge of #16264 - roife:refactor/refactor-generate-delegate-trait, r=Veykril
internal: clean and enhance readability for `generate_delegate_trait`

Continue from #16112

This PR primarily involves some cleanup and simple refactoring work, including:

- Adding numerous comments to layer the code and explain the behavior of each step.
- Renaming some variables to make them more sensible.
- Simplify certain operations using a more elegant approach.

The goal is to make this intricate implementation clearer and facilitate future maintenance.

In addition to this, the PR also removes redundant `path_transform` operations for `type_gen_args`.
Taking the example of `impl Trait<T1> for S<S1>`, where `S1` is considered. The struct `S` must be in the file where the user triggers code actions, so there's no need for the `path_transform`. Furthermore, before performing the transform, we've already renamed `S1`, ensuring it won't clash with existing generics parameters. Therefore, there's no need to transform it.
2024-01-05 13:37:54 +00:00
bors
59457091bb Auto merge of #16199 - Young-Flash:extract_struct_with_Self, r=Veykril
fix: `extract_struct_from_enum_variant` assist should resolve Self generic arg

close https://github.com/rust-lang/rust-analyzer/issues/16197
2024-01-05 13:26:34 +00:00
Lukas Wirth
cc2b79feeb internal: Speed up import searching some more 2024-01-05 12:58:20 +01:00
roife
fbdc59c54a internal: remove unnecessary path_tranform on type_gen_args in generate_delegate_trait. 2024-01-05 13:59:44 +08:00
roife
bf0c4acef4 internal: refactor generate_delegate_trait and add comments 2024-01-05 13:59:34 +08:00
Lukas Wirth
2666349392 Remove limit from symbol_index::Query 2024-01-04 19:20:10 +01:00
Young-Flash
1a9b1b8ccc test: add test case for TupleField 2024-01-03 20:07:53 +08:00
Young-Flash
099c3204a2 fix: use PathTransform to resolve GenericArg 2024-01-03 20:07:29 +08:00