aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers/extract_function.rs
Commit message (Collapse)AuthorAgeFilesLines
* internal: remove one more usage of SyntaxRewriterAleksey Kladov2021-05-081-56/+46
|
* internal: remove one more usage of the rewriterAleksey Kladov2021-05-041-10/+23
|
* internal: fix naming polarityAleksey Kladov2021-04-301-1/+1
| | | | | Type Constructors have *parameters*, when they are substituted with type *arguments*, we have a type.
* Remove unnecessary braces for extracted block expressionBrandon2021-04-221-14/+22
|
* Fix extract function with partial block selectionBrandon2021-04-151-2/+62
|
* 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
| |
* | Fix extract function's mutability of variables outliving the bodyBrandon2021-04-091-19/+109
|/
* Upgrade rowanAleksey Kladov2021-03-161-14/+6
| | | | Notably, new rowan comes with support for mutable syntax trees.
* Use upstream cov-markLaurențiu Nicola2021-03-081-11/+10
|
* Honor snippet capability in extract function assistsan2021-03-051-2/+8
|
* 7526: Rename crate assists to ide_assists.Chetan Khilosiya2021-02-221-0/+3378