Commit graph

873 commits

Author SHA1 Message Date
Lukas Wirth
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +02:00
Lukas Wirth
bfb187aacd Fix expression scope calculation when within macro expansions 2024-06-30 13:26:17 +02:00
bors
0cb22db658 Auto merge of #17487 - Veykril:ty-perf-stuff, r=Veykril
internal: Some more small memory optimizations

Not a big impact on metrics, though there are some more savings in queries mainly used by the IDE layer from this
2024-06-24 09:50:35 +00:00
Lukas Wirth
db056b4a69 Fix term_search filtering enum variant generics incorrectly 2024-06-24 10:31:21 +02:00
bors
e0a400edd4 Auto merge of #17471 - davidsemakula:fix-remove-parenthesis, r=Veykril
fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union

Fixes #17111
2024-06-24 08:25:49 +00:00
Tavo Annus
957325a5fe Run data_constructor tactic only backwards 2024-06-21 22:01:06 +03:00
davidsemakula
d6d45a23d3 fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union 2024-06-21 17:57:53 +03:00
Tavo Annus
c87609fef1 Add tactic for associated item constants 2024-06-18 22:08:44 +03:00
Lukas Wirth
8520a0c585 Thread more HasSource::source calls through Semantics for caching 2024-06-10 10:33:07 +02:00
Lukas Wirth
d4dc3ca83b Register virtual workspace Cargo.toml files in the VFS 2024-06-09 12:54:50 +02:00
bors
26c1638bfb Auto merge of #17308 - mathew-horner:prefer-workspace, r=Veykril
Add preference modifier for workspace-local crates when using auto import.

`@joshka` pointed out some odd behavior of auto import ordering. It doesn't seem that the current heuristics were applying any sort of precedence to imports from the workspace. I've went ahead and added that.

I hope to get some feedback on the modifier numbers here. I just went with something that felt like it balanced giving more power to workspace crates without completely ignoring relative path distance.

closes https://github.com/rust-lang/rust-analyzer/issues/17303
2024-06-07 10:35:49 +00:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
bors
cb6b808185 Auto merge of #17315 - hamirmahal:style/simplify-string-interpolation, r=Veykril
style: simplify string interpolation
2024-06-03 12:29:27 +00:00
DropDemBits
a741bb2055
fix typos & formatting 2024-06-02 14:09:36 -04:00
DropDemBits
cf9401049c
Make extract_expressions_from_format_string only use snippets when available 2024-06-02 11:47:05 -04:00
DropDemBits
3b763a847a
Add tt_from_syntax
Used for inserting syntax nodes into existing token trees
2024-06-02 11:10:07 -04:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
Mathew Horner
4bf51eb496
Add preference modifier for workspace-local crates when using auto import. 2024-05-28 23:05:27 -05: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
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
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
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
David Barsky
b75301cec8 internal: refactor prefer_no_std/prefer_prelude bools into a struct 2024-05-22 20:46:30 +02: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
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
c88b421853 fix: Fix general find-path inconsistencies 2024-05-22 14:05:24 +02:00
Lukas Wirth
7c6f31a45b Allow hir::Param to refer to other entity params aside from functions 2024-05-18 12:35:55 +02:00
Luuk Wester
537b4c6305 implement assist to switch between doc and normal comments 2024-05-18 02:38:41 +02:00
blyxyas
66f62836ae Fix typos 2024-05-15 18:55:27 +02:00
bors
07d71c05c3 Auto merge of #17216 - Young-Flash:mod_with_path, r=Veykril
fix: extract mod to file should respect path attribute

close https://github.com/rust-lang/rust-analyzer/issues/17181
2024-05-14 14:29:00 +00:00
bors
40ab5e5f8c Auto merge of #17220 - Veykril:hov-lit, r=Veykril
fix: Improve confusing literal hovers
2024-05-13 10:58:29 +00:00
Lukas Wirth
a39c0493a1 Render literal escaping errors in hovers 2024-05-13 12:51:57 +02:00
bors
9db1258dbe Auto merge of #17203 - kilpkonn:collapse_terms, r=Veykril
Fix OOM caused by term search

The issue came from multi Cartesian product for exprs with many (25+) arguments, each having multiple options.
The solution is two fold:
### Avoid blowing up in Cartesian product
**Before the logic was:**
    1. Find expressions for each argument/param - there may be many
    2. Take the Cartesian product (which blows up in some cases)
    4. If there are more than 2 options throw them away by squashing them to `Many`
**Now the logic is:**
    1. Find expressions for each argument/param and squash them to `Many` if there are more than 2 as otherwise we are guaranteed to also have more than 2 after taking the product which means squashing them anyway.
    2. Take the Cartesian product on iterator
    3. Start consuming it one by one
    4. If there are more than 2 options throw them away by squashing them to `Many`  (same as before)

This is also why I had to update some tests as the expressions get squashed to many more eagerly.

### Use fuel to avoid long search times and high memory usage
Now all the tactics use `should_continue:  Fn() -> bool` to chech if they should keep iterating _(Similarly to chalk)_.
This reduces the search times by a magnitude, for example from ~139ms/hole to ~14ms/hole for `ripgrep` crate.
There are slightly less expressions found, but I think speed gain worth it for usability.
Also note that syntactic hits decreases more because of squashing so you simple need to run search multiple times to get full terms.
Also the worst case time (For example `nalgebra` crate cus it has tons of generics) has search times mostly under 200ms.

Benchmarks on `ripgrep` crate
Before:
```
Tail Expr syntactic hits: 291/1692 (17%)
Tail Exprs found: 1253/1692 (74%)
Term search avg time: 139ms
````
After:
```
Tail Expr syntactic hits: 239/1692 (14%)
Tail Exprs found: 1226/1692 (72%)
Term search avg time: 14ms
```
2024-05-13 10:30:12 +00:00
Young-Flash
3e57aabf85 test: add test case extract_with_specified_path_attr 2024-05-12 11:48:17 +08:00
Young-Flash
0c13f0cd5b fix: extract mod to file should respect path attribute 2024-05-12 11:48:17 +08:00
Tavo Annus
ab18604309 Make term search fuel configurable 2024-05-08 19:46:33 +03:00
roife
4ada8265e6 tests: update test in assist apply_demorgan 2024-05-05 23:44:52 +08:00
roife
a42818f393 fix: keep parentheses when the precedence of inner expr is lower than the outer one 2024-05-05 21:39:26 +08:00
Harry Sarson
a653ddf940
braces around {self} in UseTree are not unnecessary
Before this commit `UseTree::remove_unnecessary_braces` removed the braces
around `{self}` in `use x::y::{self};` but `use x::y::self;` is not valid
rust.
2024-04-30 18:17:32 +01:00
bors
84ef3cfa91 Auto merge of #17138 - Kohei316:generate-function-assist-for-new, r=Veykril
feature: Make generate function assist generate a function as a constructor if the generated function has the name "new" and is an asscociated function.

close #17050
This PR makes `generate function assist` generate a function as a constructor if the generated function has the name "new" and is an asscociated function.
If the asscociate type is a record struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self { field_1: todo!(), field_2: todo!() }
    }
}
```
If the asscociate type is a tuple struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self(todo!(), todo!())
    }
}
```
If the asscociate type is a unit struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self
    }
}
```
If the asscociate type is another adt, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        todo!()
    }
}
```
2024-04-30 12:09:34 +00:00
morine0122
ff2629d651 Make generate function assist generate a function as a constructor if the name of function is new 2024-04-30 17:02:48 +09:00
Lukas Wirth
ac389ce2ef fix: Fix expression scopes not being calculated for inline consts 2024-04-25 09:49:19 +02:00
Lukas Wirth
ec941e599a Add inlay hints lifetime arg tests 2024-04-25 09:10:49 +02:00