Commit Graph

366 Commits

Author SHA1 Message Date
Lukas Wirth
72d47144e8 fix: Fix receiver adjustments for extract_variable assist 2023-04-11 14:01:23 +02:00
bors
fa3db447d7 Auto merge of #14536 - ClSlaid:feat/reorder-impl-items/not-applicative-editing-assoc-items, r=Veykril
fix: restrict applicable range of `reorder-impl-trait-items`

This PR should complete the need for restricting the applicable range of `reorder-impl-trait-items`.

When the cursor is in the associated items of the `impl` range, the assist will be disabled.

Fix: #14515

## Showcases
Note: If there is any available `code-action` (`ide-assist`) available, a lightbulb icon from `lspsaga` will show in the left.

- cursor in `impl` headers
![code action available](https://user-images.githubusercontent.com/44747719/230756854-7b236018-cfa8-4005-b589-2996ec42917f.png)
Code action is available. And it is reordering impl items.
![code action detail](https://user-images.githubusercontent.com/44747719/230756971-341c7fbc-f2ba-4715-a1e5-b1add984d4dd.png)

- cursor in `impl` associated items
![code action unavailable](
https://user-images.githubusercontent.com/44747719/230756906-bee7784e-bd9d-49b2-801b-743c94b4af54.png)
2023-04-11 07:36:42 +00:00
hkalbasi
59b6f2d9f2 Compute closure captures 2023-04-10 23:04:34 +03:30
蔡略
475aa2839f refactor: correct test sample
giving a sorted file is useless

Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
2023-04-09 00:24:25 +08:00
蔡略
e90e1901ef feat: restrict applicable range of reorder-impl-trait-items 2023-04-09 00:14:48 +08:00
Lukas Wirth
8e7c104b3a Move hir_def::adt to hir_def::data::adt 2023-04-06 19:23:29 +02:00
bors
ea22d245b6 Auto merge of #14499 - DropDemBits:drive-by-fixmes, r=Veykril
minor: Fix some simple FIXMEs

Each FIXME fix has been split into its own commit, since they're all pretty independent changes.

(Forgot to open a PR for this a few days ago, oops)
2023-04-05 20:42:55 +00:00
bors
e8bad53d63 Auto merge of #14455 - jplatte:convert-nested-function-to-closure, r=Veykril
Convert nested function to closure assist

Continuation of / closes #13467.
Resolves #13230.

r? `@Veykril`
2023-04-05 17:28:46 +00:00
Jonas Platte
bc704e127d
Address another round of review comments 2023-04-05 18:48:21 +02:00
bors
da9c0bd0a7 Auto merge of #14442 - DropDemBits:structured-snippet-api, r=Veykril
internal: Implement Structured API for snippets

Fixes #11638 (including moving the cursor before the generated type parameter)

Adds `add_tabstop_{before,after}` for inserting tabstop snippets before & after nodes, and `add_placeholder_snippet` for wrapping nodes inside placeholder nodes.

Currently, the snippets are inserted into the syntax tree in `SourceChange::commit` so that snippet bits won't interfere with syntax lookups before completing a `SourceChange`.

It would be preferable if snippet rendering was deferred to after so that rendering can work directly with text ranges, but have left that for a future PR (it would also make it easier to finely specify which text edits have snippets in them).

Another possible snippet variation to support would be a group of placeholders (i.e. placeholders with the same tabstop number) so that a generated item and its uses can be renamed right as it's generated, which is something that is technically supported by the current snippet hack in VSCode, though it's not clear if that's a thing that is officially supported.
2023-04-05 14:33:30 +00:00
Ryo Yoshida
0df9fb22d8
fix: insert whitespace between text and pound
`text#`, `text"..."`, and `text'...'` are reserved syntax since Rust
2021. Note that the latter two are already handled correctly.
2023-04-05 20:33:17 +09:00
Jake Heinz
f6b0c19c56 dedupe by name 2023-04-04 06:57:02 +00:00
Jake Heinz
50b427c0d1 use crate from autoderef ty 2023-04-04 06:54:26 +00:00
Jake Heinz
94e6a6642c assist: autoderef in generate delegate methods 2023-04-04 06:50:20 +00:00
DropDemBits
d689fd30bc
Remove outdated comment in sourcegen
`CommentBlock::extract` does handle blank lines in comment blocks
2023-03-31 14:43:24 -04:00
Jonas Platte
d01a38ce3f
Address second round of review comments 2023-03-31 13:53:57 +02:00
Jonas Platte
0e11d507e1
Address review comment 2023-03-31 12:20:08 +02:00
Mathew Horner
3973d1aaa7
Add assist to convert nested function to closure 2023-03-31 12:16:49 +02:00
Lukas Wirth
e244942209 internal: Set Durability to HIGH for enable_proc_attr_macros input 2023-03-30 15:11:22 +02:00
Lukas Wirth
8ea1afce28 Simplify 2023-03-28 16:32:26 +02:00
DropDemBits
369f4774dd
fix: Move cursor before generated generic 2023-03-26 18:10:41 -04:00
hkalbasi
b7b9ae59a0 desugar ? operator 2023-03-17 13:08:35 +03:30
Lukas Wirth
802d7ea335 internal: Prioritize remove-dbg assist over inline-macro 2023-03-15 14:19:50 +01:00
Ryo Yoshida
01bf0725b1
fix: don't replace SyntaxToken with SyntaxNode 2023-03-15 17:18:09 +09:00
Lukas Wirth
9fb9ee3b6a internal: Rename AstDatabase to ExpandDatabase 2023-03-13 16:35:41 +01:00
hkalbasi
811190b913 fix multiple definition binding in match to let-else 2023-03-09 00:34:31 +03:30
bors
44ff3c407a Auto merge of #14232 - HKalbasi:mir, r=Veykril
MIR episode 2

This PR adds:
1. `need-mut` and `unused-mut` diagnostics
2. `View mir` command which shows MIR for the body under cursor, useful for debugging
3. MIR lowering for or-patterns and for-loops
2023-03-07 09:49:49 +00:00
bors
31c12ec282 Auto merge of #14266 - Veykril:generalize-eager-lazy, r=Veykril
feature: Make replace_or_with_or_else assists more generally applicable
2023-03-06 21:41:46 +00:00
Lukas Wirth
199bc82ce8 feature: Make replace_or_with_or_else assists more generally applicable 2023-03-06 22:17:30 +01:00
hkalbasi
61ad6a96ad Add BindingId 2023-03-06 21:09:08 +03:30
Lukas Wirth
7be48ac32c Adjust replace_match_with_if_let applicability range 2023-03-05 16:52:07 +01:00
Lukas Wirth
b8276481e7 Fix extract_variable test 2023-03-04 14:58:58 +01:00
bors
6756294aa0 Auto merge of #14184 - lowr:feat/trait-alias-def, r=Veykril
Handle trait alias definitions

Part of #2773

This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits.

I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add.

I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
2023-03-03 15:45:18 +00:00
Ryo Yoshida
29c957f973
Lower and handle trait aliases in HIR 2023-03-04 00:24:07 +09:00
Ryo Yoshida
bda2af71c6
feat: allow generate_function to generate in different local crate 2023-03-03 18:40:13 +09:00
Ryo Yoshida
943de55214
Fix typo 2023-03-03 01:12:39 +09:00
Ryo Yoshida
de4a8961dc
Support removing nested dbg!()s in remove_dbg 2023-03-01 19:06:05 +09:00
bors
a0be16b0b2 Auto merge of #14040 - HKalbasi:mir, r=HKalbasi
Beginning of MIR

This pull request introduces the initial implementation of MIR lowering and interpreting in Rust Analyzer.

The implementation of MIR has potential to bring several benefits:
- Executing a unit test without compiling it: This is my main goal. It can be useful for quickly testing code changes and print-debugging unit tests without the need for a full compilation (ideally in almost zero time, similar to languages like python and js). There is a probability that it goes nowhere, it might become slower than rustc, or it might need some unreasonable amount of memory, or we may fail to support a common pattern/function that make it unusable for most of the codes.
- Constant evaluation: MIR allows for easier and more correct constant evaluation, on par with rustc. If r-a wants to fully support the type system, it needs full const eval, which means arbitrary code execution, which needs MIR or something similar.
- Supporting more diagnostics: MIR can be used to detect errors, most famously borrow checker and lifetime errors,  but also mutability errors and uninitialized variables, which can be difficult/impossible to detect in HIR.
- Lowering closures: With MIR we can find out closure capture modes, which is useful in detecting if a closure implements the `FnMut` or `Fn` traits, and calculating its size and data layout.

But the current PR implements no diagnostics and doesn't support closures. About const eval, I removed the old const eval code and it now uses the mir interpreter. Everything that is supported in stable rustc is either implemented or is super easy to implement. About interpreting unit tests, I added an experimental config, disabled by default, that shows a `pass` or `fail` on hover of unit tests (ideally it should be a button similar to `Run test` button, but I didn't figured out how to add them). Currently, no real world test works, due to missing features including closures, heap allocation, `dyn Trait` and ... so at this point it is only useful for me selecting what to implement next.

The implementation of MIR is based on the design of rustc, the data structures are almost copy paste (so it should be easy to migrate it to a possible future stable-mir), but the lowering and interpreting code is from me.
2023-02-28 09:12:19 +00:00
hkalbasi
cd67589f63 beginning of MIR 2023-02-27 23:45:54 +03:30
Lukas Wirth
9e5fa74279 Simplify 2023-02-27 15:51:45 +01:00
Azriel Hoh
a6f54d6c5f Conditionally add snippet marker. 2023-02-16 10:50:27 +13:00
Lukas Wirth
3c0f20a7bd internal: Enable smallvec's union feature 2023-02-14 17:01:01 +01:00
lh123
626dc651ff fix: Insert spaces when inlining macros 2023-02-10 14:22:56 +08:00
bors
57ea9826b5 Auto merge of #13991 - vasilev-alex:add-braces-assist, r=Veykril
feat: add braces assist

This assist adds support for adding braces where it may be appropriate (e.g. lambda expressions)

![ex](https://user-images.githubusercontent.com/4973437/213783924-7c8a8ab5-6a52-4d80-837c-cf2a9b56f061.gif)
2023-02-07 17:12:01 +00:00
Ryo Yoshida
493cabbde7
Treat scope info retrieval failure as assist failure 2023-02-02 17:47:11 +09:00
Ryo Yoshida
3edde6fcc1
Support generic function in generate_function assist 2023-01-31 21:05:25 +09:00
Ryo Yoshida
0df70d37fc
Minor refactoring 2023-01-31 21:05:04 +09:00
Jonas Schievink
6321b25a21 Apply the assist to itself 2023-01-30 17:52:15 +01:00
Jonas Schievink
1f20804b6e Improve "match to let-else" assist 2023-01-30 17:50:02 +01:00
Jonas Schievink
e7a2d13ff6 Fix "add missing impl members" assist for impls inside blocks 2023-01-27 16:51:55 +01:00