about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-assists
AgeCommit message (Collapse)AuthorLines
2024-08-31Add explicit enum discriminant assistriverbl-0/+204
Add assist for adding explicit discriminants to all variants of an enum.
2024-08-29fix: consider indentation in the "Generate impl" and "Generate trait impl" ↵Ivar Scholten-13/+76
assists This makes the generated impl's indentation match the ADT it targets, improving formatting when using nested modules inside of the same file or when defining types inside of a function.
2024-08-29Auto merge of #17993 - ChayimFriedman2:convert-to-tuple-attrs, r=Veykrilbors-11/+49
Consider field attributes when converting from tuple to named struct and the opposite Fixes #17983. I tried to use the `SourceChangeBuilder::make_mut()` API, but it duplicated the attribute...
2024-08-29Auto merge of #17991 - ChayimFriedman2:extract-variable-ref, r=Veykrilbors-10/+140
fix: Don't add reference when it isn't needed for the "Extract variable" assist I.e. don't generate `let var_name = &foo()`. Because it always irritates me when I need to fix that. Anything that creates a new value don't need a reference. That excludes mostly field accesses and indexing. I had a thought that we can also not generate a reference for fields and indexing as long as the type is `Copy`, but sometimes people impl `Copy` even when they don't want to copy the values (e.g. a large type), so I didn't do that.
2024-08-29Auto merge of #17940 - ChayimFriedman2:closure-to-fn, r=Veykrilbors-0/+1307
feat: Create an assist to convert closure to freestanding fn The assist converts all captures to parameters. Closes #17920. This was more work than I though, since it has to handle a bunch of edge cases... Based on #17941. Needs to merge it first.
2024-08-29Consider field attributes when converting from tuple to named struct and the ↵Chayim Refael Friedman-11/+49
opposite
2024-08-29Also handle deref expressions in "Extract variable"Chayim Refael Friedman-15/+59
And BTW, remove the parentheses of the extracted expression if there are.
2024-08-29Don't add reference when it isn't needed for the "Extract variable" assistChayim Refael Friedman-1/+42
I.e. don't generate `let var_name = &foo()`. Anything that creates a new value don't need a reference. That excludes mostly field accesses and indexing. I had a thought that we can also not generate a reference for fields and indexing as long as the type is `Copy`, but sometimes people impl `Copy` even when they don't want to copy the values (e.g. a large type), so I didn't do that.
2024-08-28Consider all expressions that autoderef in "Extract variable", not just ↵Chayim Refael Friedman-3/+48
method and field accesses.
2024-08-27Create an assist to convert closure to freestanding fnChayim Refael Friedman-0/+1307
The assist converts all captures to parameters.
2024-08-27Auto merge of #17757 - alibektas:toggle_macro_delimiters, r=Veykrilbors-0/+279
assist: Add new assist toggle_macro_delimiter Closes #17716
2024-08-27Fix testsLukas Wirth-23/+23
2024-08-26Fix "Unwrap block" assist with block modifiersChayim Refael Friedman-3/+55
The assist just assumes the `{` will be the first character, which led to strange outputs such as `nsafe {`.
2024-08-26Auto merge of #17963 - avrong:avrong/error-lifetimes, r=Veykrilbors-1/+1
Always show error lifetime arguments as `'_` Fixes #17947 Changed error lifetime argument presentation in non-test environment to `'_` and now showing them even if all of args are error lifetimes. This also influenced some of the other tests like `extract_function.rs`, `predicate.rs` and `type_pos.rs`. Not sure whether I need to refrain from adding lifetimes args there. Happy to fix if needed
2024-08-26Show and render error lifetime args as `'_`Aleksei Trifonov-1/+1
2024-08-24Modify `hacks::parse_expr_from_str()` to take an edition tooChayim Refael Friedman-2/+2
This will be needed as we parse unknown identifiers and want to insert them into source code.
2024-08-24Add `gen` modifier to functionsChayim Refael Friedman-2/+32
We don't yet lower or maybe even parse them, but blocks already have `gen`, so why not.
2024-08-22Fully remove old macro descension APILukas Wirth-3/+3
2024-08-22Remove DescendPreference::SameTextLukas Wirth-12/+2
2024-08-19fix: keep comments in convert_while_to_looproife-8/+89
2024-08-16Properly account for editions in namesChayim Refael Friedman-143/+269
This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-12fix: Trailing excess comma in "Convert to named struct" assistShoyu Vanilla-2/+27
2024-08-06Auto merge of #17745 - regexident:improve-crate-manifests, r=Veykrilbors-1/+2
Improve crate manifests, adding missing `[package.repository]` and `[package.description]` fields As [discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Could.20we.20add.20repository.20url.20to.20.60ra_ap_.60.20crates.20on.20crates.2Eio.3F/near/455095161). cc `@Veykril` `@lnicola`
2024-08-06Replace `[package.repository] = "…"` of published crates with ↵Vincent Esche-1/+1
`[package.repository.workspace] = true`
2024-08-06Add repository URL for published crates' missing `[package.repository]` fieldsVincent Esche-0/+1
2024-08-06Replace `"TBD"` with more helpful desciptions in published crates' ↵Vincent Esche-1/+1
`[package.description]` fields
2024-08-06fix: Panic in path transform with default type parametersShoyu Vanilla-0/+25
2024-08-05Simplify FileDelegateLukas Wirth-1/+1
2024-08-05feat: Load sysroot library via cargo metadataLukas Wirth-1/+1
2024-08-02Make toggle_macro_delimiters work only for macro_callsAli Bektas-62/+112
2024-08-01Add new assist toggle_macro_delimiterAli Bektas-0/+229
2024-07-28flip the naming of the doc comment to comment assistLuuk Wester-2/+2
2024-07-22Auto merge of #17647 - joshka:jm/rename-commands, r=Veykrilbors-1/+1
Rename rust-analyzer commands The commands `editor.action.triggerParameterHints` and `editor.action.rename` are now renamed to `rust-analyzer.triggerParameterHints` and `rust-analyzer.rename` This change helps make it clear that these commands are specific to rust-analyzer and not part of the default set of commands provided by VSCode. Fixes: https://github.com/rust-lang/rust-analyzer/issues/17644 Note: This seems like it will be a breaking change for any RA client that previously reacted to `editor.action.triggerParameterHints` - naive search: https://github.com/search?q=editor.action.triggerParameterHints+AND+%28NOT+is%3Afork%29+rust-analyzer&type=code
2024-07-22SimplifyLukas Wirth-139/+65
2024-07-20Rename rust-analyzer commandsJosh McKinney-1/+1
The commands `editor.action.triggerParameterHints` and `editor.action.rename` are now renamed to `rust-analyzer.triggerParameterHints` and `rust-analyzer.rename` This change helps make it clear that these commands are specific to rust-analyzer and not part of the default set of commands provided by VSCode. Fixes: https://github.com/rust-lang/rust-analyzer/issues/17644
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19Auto merge of #17622 - roife:fix-issue-17602, r=Veykrilbors-0/+69
fix: handle synonymous imports with different renaming in 'merge imports' fix #17602
2024-07-18Encode edition within FileId in the hir layerLukas Wirth-84/+92
2024-07-18fix: handle synonymous imports in 'merge imports'roife-0/+69
2024-07-17Add always disabled gen parse supportLukas Wirth-4/+4
2024-07-16Remove Name::to_smol_strLukas Wirth-12/+14
2024-07-16More symbol usageLukas Wirth-6/+6
2024-07-15Auto merge of #17587 - joshka:jm/edit-name-after-refactor, r=Veykrilbors-11/+16
Trigger VSCode to rename after extract variable assist is applied When the user applies the "Extract Variable" assist, the cursor is positioned at the newly inserted variable. This commit adds a command to the assist that triggers the rename action in VSCode. This way, the user can quickly rename the variable after applying the assist. Fixes part of: #17579 https://github.com/user-attachments/assets/4cf38740-ab22-4b94-b0f1-eddd51c26c29 I haven't yet looked at the module or function extraction assists yet.
2024-07-15Fix stable iteration ordering for `Map<Name, ...>` usagesLukas Wirth-4/+24
2024-07-14Use statics + clone instead of const until const can access staticsLukas Wirth-6/+6
2024-07-13Address feedback from @DropDemBitsJosh McKinney-3/+1
- move `edit.rename()` to the end of the function - use a match statement to set `res.command`
2024-07-12Trigger VSCode to rename after extract variable assist is appliedbors-11/+18
When the user applies the "Extract Variable" assist, the cursor is positioned at the newly inserted variable. This commit adds a command to the assist that triggers the rename action in VSCode. This way, the user can quickly rename the variable after applying the assist. Fixes part of: #17579
2024-07-12Use Symbol in NameLukas Wirth-19/+20
2024-07-10refactor: search for enum semanticallywinstxnhdw-6/+8
2024-07-09style: prefer type inferencewinstxnhdw-1/+1
- unrelated to the PR but I wanted to change this in #17467