aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers/extract_function.rs
Commit message (Collapse)AuthorAgeFilesLines
* Extract function assist will add async if requiredJamie Cunliffe2021-05-171-2/+63
| | | | | The extract function assist will check for an AWAIT_EXPR in the body and if found, will add async to the generated function.
* internal: introduce `ast::make::ext` module with common shortcutsAleksey Kladov2021-05-091-37/+25
| | | | | | | | | | There's a tension between keeping a well-architectured minimal orthogonal set of constructs, and providing convenience functions. Relieve this pressure by introducing an dedicated module for non-orthogonal shortcuts. This is inspired by the django.shortcuts module which serves a similar purpose architecturally.
* internal: fix make APIAleksey Kladov2021-05-091-1/+1
|
* 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