aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
Commit message (Collapse)AuthorAgeFilesLines
...
* Split out merge_imports module from helpers::insert_useLukas Wirth2021-04-242-5/+2
|
*-. Merge #8591 #8638bors[bot]2021-04-237-152/+164
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8591: Remove SyntaxRewriter usage in insert_use in favor of mutable syntax trees r=matklad a=Veykril Unfortunately changing `insert_use` to not use `SyntaxRewriter` creates a lot of changes since so much relies on that. But on the other hand this should be the biggest usage of `SyntaxRewriter` I believe. 8638: Remove SyntaxRewriter::from_fn r=Veykril a=Veykril Co-authored-by: Lukas Wirth <[email protected]>
| | * Remove SyntaxRewriter::from_fnLukas Wirth2021-04-232-15/+21
| |/ |/|
* | Merge #8317bors[bot]2021-04-233-0/+559
|\ \ | | | | | | | | | | | | | | | | | | | | | 8317: Convert tuple struct to named struct assist r=Veykril a=unexge Closes https://github.com/rust-analyzer/rust-analyzer/issues/8192 Co-authored-by: unexge <[email protected]>
| * | Add missing test case for "Convert to named struct" assistunexge2021-04-231-0/+40
| | |
| * | Stop iterating reference after made an edit in "Convert to named struct" assistunexge2021-04-231-2/+47
| | |
| * | Move reference editing logic into own function to make error handling more ↵unexge2021-04-221-68/+61
| | | | | | | | | | | | ease in "Convert to named struct" assist
| * | Add multi file test for "Convert to named struct" assistunexge2021-04-211-0/+33
| | |
| * | Remove `unwrap`s in "Convert to named struct" assistunexge2021-04-211-9/+19
| | |
| * | Add larger example for "Convert to named struct" assistunexge2021-04-212-8/+60
| | |
| * | Fix incorrectly replacing method calls in "Convert to named struct" assistunexge2021-04-211-17/+41
| | |
| * | Add convert tuple struct to named struct assistunexge2021-04-043-0/+362
| | |
* | | Merge #8620bors[bot]2021-04-221-14/+22
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8620: Remove unnecessary braces for extracted block expression r=Veykril a=brandondong This change addresses the first bullet point of https://github.com/rust-analyzer/rust-analyzer/issues/7839. Specifically, when extracting block expressions, remove the unneeded extra braces inside the generated function. Co-authored-by: Brandon <[email protected]>
| * | | Remove unnecessary braces for extracted block expressionBrandon2021-04-221-14/+22
| | | |
* | | | Add support for fill match arms of boolean valuesComonad2021-04-211-23/+199
| | | | | | | | | | | | | | | | - Add support for boolean inside tuple
* | | | Merge #8602bors[bot]2021-04-201-28/+45
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8602: Fix panic in `replace_derive_with_manual_impl` r=jonas-schievink a=jonas-schievink bors r+ Co-authored-by: Jonas Schievink <[email protected]>
| * | | | Follow testing style guideJonas Schievink2021-04-201-28/+28
| | | | |
| * | | | Fix panic in `replace_derive_with_manual_impl`Jonas Schievink2021-04-201-0/+17
| |/ / /
* / / / "Inline variable" when on a use of the variableJonas Schievink2021-04-201-38/+185
|/ / /
| | * Don't filter equal nodes in reorder assistsLukas Wirth2021-04-212-10/+6
| | |
| | * Add cov_marks to insert_use testsLukas Wirth2021-04-203-39/+36
| | |
| | * Rewrite extract_struct_from_enum_variant assistLukas Wirth2021-04-201-85/+91
| | |
| | * Remove SyntaxRewriter usage in insert_use in favor of tedLukas Wirth2021-04-203-59/+62
| | |
| | * Replace SyntaxRewriter usage with ted in reorder_impl assistLukas Wirth2021-04-201-9/+13
| |/ |/|
* | Add autoimport test with inner itemsJonas Schievink2021-04-191-0/+33
| |
* | Merge #8583bors[bot]2021-04-191-23/+14
|\ \ | | | | | | | | | | | | | | | | | | | | | 8583: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
| * | SimplifyLukas Wirth2021-04-191-23/+14
| | |
| | |
| \ \
*-. \ \ Merge #8524 #8527bors[bot]2021-04-192-38/+138
|\ \ \ \ | |_|/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8524: Fix extract function with partial block selection r=matklad a=brandondong **Reproduction:** ```rust fn foo() { let n = 1; let mut v = $0n * n;$0 v += 1; } ``` 1. Select the snippet ($0) and use the "Extract into function" assist. 2. Extracted function is incorrect and does not compile: ```rust fn foo() { let n = 1; let mut v = fun_name(n); v += 1; } fn fun_name(n: i32) {} ``` 3. Omitting the ending semicolon from the selection fixes the extracted function: ```rust fn fun_name(n: i32) -> i32 { n * n } ``` **Cause:** - When `extraction_target` uses a block extraction (semicolon case) instead of an expression extraction (no semicolon case), the user selection is directly used as the TextRange. - However, the existing function extraction logic for blocks requires that the TextRange spans from start to end of complete statements to work correctly. - For example: ```rust fn foo() { let m = 2; let n = 1; let mut v = m $0* n; let mut w = 3;$0 v += 1; w += 1; } ``` produces ```rust fn foo() { let m = 2; let n = 1; let mut v = m let mut w = fun_name(n); v += 1; w += 1; } fn fun_name(n: i32) -> i32 { let mut w = 3; w } ``` - The user selected TextRange is directly replaced by the function call which is now in the middle of another statement. The extracted function body only contains statements that were fully covered by the TextRange and so the `* n` code is deleted. The logic for calculating variable usage and outlived variables for the function parameters and return type respectively search within the TextRange and so do not include `m` or `v`. **Fix:** - Only extract full statements when using block extraction. If a user selected part of a statement, extract that full statement. 8527: Switch introduce_named_lifetime assist to use mutable syntax tree r=matklad a=iDawer This extends `GenericParamsOwnerEdit` trait with `get_or_create_generic_param_list` method Co-authored-by: Brandon <[email protected]> Co-authored-by: Dawer <[email protected]>
| | * | Switch introduce_named_lifetime assist to use mutable syntax treeDawer2021-04-141-36/+76
| | | |
| * | | Fix extract function with partial block selectionBrandon2021-04-151-2/+62
| | | |
* | | | Merge #8565bors[bot]2021-04-191-28/+100
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8565: Fill match arms assist: add remaining arms for tuple of enums r=iDawer a=iDawer Fix for #8493 However, the assist is still flaky and does not use `hir_ty::diagnostics::match_check` Co-authored-by: Dawer <[email protected]>
| * | | | Unindent test according to the style guide.Dawer2021-04-191-23/+23
| | | | |
| * | | | Return to the status quo in #8129Dawer2021-04-181-0/+2
| | | | |
| * | | | Prevent adding useless match armsDawer2021-04-181-11/+27
| | | | |
| * | | | Test fill-match-arms assist: partial with wildcardsDawer2021-04-171-0/+34
| | | | |
| * | | | Fill partial match arms for a tuple of enumsDawer2021-04-161-17/+37
| | | | |
* | | | | Merge #8467bors[bot]2021-04-194-0/+257
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8467: Adds impl Deref assist r=jhgg a=jhgg This PR adds a new `generate_deref` assist that automatically generates a deref impl for a given struct field. Check out this gif: ![2021-04-11_00-33-33](https://user-images.githubusercontent.com/5489149/114296006-b38e1000-9a5d-11eb-9112-807c01b8fd0a.gif) -- I have a few Q's: - [x] Should I write more tests, if so, what precisely should I test for? - [x] I have an inline question on line 65, can someone provide guidance? :) - [x] I can implement this for `ast::TupleField` too. But should it be a separate assist fn, or should I try and jam both into the `generate_deref`? - [x] I want to follow this up with an assist on `impl $0Deref for T {` which would automatically generate a `DerefMut` impl that mirrors the Deref as well, however, I could probably use some pointers on how to do that, since I'll have to reach into the ast of `fn deref` to grab the field that it's referencing for the `DerefMut` impl. Co-authored-by: jake <[email protected]>
| * | | | | implement field stuff toojake2021-04-191-22/+106
| | | | | |
| * | | | | Adds impl Deref assistjake2021-04-114-0/+173
| | |_|/ / | |/| | |
* | | | | Add some more error messages to fixture failure casesLukas Wirth2021-04-171-2/+4
| |/ / / |/| | |
* | | | Fill match arms for a tuple of a single enum.Dawer2021-04-161-10/+12
| |/ / |/| |
* | | Merge #8415bors[bot]2021-04-131-2/+46
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8415: Fix faulty assertion when extracting function with macro call r=matklad a=brandondong **Reproduction:** ```rust fn main() { let n = 1; let k = n * n; dbg!(n); } ``` 1. Select the second and third lines of the main function. Use the "Extract into function" code assist. 2. Panic occurs in debug, error is logged in release: "[ERROR ide_assists::handlers::extract_function] assertion failed: matches!(path, ast :: Expr :: PathExpr(_))". 3. Function generates successfully on release where the panic was bypassed. ```rust fn fun_name(n: i32) { let k = n * n; dbg!(n); } ``` **Cause:** - The generated function will take `n` as a parameter. The extraction logic needs to search the usages of `n` to determine whether it is used mutably or not. The helper `path_element_of_reference` is called for each usage but the second usage is a macro call and fails the `Expr::PathExpr(_)` match assertion. - The caller of `path_element_of_reference` does implicitly assume it to be a `Expr::PathExpr(_)` in how it looks at its parent node for determining whether it is used mutably. This logic will not work for macros. - I'm not sure if there are any other cases besides macros where it could be something other than a `Expr::PathExpr(_)`. I tried various examples and could not find any. **Fix:** - Update assertion to include the macro case. - Add a FIXME to properly handle checking if a macro usage requires mutable access. For now, return false instead of running the existing logic that is tailored for `Expr::PathExpr(_)`'s. Co-authored-by: Brandon <[email protected]>
| * | | Add macro testBrandon2021-04-111-0/+32
| | | |
| * | | Add FIXME for macro caseBrandon2021-04-081-0/+13
| | | |
| * | | Fix faulty assertion when extracting function with macro callBrandon2021-04-081-2/+1
| | | |
* | | | internal: don't use `#[should_panic]` for testsAleksey Kladov2021-04-131-16/+2
| | | |
* | | | internal: unfork code paths for unresolved and resolved assistAleksey Kladov2021-04-131-0/+2
| |/ / |/| |
* | | Merge #8436bors[bot]2021-04-101-19/+109
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 8436: Fix extract function's mutability of variables outliving the body r=matklad a=brandondong **Reproduction:** ```rust fn main() { let mut k = 1; let mut j = 2; j += 1; k += j; } ``` 1. Select the first to third lines of the main function. Use the "Extract into function" code assist. 2. The output is the following which does not compile because the outlived variable `k` is declared as immutable: ```rust fn main() { let (k, j) = fun_name(); k += j; } fn fun_name() -> (i32, i32) { let mut k = 1; let mut j = 2; j += 1; (k, j) } ``` 3. We would instead expect the output to be: ```rust fn main() { let (mut k, j) = fun_name(); k += j; } ``` **Fix:** - Instead of declaring outlived variables as immutable unconditionally, check for any mutable usages outside of the extracted function. Co-authored-by: Brandon <[email protected]>
| * | | Fix extract function's mutability of variables outliving the bodyBrandon2021-04-091-19/+109
| |/ /
* | | Insert unnamed consts to ChildBySource DynMapLukas Wirth2021-04-091-1/+1
| | |