aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
Commit message (Collapse)AuthorAgeFilesLines
* Add support for fill match arms of boolean valuesComonad2021-04-211-0/+8
| | | | - Add support for boolean inside tuple
* Merge #8578bors[bot]2021-04-191-0/+12
|\ | | | | | | | | | | | | | | | | 8578: fix: false positive about inner attrs in docs r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
| * fix: false positive about inner attrs in docsAleksey Kladov2021-04-191-0/+12
| | | | | | | | closes #8541
| |
| \
*-. \ Merge #8524 #8527bors[bot]2021-04-191-0/+153
|\ \ \ | |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]>
| | * Finish GenericParamsOwnerEdit implsDawer2021-04-151-5/+94
| | |
| | * Switch introduce_named_lifetime assist to use mutable syntax treeDawer2021-04-141-0/+64
| |/
* / Fill match arms for a tuple of a single enum.Dawer2021-04-161-6/+12
|/
* Basic Support Macro 2.0Edwin Cheng2021-03-271-0/+1
|
* Add TokenTextAleksey Kladov2021-03-261-7/+10
|
* syntax: return owned string instead of leaking stringcynecx2021-03-262-10/+8
|
* Use more std::array::IntoIterLaurențiu Nicola2021-03-251-4/+3
|
* Use arrayvec 0.6Laurențiu Nicola2021-03-251-8/+8
|
* Simplify codeAleksey Kladov2021-03-231-2/+3
| | | | changelog: skip
* rewrite merge use trees assist to use muatable syntax treesAleksey Kladov2021-03-223-42/+50
| | | | changelog internal
* a lot of clippy::style fixesMatthias Krüger2021-03-214-41/+29
|
* clippy::complexity simplifications related to IteratorsMatthias Krüger2021-03-211-2/+1
|
* use strip_prefix() instead of starts_with and slicing (clippy::manual_strip)Matthias Krüger2021-03-211-2/+1
|
* remove more redundant clones (clippy::redundant_clone())Matthias Krüger2021-03-211-1/+1
|
* Don't use an untyped String for ActiveParam trackingLukas Wirth2021-03-201-0/+9
|
* Move `AttrsOwnerNode` to syntax and make it publicJonas Schievink2021-03-191-0/+30
|
* Make ast editing more ergonomicAleksey Kladov2021-03-191-21/+20
| | | | changelog internal
* Parse extended_key_value_attributesLukas Wirth2021-03-192-33/+23
|
* Better handling of block doc commentsLukas Wirth2021-03-172-22/+13
|
* Merge #8059bors[bot]2021-03-171-1/+1
|\ | | | | | | | | | | | | | | 8059: Move doc-comment highlight injection from AST to HIR r=matklad,jonas-schievink a=Veykril Fixes #5016 Co-authored-by: Lukas Wirth <[email protected]>
| * Replace trait object boxing with extra AttrsOwnerNodeLukas Wirth2021-03-161-1/+1
| |
* | avoid converting types into themselves via .into() (clippy::useless-conversion)Matthias Krüger2021-03-171-1/+1
| | | | | | | | example: let x: String = String::from("hello world").into();
* | pit-of-successify tree editorAleksey Kladov2021-03-161-3/+3
| |
* | Auto-magical whitespaceAleksey Kladov2021-03-161-21/+11
| |
* | Move more boundsAleksey Kladov2021-03-161-10/+44
|/ | | | changelog: skip
* Upgrade rowanAleksey Kladov2021-03-163-3/+120
| | | | Notably, new rowan comes with support for mutable syntax trees.
* Fix macro expansion for statements w/o semicolonEdwin Cheng2021-03-161-2/+8
|
* feat: add expr_for_loop to make in syntaxLuiz Carlos Mourão Paes de Carvalho2021-03-101-0/+3
|
* Better strip turbofishesKirill Bulatov2021-03-081-0/+4
|
* Merge #7777bors[bot]2021-03-022-5/+9
|\ | | | | | | | | | | | | | | 7777: Implement line<->block comment assist r=Veykril a=djrenren Fixes: https://github.com/rust-analyzer/rust-analyzer/issues/6515 Co-authored-by: John Renner <[email protected]>
| * Implement line<->block comment assistJohn Renner2021-02-252-5/+9
| |
* | Add tests for apply_demorganLukas Wirth2021-02-241-2/+5
|/
* Fix incorrect missing field diagnostic with box patternsLaurențiu Nicola2021-02-201-4/+13
|
* Revert "Replace usage of ast::NameOrNameRef with ast::NameLike"Lukas Wirth2021-02-171-16/+21
| | | | This reverts commit e1dbf43cf85f84c3a7e40f9731fc1f7ac96f8979.
* Replace usage of ast::NameOrNameRef with ast::NameLikeLukas Wirth2021-02-171-21/+16
|
* Implement ast::AstNode for NameLike and move it to node_extLukas Wirth2021-02-161-0/+46
|
* Merge #7620bors[bot]2021-02-161-9/+50
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 7620: Support control flow in `extract_function` assist r=matklad a=cpud36 Support `return`ing from outer function, `break`ing and `continue`ing outer loops when extracting function. # Example Transforms ```rust fn foo() -> i32 { let items = [1,2,3]; let mut sum = 0; for &item in items { <|>if item == 42 { break; }<|> sum += item; } sum } ``` Into ```rust fn foo() -> i32 { let items = [1,2,3]; let mut sum = 0; for &item in items { if fun_name(item) { break; } sum += item; } sum } fn fun_name(item: i32) -> bool { if item == 42 { return true; } false } ``` ![add_explicit_type_infer_type](https://user-images.githubusercontent.com/4218373/107544222-0fadf280-6bdb-11eb-9625-ed6194ba92c0.gif) # Features Supported variants - break and function does not return => uses `bool` and plain if - break and function does return => uses `Option<T>` and matches on it - break with value and function does not return => uses `Option<T>` and if let - break with value and function does return => uses `Result<T, U>` and matches on t - same for `return` and `continue`(but we can't continue with value) Assist does handle nested loops and nested items(like functions, modules, impls) Try `expr?` operator is allowed together with `return Err(_)` and `return None`. `return expr` is not allowed. # Not supported ## Mixing `return` with `break` or `continue` If we have e.g. a `return` and a `break` in the selected code, it is unclear what the produced code should look like. We can try `Result<T, Option<U>>` or something like that, but it isn't idiomatic, nor it is established. Otherwise, implementation is relatively simple. ## `break` with label Not sure how to handle different labels for multiple `break`s. [edit] implemented try `expr?` Co-authored-by: Vladyslav Katasonov <[email protected]>
| * allow try expr? when extacting functionVladyslav Katasonov2021-02-131-0/+3
| |
| * handle return, break and continue when extracting functionVladyslav Katasonov2021-02-131-9/+47
| |
* | Don't rename field record patterns directlyLukas Wirth2021-02-131-3/+2
|/
* Refactor reference searching to work with the astLukas Wirth2021-02-121-4/+26
|
* AdtDef -> AdtAleksey Kladov2021-02-071-19/+19
|
* allow modifications of vars from outer scope inside extracted functionVladyslav Katasonov2021-02-031-1/+1
| | | | | It currently allows only directly setting variable. No `&mut` references or methods.
* Fix ast::String::value not properly escaping in some casesLukas Wirth2021-01-301-2/+19
|
* .Aleksey Kladov2021-01-193-14/+14
|
* :arrow_up: rowanAleksey Kladov2021-01-191-1/+1
|