Commit graph

796 commits

Author SHA1 Message Date
Lukas Wirth
9ba4493918 internal: Improve rooted upmapping 2024-03-12 13:46:58 +01:00
bors
48cb059182 Auto merge of #16781 - DropDemBits:extract-format-args-escaping, r=Veykril
fix: Don't escape `\` and `$` in "Extract format expressions" assist

Fixes #16745
2024-03-07 20:04:33 +00:00
DropDemBits
1f37e5ac9a
fix: Don't escape \ and $ in "Extract format expressions" assist 2024-03-07 14:20:23 -05:00
roife
5c9ce7b11f test: add tests for keeping attrs in assist 'generate_delegate_trait' 2024-03-06 15:32:49 +08:00
roife
faea7fca01 fix: keep attrs for assist 'generate_delegate_trait' 2024-03-06 15:32:26 +08:00
Niklas Lindorfer
2a4ba4295b
fix: hide destructure_struct_binding assist if no public fields 2024-03-04 21:50:01 +00:00
Lukas Wirth
0964374274 Move diagnostics docs generation into xtask/codegen 2024-03-04 17:14:14 +01:00
bors
4e8cbf36a8 Auto merge of #16708 - Veykril:codegen, r=Veykril
internal: Move ide-assists codegen tests into an xtask codegen command
2024-03-04 15:50:39 +00:00
bors
99a1b8f7a8 Auto merge of #16747 - Veykril:cleanup, r=Veykril
internal: Clean some stuff up

Just a bunch of small refactorings, mainly from browsing through `hir-def`
2024-03-04 10:30:17 +00:00
Lukas Wirth
4303e741de Cleanup 2024-03-04 11:10:06 +01:00
bors
d8feb908be Auto merge of #16703 - regexident:sema-ast-to-hir, r=Veykril
Add more methods for resolving definitions from AST to their corresponding HIR types

In order to be able to add these methods with consistent naming I had to also rename two existing methods that would otherwise be conflicting/confusing:

`Semantics::to_module_def(&self, file: FileId) -> Option<Module>` (before)
`Semantics::file_to_module_def(&self, file: FileId) -> Option<Module>` (after)

`Semantics::to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module>` (before)
`Semantics::file_to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module>` (after)

(the PR is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to walk a `hir::Function`'s AST, resolving its exprs/stmts/items to their HIR equivalents)
2024-03-04 09:02:32 +00:00
bors
0b7d4cc6ff Auto merge of #16690 - roife:fix-issue-16471, r=Veykril
fix: use 4 spaces for indentation in macro expansion

Partial fix for #16471.

In the previous code, the indentation produced by macro expansion was set to 2 spaces. This PR modifies it to 4 spaces for the sake of consistency.
2024-03-04 08:49:51 +00:00
Lukas Wirth
ed7e9aa5d8 Simplify 2024-03-01 13:25:24 +01:00
Niklas Lindorfer
dc7b502689
Fix usage in other assist 2024-02-29 13:17:45 +00:00
Niklas Lindorfer
7c30c70658
Attempt resolving name collisions 2024-02-29 13:17:45 +00:00
Niklas Lindorfer
b203a07d92
Handle bindings to refs 2024-02-29 13:17:45 +00:00
Niklas Lindorfer
ed230048dc
Add destructure_struct_binding action
Separate into create and apply edit

Rename usages

Hacky name map

Add more tests

Handle non-exhaustive

Add some more TODOs

Private fields

Use todo

Nesting

Improve rest token generation

Cleanup

Doc -> regular comment

Support mut
2024-02-29 13:17:44 +00:00
Lukas Wirth
03b02e6bd0 internal: Move ide-assists codegen tests into an xtask codegen command 2024-02-28 16:54:44 +01:00
Vincent Esche
6112ddfabb Add prefix file_ to Semantics's to_module_defs()/to_module_def() methods 2024-02-28 10:27:28 +01:00
roife
76b86b24bd fix: clippy and format 2024-02-27 20:53:09 +08:00
roife
ec5236f3a8 test: use 4 spaces for indetation in macro expansion 2024-02-27 20:53:07 +08:00
roife
ce4ae41605 internal: simplify the process of inserting spaces after mut 2024-02-27 20:49:09 +08:00
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