Commit Graph

774 Commits

Author SHA1 Message Date
bors
6b250a22c4 Auto merge of #16687 - kilpkonn:master, r=Veykril
feat: Add "make tuple" tactic to term search

Follow up to https://github.com/rust-lang/rust-analyzer/pull/16092

Now term search also supports tuples.
```rust
let a: i32 = 1;
let b: f64 = 0.0;
let c: (i32, (f64, i32)) = todo!(); // Finds (a, (b, a))
```
In addition to new tactic that handles tuples I changed how the generics are handled.
Previously it tried all possible options from types we had in scope but now it only tries useful ones that help us directly towards the goal or at least towards calling some other function.
This changes O(2^n) to O(n^2) where n is amount of rounds which in practice allows using types that take generics for multiple rounds (previously limited to 1). Average case that also used to be exponential is now roughly linear.
This means that deeply nested generics also work.
````rust
// Finds all valid combos, including `Some(Some(Some(...)))`
let a: Option<Option<Option<bool>>> = todo!();
````

_Note that although the complexity is smaller allowing more types with generics the search overall slows down considerably. I hope it's fine tho as the autocomplete is disabled by default and for code actions it's not super slow. Might have to tweak the depth hyper parameter tho_

This resulted in a huge increase of results found (benchmarks on `ripgrep` crate):
Before
````
Tail Expr syntactic hits: 149/1692 (8%)
Tail Exprs found: 749/1692 (44%)
Term search avg time: 18ms
```
After
```
Tail Expr syntactic hits: 291/1692 (17%)
Tail Exprs found: 1253/1692 (74%)
Term search avg time: 139ms
````

Most changes are local to term search except some tuple related stuff on `hir::Type`.
2024-02-27 09:41:14 +00:00
bors
d8c5a6128f Auto merge of #16651 - dfireBird:new_assist_fill_fields, r=Veykril
Add assist for filling fields by replacing ellipsis in record syntax

I'm not sure if the tests cover the most cases, I'll add more if suggested.
2024-02-27 09:28:23 +00:00
Tavo Annus
be6f8e2648 Add make_tuple tactic 2024-02-26 20:17:09 +02:00
Tavo Annus
8bd30e9b3f Improve generics handling in term search 2024-02-26 20:17:09 +02:00
dfireBird
8fa903a447
add test for checking struct generated through macro 2024-02-26 21:32:59 +05:30
dfireBird
2ea70662f0
make assist not applicable if there is no missing field 2024-02-26 21:21:56 +05:30
roife
61b576c5ab fix: fmt 2024-02-26 22:36:47 +08:00
roife
38a50cf1a4 test: callsites inside inline_into_callers 2024-02-26 20:24:44 +08:00
roife
36298c622e fix:do not handle callsites in macros' parameters 2024-02-26 20:23:36 +08:00
dfireBird
6f4354f6ad
add assist for filling fields by replacing ellipsis in record syntax 2024-02-24 11:59:48 +05:30
Lukas Wirth
d93096ecc0 internal: Fetch toolchain and datalayout for DetachedFiles 2024-02-20 10:40:39 +01:00
DropDemBits
eb6d6ba17c
Migrate generate_trait_from_impl to mutable ast 2024-02-15 21:34:29 -05:00
DropDemBits
115646d7d5
Align set_visibility with the rest of the set_ edit-in-place methods 2024-02-15 20:40:14 -05:00
Chengxu Bian
ca64359945 remove eprintln! overwrite 2024-02-12 23:54:32 -05:00
Tavo Annus
125791386d Cleanup term search related changes 2024-02-11 14:35:54 +02:00
Tavo Annus
88964c0b6a Optionally disable term search for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
0b838e3e23 Expand target for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
a946970e2d Add quantified trees to reduce autocomplete options 2024-02-11 13:33:29 +02:00
Tavo Annus
bdbdd83ec1 Initial version of term_search for autocomplete 2024-02-11 13:33:29 +02:00
Tavo Annus
627255dd5a Add static method tactic 2024-02-11 13:33:29 +02:00
Tavo Annus
bb3c7cff60 Introduce term search to rust-analyzer 2024-02-11 13:33:29 +02:00
bors
0878cdef2a Auto merge of #16524 - evertedsphere:swann/trait-bound-dyn, r=Veykril
minor: test that flip_trait_bound works with trait objects

Closes https://github.com/rust-lang/rust-analyzer/issues/16522.
2024-02-10 10:59:46 +00:00
bors
1ef7a2329b Auto merge of #16525 - Veykril:item-loc, r=Veykril
Abstract more over ItemTreeLoc-like structs

Allows reducing some code duplication by using functions generic over said structs. The diff isn't negative due to me adding some additional impls for completeness.
2024-02-10 10:47:37 +00:00
Soham Chowdhury
dcdfc35fce test that flip_trait_bound works with trait objects 2024-02-10 11:06:07 +01:00
bors
aa97edb214 Auto merge of #16497 - evertedsphere:swann/fix-inline-for-macro-generated-method, r=Veykril
Fix incorrect inlining of functions that come from MBE macros

Partial fix for https://github.com/rust-lang/rust-analyzer/issues/16471.

As a reminder, there are two issues there:
1. missing whitespace in parameter types (the first test)
2. the `self` parameter not being replaced by `this` in the function body (the second test)

The first part is fixed in this PR. See [this comment](https://github.com/rust-lang/rust-analyzer/pull/16497#issuecomment-1934243409) for the second.
2024-02-10 08:59:51 +00:00
Lukas Wirth
2ebf0c87c2 Deduplicate some code 2024-02-10 01:51:22 +01:00
Soham Chowdhury
18be556b37 inline_call: remove macro self->this test
To be added back later once we have a fix.

See #16471 and https://github.com/rust-lang/rust-analyzer/pull/16497#issuecomment-1934243409.
2024-02-09 22:02:51 +01:00
Tetsuharu Ohzeki
80e684254d ide-assists: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
bors
65a644190d Auto merge of #16424 - dfireBird:let-stmt-guarded-return-assist, r=Veykril
implement convert to guarded return assist for `let` statement with type that implements `std::ops::Try`

I've tried to implement the assist that #16390 talked about

If there are any improvements that I can make in implementation, please suggest them.

![Peek 2024-02-05 19-01](https://github.com/rust-lang/rust-analyzer/assets/40687700/d6af3222-4f23-4ade-a930-8a78cc75e821)
2024-02-09 13:42:20 +00:00
David Barsky
2d09d69fbe internal: fix crash inside filter_unnecessary_bounds for a missing generic param 2024-02-08 20:58:48 -05:00
DropDemBits
05b8ccc378
Fix clippy lints 2024-02-08 19:39:04 -05:00
DropDemBits
1161082051
Remove unused code in utils
All usages of `render_snippet` and `Cursor` have been removed as part of the migration
2024-02-08 19:13:10 -05:00
DropDemBits
8eebf1701b
Migrate replace_derive_with_manual_impl to mutable ast 2024-02-08 19:13:10 -05:00
DropDemBits
18ea09feca
Migrate generate_new to mutable ast 2024-02-08 19:13:10 -05:00
DropDemBits
e0117154cf
Migrate generate_impl to mutable ast 2024-02-08 19:13:10 -05:00
DropDemBits
ab2233e562
Migrate generate_getter_or_setter to mutable ast 2024-02-08 19:13:09 -05:00
DropDemBits
f1293a8fc4
Add newline to body when where clause is present 2024-02-08 19:13:09 -05:00
DropDemBits
0519414c19
Make ReferenceConversion methods return ast types 2024-02-08 19:13:09 -05:00
DropDemBits
0e39257e5b
Migrate extract_function to mutable ast 2024-02-08 19:09:33 -05:00
DropDemBits
3924a0ef7c
Add ast versions of generate{_trait}_impl_text{_intransitive} 2024-02-08 19:09:33 -05:00
DropDemBits
8c0661b2de
Use GenericArgList for make::impl{_trait}
`make::impl_` no longer merges generic params and args in order to be in line
with `make::impl_`, which doesn't do it either.
2024-02-08 19:09:32 -05:00
bors
e07183461f Auto merge of #16487 - ShoyuVanilla:deref-generate-getter, r=Veykril
Remove unnecessary `.as_ref()` in generate getter assist

Resolves #12389
2024-02-08 15:15:52 +00:00
Soham Chowdhury
57a454233c inline_call: ensure correct whitespace in parameter types 2024-02-06 20:24:16 +01:00
bors
66cec4d11a Auto merge of #16470 - Veykril:clippy-disallow, r=lnicola
internal: Lint debug prints and disallowed types with clippy
2024-02-05 17:20:43 +00:00
dfireBird
53db37f9bf
restrict cursor range to show assists 2024-02-05 18:53:40 +05:30
Shoyu Vanilla
26715a8fde
cargo fmt 2024-02-05 10:48:34 +09:00
Shoyu Vanilla
983cce8c31
Typo fix 2024-02-05 10:37:58 +09:00
Shoyu Vanilla
f0428e57ea
Simplify redundant coercion 2024-02-05 10:35:12 +09:00
Shoyu Vanilla
97ecfe4fab Remove unnecessary .as_ref() in generate getter assist 2024-02-05 00:44:57 +09:00
bors
8f6a72871e Auto merge of #16469 - Young-Flash:ci_typos, r=lnicola
internal: add typos check CI (part 2)

follow up https://github.com/rust-lang/rust-analyzer/pull/16448
2024-02-02 12:02:48 +00:00