Commit graph

364 commits

Author SHA1 Message Date
Dawer
0a156c80af Hide implementation details of TokenText 2021-05-06 10:07:06 +05:00
Dawer
d9b4ac8128 Clean up 2021-05-06 10:07:06 +05:00
Dawer
d7e169fe55 Borrow text from nodes of immutable syntax trees 2021-05-06 10:07:06 +05:00
Dawer
dc4fa504ea Adapt to a new rowan borrowing node API. 2021-05-06 10:06:52 +05:00
Dawer
52143f389f Update to rowan 0.13.0-pre.5 2021-05-06 10:04:39 +05:00
Jonas Schievink
cb8632d87c Parse const param defaults 2021-04-29 03:07:53 +02:00
Jonas Schievink
caee3a2eeb Correctly parse negated literals as const args 2021-04-29 02:27:55 +02:00
Lukas Wirth
050c69c19d Split out merge_imports module from helpers::insert_use 2021-04-24 13:31:43 +02:00
bors[bot]
5cbde9f531
Merge #8591 #8638
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 <lukastw97@gmail.com>
2021-04-23 16:49:08 +00:00
Lukas Wirth
e6e4417bbb Remove SyntaxRewriter::from_fn 2021-04-23 18:36:43 +02:00
bors[bot]
85bab7539a
Merge #8317
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 <unexge@gmail.com>
2021-04-23 13:37:48 +00:00
Laurențiu Nicola
e50ca6b067 Bump rustc_lexer 2021-04-21 19:19:27 +03:00
Comonad
09147c3303 Add support for fill match arms of boolean values
- Add support for boolean inside tuple
2021-04-21 19:33:45 +08:00
Lukas Wirth
3f7a086b4f Parse outer atttributes for RecordPatField 2021-04-21 11:08:15 +02:00
Lukas Wirth
fa20a5064b Remove SyntaxRewriter usage in insert_use in favor of ted 2021-04-20 02:09:12 +02:00
bors[bot]
6877e6e4da
Merge #8578
8578: fix: false positive about inner attrs in docs r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-04-19 14:37:54 +00:00
Aleksey Kladov
5f89a60f1a fix: false positive about inner attrs in docs
closes #8541
2021-04-19 17:11:49 +03:00
bors[bot]
e7a8977358
Merge #8524 #8527
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 <brandondong604@hotmail.com>
Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-04-19 13:09:18 +00:00
cynecx
cf3b4f1e20 hir_ty: Expand macros at type position 2021-04-17 16:24:56 +02:00
Bernhard Schuster
3b7753d257
nail rowan version down
The different pre versions include breaking changes, which cause build failures for the users.
2021-04-17 09:31:54 +02:00
Dawer
8965be3d0e Fill match arms for a tuple of a single enum. 2021-04-16 17:22:11 +05:00
Dawer
cedbf2e1c5 Finish GenericParamsOwnerEdit impls 2021-04-15 15:57:45 +05:00
Dawer
144afa55a6 Switch introduce_named_lifetime assist to use mutable syntax tree 2021-04-15 01:56:19 +05:00
kjeremy
761a81822a Update crates 2021-04-07 11:39:33 -04:00
kjeremy
b246f57fad Use arrayvec 0.7 to avoid perf regression in 0.6.1
See: https://github.com/bluss/arrayvec/issues/182
2021-04-05 12:58:35 -04:00
unexge
8d4be829e0 Add convert tuple struct to named struct assist 2021-04-04 20:52:43 +03:00
Edwin Cheng
eedadd7024 Add support for doc on hover for macro 2.0 2021-03-27 14:57:11 +08:00
Edwin Cheng
a193666361 Basic Support Macro 2.0 2021-03-27 13:44:54 +08:00
Aleksey Kladov
1bbac9053d Add TokenText 2021-03-26 21:33:45 +03:00
cynecx
5ff3299dd6 syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
Laurențiu Nicola
bc5c86543b Use more std::array::IntoIter 2021-03-25 21:06:48 +02:00
Laurențiu Nicola
9787bddac5 Use arrayvec 0.6 2021-03-25 21:03:20 +02:00
Aleksey Kladov
e33959a888 Simplify code
changelog: skip
2021-03-23 19:41:15 +03:00
Aleksey Kladov
9cbf09ec4f rewrite merge use trees assist to use muatable syntax trees
changelog internal
2021-03-22 20:47:46 +03:00
Aleksey Kladov
48b534ceb8 ⬆️ rowan 2021-03-22 20:26:59 +03:00
Matthias Krüger
202b51bc7b a lot of clippy::style fixes 2021-03-21 16:15:41 +01:00
Matthias Krüger
ae7e55c1dd clippy::complexity simplifications related to Iterators 2021-03-21 13:13:34 +01:00
Matthias Krüger
8a67116857 use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) 2021-03-21 12:38:21 +01:00
Matthias Krüger
3d9b3a8575 remove more redundant clones (clippy::redundant_clone()) 2021-03-21 12:10:39 +01:00
Lukas Wirth
38048c35d8 Don't use an untyped String for ActiveParam tracking 2021-03-20 23:22:09 +01:00
Jonas Schievink
fc5f73de45 Move AttrsOwnerNode to syntax and make it public 2021-03-19 20:05:17 +01:00
Aleksey Kladov
a61691026a Make ast editing more ergonomic
changelog internal
2021-03-19 20:53:23 +03:00
Lukas Wirth
4771a56791 Parse extended_key_value_attributes 2021-03-19 02:13:46 +01:00
Jonas Schievink
022a0f061e Correctly parse attributes on fn parameters 2021-03-17 18:28:27 +01:00
Lukas Wirth
ec824a92d0 Better handling of block doc comments 2021-03-17 14:48:57 +01:00
bors[bot]
0fbfab3b45
Merge #8059
8059: Move doc-comment highlight injection from AST to HIR r=matklad,jonas-schievink a=Veykril

Fixes #5016

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 11:13:54 +00:00
Matthias Krüger
966c23f529 avoid converting types into themselves via .into() (clippy::useless-conversion)
example: let x: String = String::from("hello world").into();
2021-03-17 01:27:56 +01:00
Aleksey Kladov
186a430853 pit-of-successify tree editor 2021-03-16 22:59:57 +03:00
Aleksey Kladov
34555593ca Auto-magical whitespace 2021-03-16 22:51:37 +03:00
Aleksey Kladov
d733c9bdad Move more bounds
changelog: skip
2021-03-16 22:28:04 +03:00
Lukas Wirth
acc6458390 Replace trait object boxing with extra AttrsOwnerNode 2021-03-16 19:06:58 +01:00
Aleksey Kladov
f5a81ec468 Upgrade rowan
Notably, new rowan comes with support for mutable syntax trees.
2021-03-16 16:10:49 +03:00
Edwin Cheng
8e07b23b84 Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
Lukas Wirth
6e6d75bbdc Attach trivia to ast::Union nodes 2021-03-14 11:11:01 +01:00
bors[bot]
c0459c5357
Merge #7956
7956: Add assist to convert for_each into for loops r=Veykril a=SaiintBrisson

This PR resolves #7821.
Adds an assist to that converts an `Iterator::for_each` into a for loop: 

```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    x.iter().for_each(|(x, y)| {
        println!("x: {}, y: {}", x, y);
    })
}
```
becomes
```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    for (x, y) in x.iter() {
        println!("x: {}, y: {}", x, y);
    });
}
```

Co-authored-by: Luiz Carlos Mourão Paes de Carvalho <luizcarlosmpc@gmail.com>
Co-authored-by: Luiz Carlos <luizcarlosmpc@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 14:45:04 +00:00
kjeremy
08e0e9976d cargo update and lexer 2021-03-10 13:47:12 -05:00
Luiz Carlos Mourão Paes de Carvalho
61fb16577b feat: add expr_for_loop to make in syntax 2021-03-09 23:54:35 -03:00
bors[bot]
21913d0fdb
Merge #7873 #7933
7873: Consider unresolved qualifiers during flyimport r=matklad a=SomeoneToIgnore

Closes https://github.com/rust-analyzer/rust-analyzer/issues/7679

Takes unresolved qualifiers into account, providing better completions (or none, if the path is resolved or do not match).

Does not handle cases when both path qualifier and some trait has to be imported: there are many extra issues with those (such as overlapping imports, for instance) that will require large diffs to address.

Also does not do a fuzzy search on qualifier, that requires some adjustments in `import_map` for better queries and changes to the default replace range which also seems relatively big to include here.

![qualifier_completion](https://user-images.githubusercontent.com/2690773/110040808-0af8dc00-7d4c-11eb-83db-65af94e843bb.gif)


7933: Improve compilation speed r=matklad a=matklad

bors r+
🤖

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-09 11:58:48 +00:00
Aleksey Kladov
867fdf8f03 Improve compilation speed 2021-03-09 14:54:50 +03:00
Kirill Bulatov
778deb38fe Better strip turbofishes 2021-03-08 23:59:39 +02:00
Laurențiu Nicola
fc9eed4836 Use upstream cov-mark 2021-03-08 22:19:44 +02:00
Aleksey Kladov
abb6b8f14c Use the same name in xtask and test utils 2021-03-08 21:45:06 +03:00
kjeremy
41d1b4cd26 Update lexer 2021-03-02 15:33:22 -05:00
bors[bot]
2183d65c97
Merge #7777
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 <john@jrenner.net>
2021-03-02 08:04:38 +00:00
kjeremy
d42730b76e bump crates 2021-02-25 10:34:48 -05:00
John Renner
9eecba4dbf Implement line<->block comment assist 2021-02-24 17:13:00 -08:00
Lukas Wirth
694f7a7e9f Add tests for apply_demorgan 2021-02-24 11:58:37 +01:00
Laurențiu Nicola
48ae948b22 Bump deps 2021-02-21 19:13:11 +02:00
Laurențiu Nicola
af4148970a Fix incorrect missing field diagnostic with box patterns 2021-02-20 12:36:17 +02:00
Lukas Wirth
2887426da0 Revert "Replace usage of ast::NameOrNameRef with ast::NameLike"
This reverts commit e1dbf43cf8.
2021-02-17 15:00:44 +01:00
Lukas Wirth
e1dbf43cf8 Replace usage of ast::NameOrNameRef with ast::NameLike 2021-02-17 14:02:34 +01:00
Lukas Wirth
e52bdc55ef Implement ast::AstNode for NameLike and move it to node_ext 2021-02-16 19:27:08 +01:00
bors[bot]
b7a6d830be
Merge #7687
7687: Specialization for async traits r=matklad a=arnaudgolfouse

Fixes #7669.

Adapting the parser seemed to be all that was needed, but I am not very experienced with the codebase. Is this enough ?

Co-authored-by: Arnaud <arnaud.golfouse@laposte.net>
2021-02-16 14:16:47 +00:00
bors[bot]
88e8b0a5fa
Merge #7620
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 <cpud47@gmail.com>
2021-02-16 14:01:09 +00:00
Arnaud
95d239da99 Specialization for async traits 2021-02-15 18:33:12 +01:00
Lukas Wirth
7b64622780 Don't rename field record patterns directly 2021-02-13 23:47:21 +01:00
Vladyslav Katasonov
9eb19d92dd allow try expr? when extacting function 2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
f345d1772a handle return, break and continue when extracting function 2021-02-13 22:04:52 +03:00
Lukas Wirth
d644728d82 Refactor reference searching to work with the ast 2021-02-12 18:58:28 +01:00
Aleksey Kladov
61f15b72ac Add parsing benchmark 2021-02-09 21:52:34 +03:00
Aleksey Kladov
4b1279d0b1 Infra for "unit" benchmarking 2021-02-09 20:25:39 +03:00
kjeremy
0c3b38695a Update crates
Pulls in https://github.com/rust-lang/chalk/pull/682
2021-02-08 11:38:51 -05:00
Aleksey Kladov
7022ea52b5 AdtDef -> Adt 2021-02-07 14:15:02 +03:00
bors[bot]
ac5958485e
Merge #7535
7535: Extract function assist r=cpud36 a=cpud36

This PR adds `extract function/method` assist. closes #5409.

# Supported features
Assist should support extracting from expressions(`1`, `2 + 2`, `loop { }`) and from a series of statements, e.g.:
```rust
foo();
$0bar();
baz();$0
quix();
```
Assist also supports extracting parameters, like:
```rust
fn foo() -> i32 {
  let n = 1;
  $0n + 1$0
}

// -
fn foo() -> i32 {
  let n = 1;
  fun_name(n)
}

fn fun_name(n: i32) -> i32 {
  n + 1
}
```

Extracting methods also generally works.

Assist allows referencing outer variables, both mutably and immutably, and handles handles access to variables local to extracted function:
```rust
fn foo() {
  let mut n = 1;
  let mut m = 2;
  let mut moved_v = Vec::new();
  let mut ref_mut_v = Vec::new();
  $0
  n += 1;
  let k = 1;
  moved_v.push(n);
  let r = &mut m;
  ref_mut_v.push(*r);
  let h = 3;
  $0
  n = ref_mut_v.len() + k;
  n -= h + m;
}

// -
fn foo() {
  let mut n = 1;
  let mut m = 2;
  let mut moved_v = Vec::new();
  let mut ref_mut_v = Vec::new();
 
  let (k, h) =  fun_name(&mut n, moved_v, &mut m, &mut ref_mut_v);

  n = ref_mut_v.len() + k;
  n -= h + m;
}

fn fun_name(n: &mut i32, mut moved_v: Vec<i32>, m: &mut i32, ref_mut_v: &mut Vec<i32>) -> (i32, i32) {
  *n += 1;
  let k = 1;
  moved_v.push(*n);
  let r = m;
  ref_mut_v.push(*r);
  let h = 3;
  (k, h)
}
```

So we handle both input and output paramters

# Showcase

![extract_cursor_in_range_3](https://user-images.githubusercontent.com/4218373/106980190-c9870800-6770-11eb-83d9-3d36b2550ff6.gif)
![fill_match_arms_discard_wildcard](https://user-images.githubusercontent.com/4218373/106980197-cbe96200-6770-11eb-96b0-14c27894fac0.gif)
![ide_db_helpers_handle_kind](https://user-images.githubusercontent.com/4218373/106980201-cdb32580-6770-11eb-9e6e-6ac8155d65ac.gif)
![ide_db_imports_location_local_query](https://user-images.githubusercontent.com/4218373/106980205-cf7ce900-6770-11eb-8516-653c8fcca807.gif)

# Working with non-`Copy` types

Consider the following example:
```rust
fn foo() {
  let v = Vec::new();
  $0
  let n = v.len();
  $0
  let is_empty = v.is_empty();
}
```
`v` must be a parameter to extracted function. 
The question is, what type should it have.
It could be `v: Vec<i32>`, or `v: &Vec<i32>`. 
The former is incorrect for `Vec<i32>`, but the later is silly for `i32`.

To resolve this we need to know if the type implements `Copy` trait.

I didn't find any api available from assists to query this. 
`hir_ty::method_resolution::implements` seems relevant, but is isn't publicly re-exported from `hir`.

# Star(`*`) token and pointer dereference

If I understand correctly, in order to create expression like `*p`, one should use `ast::make::expr_prefix(T![*], ...)`, which
in turn calls `token(T![*])`.

`token` does not have star in `tokens::SOURCE_FILE`, so this panics.
I had to add `*` to `SOURCE_FILE` to make it work.

Correct me if this is not intended way to do this.

# Lowering access `value -> mut ref -> shared ref`

Consider the following example:
```rust
fn foo() {
  let v = Vec::new();
  $0 let n = v.len(); $0
}
```
`v` is not used after extracted function body, so both `v: &Vec<i32>` and `v: Vec<i32>` would work.
Currently the later would be chosen.

We can however check the body of extracted function and conclude that `v: &Vec<i32>` is sufficient.
Using `v: &Vec<i32>`(that is a minimal required access level) might be a better default.
I am unsure.

# Cleanup
The assist seems to be reasonably handling most of common cases.
If there are no concerns with code it produces(i.e. with test cases), I will start cleaning up

[edit]
added showcase


Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
2021-02-05 02:55:56 +00:00
Vladyslav Katasonov
f102616aae allow modifications of vars from outer scope inside extracted function
It currently allows only directly setting variable.
No `&mut` references or methods.
2021-02-03 23:45:03 +03:00
Edwin Cheng
e73ffbf1e5 Add cargo file tidy test 2021-02-03 22:01:09 +08:00
Laurențiu Nicola
6b60206669 Bump rustc_lexer 2021-02-02 17:40:01 +02:00
Lukas Wirth
6c2ce55150 Fix ast::String::value not properly escaping in some cases 2021-01-30 16:31:19 +01:00
Laurențiu Nicola
efafcf2428 Bump deps 2021-01-27 14:22:19 +02:00
Aleksey Kladov
1df711b95c ⬆️ rowan 2021-01-25 12:32:35 +03:00
Lukas Wirth
70d43c3faf Add validation for mutable const items 2021-01-24 02:17:41 +01:00
kjeremy
f006517857 Up lexer 2021-01-21 09:31:06 -05:00
Aleksey Kladov
3429b32ad1 ⬆️ rowan
It now stores text inline with tokens
2021-01-20 14:04:53 +03:00
Aleksey Kladov
46b4f89c92 . 2021-01-20 01:56:11 +03:00
Aleksey Kladov
cd21b0e9c1 ⬆️ rowan 2021-01-19 22:11:42 +03:00
Lukas Wirth
b26002410b Parse impl const Trait 2021-01-18 20:18:02 +01:00
Jonas Schievink
872bf09381 Add MacroType syntax 2021-01-18 17:56:35 +01:00
bors[bot]
9daba961f2
Merge #7291
7291: Wrap remaining self/super/crate in Name{Ref} r=matklad a=Veykril

That should be the remaining special casing for `self` 🎉 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-18 16:13:06 +00:00
Aleksey Kladov
b38414c7f4 When building an item-tree, keep fewer nodes in memory 2021-01-16 23:07:28 +03:00
Lukas Wirth
98718e0544 Wrap remaining self/super/crate in Name{Ref} 2021-01-15 22:18:43 +01:00
unexge
a3a722de9f Add Unmerge Use assist 2021-01-15 22:14:51 +03:00
bors[bot]
8a869e870a
Merge #7288
7288: Handle self/super/crate in PathSegment as NameRef r=matklad a=Veykril

Wrapping self/super/crate in NameRef as per https://github.com/rust-analyzer/rust-analyzer/pull/7261#issuecomment-760023172



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-15 18:40:47 +00:00
Lukas Wirth
cb863390f2 Handle self/super/crate in PathSegment as NameRef 2021-01-15 19:21:23 +01:00
bors[bot]
148e3d0f6a
Merge #7287
7287: Make SyntaxPtr lookup logarithmic r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-15 17:46:36 +00:00
Aleksey Kladov
26ef7e39f4 Make SyntaxPtr lookup logarithmic
closes #3934

cc https://github.com/rust-analyzer/rowan/pull/81
2021-01-15 20:40:40 +03:00
bors[bot]
a8587f153b
Merge #7286
7286: Remove useless wrapper r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-15 17:16:27 +00:00
Aleksey Kladov
6dbba4d75d Remove useless wrapper 2021-01-15 20:15:33 +03:00
Daiki Ihara
138514bea2 Add test for yield_expr 2021-01-15 23:35:17 +09:00
Daiki Ihara
85cd3524e2 Add support for yiled keyword 2021-01-15 23:35:17 +09:00
Aleksey Kladov
8dc68ecdfc Introduce more appropriate assertion mechanism
rust-analyzer is a long-running program, so we *should* handle assertion
failures.

See also https://www.sqlite.org/assert.html.
2021-01-14 18:25:19 +03:00
bors[bot]
607b9ea160
Merge #7218
7218: Fix typos r=Veykril a=regexident

Apart from the very last commit on this PR (which fixes a public type's name) all changes are non-breaking.

Co-authored-by: Vincent Esche <regexident@gmail.com>
2021-01-10 18:16:29 +00:00
Vincent Esche
d462119744 Updated tests via cargo xtask codegen 2021-01-10 18:36:27 +01:00
bors[bot]
b3ae7974af
Merge #7239
7239: Replace SyntaxKind usage with T! macro where applicable r=lnicola a=Veykril

https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#token-names

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-10 16:31:32 +00:00
Lukas Wirth
e618d12903 Replace SyntaxKind usage with T! macro where applicable 2021-01-10 17:14:01 +01:00
Laurențiu Nicola
10e7fd25fe Fix typo, parentheses is plural 2021-01-10 17:56:53 +02:00
Callym
dcb4c0ada6 Allow true and false keywords in const generics 2021-01-10 13:58:09 +00:00
Vincent Esche
c8c2bd097a Fixed typos in local bindings 2021-01-09 15:41:29 +01:00
Vincent Esche
6cd93db8a5 Fixed typos in code asserts 2021-01-09 15:41:29 +01:00
Vincent Esche
21f8239ac8 Fixed typos in code comments 2021-01-09 15:41:29 +01:00
Kevaundray Wedderburn
72b9a4fbd3 Change <|> to $0 - Rebase 2021-01-07 12:09:23 +00:00
Aleksey Kladov
f9707cde68 Rename expr -> tail_expr 2021-01-05 15:51:13 +03:00
kjeremy
f2d1144b4a Update crates 2021-01-04 11:12:42 -05:00
bors[bot]
ac123ac9e4
Merge #6587
6587: SSR: Support statement matching and replacing r=davidlattimore a=MarijnS95


For #3186

Hi!

This is a smaller initial patchset that came up while working on support for statement lists (and my first time working on RA 😁). It has me stuck on trailing semicolons for which I hope to receive some feedback. Matching (and replacing) `let` bindings with a trailing semicolon works fine, but trying to omit these (to make patterns more ergonomic) turns out more complex than expected.

The "optional trailing semicolon solution" implemented in this PR is ugly because `Matcher::attempt_match_token` should only consume a trailing `;` when parsing `let` bindings to prevent other code from breaking. That at the same time has a nasty side-effect of `;` ending up in the matched code: any replacements on that should include the trailing semicolon as well even if it was not in the pattern. A better example is in the tests:

3ae1649c24/crates/ssr/src/tests.rs (L178-L184)

The end result to achieve is (I guess) allowing replacement of let bindings without trailing semicolon like `let x = $a ==>> let x = 1` (but including them on both sides is still fine), and should make replacement in a macro call (where `foo!(let a = 2;)` for a `$x:stmt` is invalid syntax) possible as well. That should allow to enable/fix these tests:

3ae1649c24/crates/ssr/src/tests.rs (L201-L214)

A possible MVP of this PR might be to drop this optional `;' handling entirely and only allow an SSR pattern/template with semicolons on either side.

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
2021-01-04 11:14:40 +00:00
Jesse Bakker
c7e0c7f43a Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
Marijn Suijten
42da26e959 parser,syntax: Add separate parser for stmt with optional semicolon
Adjusting `grammar::fragments::stmt` to Optional or Yes will break
original functionality and tests.
2021-01-03 12:05:52 +01:00
Marijn Suijten
cc081b7e1c syntax,ssr: Implement statement parsing 2021-01-03 11:29:33 +01:00
cynecx
59fe884ef5 Fix warnings on rust-nightly 2021-01-02 20:48:39 +01:00
kjeremy
dc1396eec7 Update crates 2020-12-30 10:39:50 -05:00
AdnoC
ddbf484acf indentation 2020-12-29 22:56:00 -07:00
AdnoC
6eeec5d75f Smarter bracketed use diagnostic 2020-12-29 22:46:34 -07:00
bors[bot]
1487f2f10e
Merge #7027
7027: Fix macro_rules not accepting brackets or parentheses r=matklad,lnicola a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-24 08:44:52 +00:00
Lukas Wirth
3e0bb89541 Fix macro_rules not accepting brackets or parentheses 2020-12-24 09:36:47 +01:00
bors[bot]
a82c2445be
Merge #7020
7020: Implement const pat and expr inference r=flodiebold a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-23 19:50:04 +00:00
Lukas Wirth
a142beaf01 Implement const block inference 2020-12-23 12:24:24 +01:00
bors[bot]
4228e826b8
Merge #7016
7016: Bump deps r=flodiebold a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-12-23 11:04:07 +00:00
bors[bot]
fd1fcf2c2e
Merge #7010
7010: Update ungrammar for const block patterns r=matklad a=Veykril

Fixes #6848

Adds const blocks and const block patterns to the AST and parses them.

Blocked on https://github.com/rust-analyzer/ungrammar/pull/17/, will merge that PR there once this one gets the OK so I can remove the local ungrammar dependency path and fix the Cargo.lock.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-23 10:37:30 +00:00
Aleksey Kladov
f00f75a078 Document make module design 2020-12-23 13:01:31 +03:00
Laurențiu Nicola
18a7b98b2e Bump rustc_lexer 2020-12-23 11:24:52 +02:00
Lukas Wirth
2c94c4964a Parse const effect block 2020-12-23 02:15:44 +01:00
Lukas Wirth
03a9bbacf2 Parse ConstBlockPat 2020-12-23 01:49:43 +01:00
Lukas Wirth
be7260485e Update ungrammar for const block patterns 2020-12-23 01:26:31 +01:00
bors[bot]
9bb9fbab3a
Merge #6965
6965: Properly attach attributes to Param instead of parent ParamList r=matklad a=Veykril

Fixes #2783, fixes #2781

The problem with `let _a = [0,#[cfg(feature = "L")]0];` has already been fixed some time ago it seems:
<details>
  <summary>Syntax Tree for the const item</summary>

```
  LET_STMT@200..236
    LET_KW@200..203 "let"
    WHITESPACE@203..204 " "
    IDENT_PAT@204..206
      NAME@204..206
        IDENT@204..206 "_a"
    WHITESPACE@206..207 " "
    EQ@207..208 "="
    WHITESPACE@208..209 " "
    ARRAY_EXPR@209..235
      L_BRACK@209..210 "["
      LITERAL@210..211
        INT_NUMBER@210..211 "0"
      COMMA@211..212 ","
      LITERAL@212..234
        ATTR@212..233
          POUND@212..213 "#"
          L_BRACK@213..214 "["
          PATH@214..217
            PATH_SEGMENT@214..217
              NAME_REF@214..217
                IDENT@214..217 "cfg"
          TOKEN_TREE@217..232
            L_PAREN@217..218 "("
            IDENT@218..225 "feature"
            WHITESPACE@225..226 " "
            EQ@226..227 "="
            WHITESPACE@227..228 " "
            STRING@228..231 "\"L\""
            R_PAREN@231..232 ")"
          R_BRACK@232..233 "]"
        INT_NUMBER@233..234 "0"
      R_BRACK@234..235 "]"
    SEMICOLON@235..236 ";"
```
</details>

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-21 08:54:31 +00:00
Lukas Wirth
3ea4d43850 Properly parse legacy trait objects with leading ForType 2020-12-20 21:53:55 +01:00
Lukas Wirth
64caa027b8 Parse attributes in tuple expressions 2020-12-20 21:01:36 +01:00
Lukas Wirth
4be9ed675e Properly attach attributes to Param instead of parent ParamList 2020-12-20 20:30:18 +01:00
bors[bot]
c073e4f6ba
Merge #6934
6934: Implement `cfg_attr` handling r=jonas-schievink a=jonas-schievink

Part of https://github.com/rust-analyzer/rust-analyzer/issues/5548

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-18 19:27:18 +00:00
Jonas Schievink
08de1b4fa5 Implement RawAttr::filter 2020-12-18 18:58:42 +01:00
Aleksey Kladov
cd4a7bf36e Minor, cleanup API 2020-12-18 19:50:00 +03:00
bors[bot]
067067a6c1
Merge #6896
6896: Node-ify lifetimes r=jonas-schievink a=Veykril

Let's see if this passes the tests 🤞 

Depends on https://github.com/rust-analyzer/ungrammar/pull/15

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-16 17:08:03 +00:00