Commit graph

578 commits

Author SHA1 Message Date
Aleksey Kladov
c4d2671767 minor: untangle complex condition 2021-07-04 17:32:59 +03:00
Aleksey Kladov
c2704bebc1 minor: better error message 2021-07-04 11:20:31 +03:00
bors[bot]
336194c09b
Merge #9476
9476: internal: overhaul codegen r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-07-03 19:26:04 +00:00
Aleksey Kladov
58d2ece88a internal: overhaul code generation
* Keep codegen adjacent to the relevant crates.
* Remove codgen deps from xtask, speeding-up from-source installation.

This regresses the release process a bit, as it now needs to run the
tests (and, by extension, compile the code).
2021-07-03 22:11:03 +03:00
Lukas Wirth
d308f17a21 Inline parameters in inline_call if possible 2021-07-03 20:05:54 +02:00
Lukas Wirth
14e18bfa38 Merge the inline function/method assists into inline_call 2021-07-03 18:07:03 +02:00
Lukas Wirth
688398febc feat: Implement inline_method assist 2021-07-03 01:33:34 +02:00
Lukas Wirth
251f0c6090 replace_match_with_if_let works on more binary matches 2021-07-02 21:05:10 +02:00
bors[bot]
d18cfd4467
Merge #9458
9458: minor: Remove make::match_arm_with_guard r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:47:38 +00:00
Lukas Wirth
071ac48b6c Remove make::match_arm_with_guard 2021-07-02 01:44:54 +02:00
bors[bot]
cd3d633850
Merge #9455
9455: feat: Handle not let if expressions in replace_if_let_with_match r=Veykril a=Veykril

Transforms bare `if cond {}` into `_ if cond` guard patterns in the match as long as at least one `if let` is in the if chain, otherwise the assist wont be applicable.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:00:50 +00:00
Lukas Wirth
8967856d78 Handle not let if expressions in replace_if_let_with_match 2021-07-02 00:58:56 +02:00
bors[bot]
c8c4d73648
Merge #9437
9437: fix: Don't classify paths inside attribute TokenTrees r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-30 19:52:03 +00:00
Lukas Wirth
04f1104179 Don't classify NameRef paths inside attribute TokenTrees 2021-06-30 21:51:28 +02:00
kjeremy
bf7651886e Cargo update and pull in the new rowan
This brings in the new hashbrown for better compile times.
2021-06-30 10:03:31 -04:00
Lukas Wirth
9957220dfe Fix NameRef::classify path resolution inside attributes 2021-06-28 19:07:23 +02:00
Lukas Wirth
3ce5c66ca1 Deduplicate ast expression walking logic 2021-06-27 01:11:57 +02:00
bors[bot]
e2ca2325f5
Merge #9367
9367: Document perf characteristic of to_node r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-06-22 08:46:01 +00:00
Aleksey Kladov
e611c6758c Document perf characteristic of to_node 2021-06-22 11:45:22 +03:00
Aleksey Kladov
099b63e7c0 feature: massively improve performance for large files
This story begins in #8384, where we added a smart test for our syntax
highting, which run the algorithm on synthetic files of varying length
in order to guesstimate if the complexity is O(N^2) or O(N)-ish.

The test turned out to be pretty effective, and flagged #9031 as a
change that makes syntax highlighting accidentally quadratic. There was
much rejoicing, for the time being.

Then, lnicola asked an ominous question[1]: "Are we sure that the time
is linear right now?"

Of course it turned out that our sophisticated non-linearity detector
*was* broken, and that our syntax highlighting *was* quadratic.

Investigating that, many brave hearts dug deeper and deeper into the
guts of rust-analyzer, only to get lost in a maze of traits delegating
to traits delegating to macros.

Eventually, matklad managed to peel off all layers of abstraction one by
one, until almost nothing was left. In fact, the issue was discovered in
the very foundation of the rust-analyzer -- in the syntax trees.

Worse, it was not a new problem, but rather a well-know, well-understood
and event (almost) well-fixed (!) performance bug.

The problem lies within `SyntaxNodePtr` type -- a light-weight "address"
of a node in a syntax tree [3]. Such pointers are used by rust-analyzer all
other the place to record relationships between IR nodes and the
original syntax.

Internally, the pointer to a syntax node is represented by node's range.
To "dereference" the pointer, you traverse the syntax tree from the
root, looking for the node with the right range. The inner loop of this
search is finding a node's child whose range contains the specified
range. This inner loop was implemented by naive linear search over all
the children. For wide trees, dereferencing a single `SyntaxNodePtr` was
linear. The problem with wide trees though is that they contain a lot of
nodes! And dereferencing pointers to all the nodes is quadratic in the
size of the file!

The solution to this problem is to speed up the children search --
rather than doing a linear lookup, we can use binary search to locate
the child with the desired interval.

Doing this optimization was one of the motivations (or rather, side
effects) of #6857. That's why `rowan` grew the useful
`child_or_token_at_range` method which does exactly this binary search.

But looks like we've never actually switch to this method? Oups.

Lesson learned: do not leave broken windows in the fundamental infra.
Otherwise, you'll have to repeatedly re-investigate the issue, by
digging from the top of the Everest down to the foundation!

[1]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/.60syntax_highlighting_not_quadratic.60.20failure/near/240811501
[2]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Syntax.20highlighting.20is.20quadratic
[3]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Syntax.20highlighting.20is.20quadratic/near/243412392
2021-06-21 20:14:38 +03:00
Lukas Wirth
344cb5e76a Don't insert imports outside of cfg attributed items 2021-06-18 23:56:43 +02:00
Lukas Wirth
2ee090faaf Allow to disable import insertion on single path glob imports 2021-06-18 23:11:56 +02:00
Lukas Wirth
02d25ab60d Fix parser tests for 1.53 2021-06-17 18:09:44 +02:00
Lukas Wirth
cd5f4121e3 Create modules in correct directory for nested modules in move_module assist 2021-06-17 12:09:28 +02:00
Lukas Wirth
29054e02fb Highlight unsafe trait refs as unsafe only in impl blocks and definitions 2021-06-15 21:49:59 +02:00
Aleksey Kladov
067e97d149 internal: enforce no #[ignore] and no #[should_panic] 2021-06-15 16:54:43 +03:00
Maan2003
b857a5dcf0
clippy::manual_str_repeat 2021-06-13 09:37:28 +05:30
Maan2003
c9b4ac5be4
clippy::redudant_borrow 2021-06-13 09:24:16 +05:30
Aleksey Kladov
0463d76a1f internal: cross-crate cov-marks 2021-06-12 23:40:52 +03:00
Jonas Schievink
1d6eef1350 Update ungrammar 2021-06-11 18:34:30 +02:00
Lukas Wirth
31aad2528f Fix edge case for ImportGranularity guessing 2021-06-08 22:14:30 +02:00
Clemens Wasser
629e8d1ed0 Apply more clippy suggestions and update generated 2021-06-03 12:46:56 +02:00
Lukas Wirth
f3dc4321c8 Account for generics in extract_struct_from_enum_variant 2021-06-02 17:44:00 +02:00
Aleksey Kladov
ee51bf04be minor: remove debug print 2021-05-31 20:20:30 +03:00
bors[bot]
f41b68637a
Merge #9062
9062: internal: Bump deps r=lnicola a=lnicola

Fixes #9061

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-30 11:48:59 +00:00
Laurențiu Nicola
36567eb9be Bump deps 2021-05-30 14:48:10 +03:00
Lukas Wirth
fc37e2f953 Attribute completion is context aware 2021-05-27 23:28:14 +02:00
Domantas Jadenkus
22e5194396 generate match arms with todo!() as placeholder body 2021-05-24 22:17:16 +03:00
Laurențiu Nicola
b43bc61981 Bump rustc_lexer 2021-05-24 16:39:19 +03:00
Aleksey Kladov
188b0f96f9 Add more docs 2021-05-22 16:53:47 +03:00
Aleksey Kladov
47d7434dde internal: replace AstTransformer with mutable syntax trees 2021-05-22 15:27:32 +03:00
Lukas Tobias Wirth
da7f1eb756 Don't compare ast::Visibility by stringifying 2021-05-20 17:45:59 +02:00
Aleksey Kladov
75a0123614 fix: don't add extra whitespace around fields
closes #8785
2021-05-17 12:45:01 +03:00
Aleksey Kladov
1859df37fd internal: use mutable syntax trees when filling fields 2021-05-16 18:10:56 +03:00
Aleksey Kladov
e4a7b44e55 internal: use mutable trees when filling match arms 2021-05-16 15:10:18 +03:00
bors[bot]
a57bd59f35
Merge #8813
8813: Get some more array lengths! r=lf- a=lf-

This is built on #8799 and thus contains its changes. I'll rebase it onto master when that one gets merged. It adds support for r-a understanding the length of:

* `let a: [u8; 2] = ...`
* `let a = b"aaa"`
* `let a = [0u8; 4]`

I have added support for getting the values of byte strings, which was not previously there. I am least confident in the correctness of this part and it probably needs some more tests, as we currently have only one test that exercised that part (!).

Fixes #2922.

Co-authored-by: Jade <software@lfcode.ca>
2021-05-16 01:53:12 +00:00
Lukas Wirth
4b5b54279a Attach comments to ast::Impl 2021-05-15 17:32:28 +02:00
Aleksey Kladov
883dd1568f internal: use more mutable APIs 2021-05-14 20:00:35 +03:00
Aleksey Kladov
cea589b3b5 internal: rewrite assoc item manipulaion to use mutable trees 2021-05-14 18:47:08 +03:00
Aleksey Kladov
73123a7550 internal: remove SyntaxRewriter 2021-05-14 16:40:11 +03:00
Aleksey Kladov
873717190d internal: remove more of the SyntaxRewriter 2021-05-14 16:28:59 +03:00
Aleksey Kladov
0650f77dd9 internal: remove one more immutable tree 2021-05-14 16:19:27 +03:00
Aleksey Kladov
ad0648dc95 Cleanup imports 2021-05-13 13:44:47 +03:00
Jade
73023c0299 Support length for ByteStrings
I am not confident that my added byte string parsing is right.
2021-05-12 21:22:46 -07:00
Aleksey Kladov
bf26e13cd2 simplify 2021-05-10 15:25:56 +03:00
Aleksey Kladov
4f3c0adc5a internal: introduce ast::make::ext module with common shortcuts
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.
2021-05-09 19:55:43 +03:00
Aleksey Kladov
680a0d54e4 internal: fix make API 2021-05-09 19:22:33 +03:00
Aleksey Kladov
5342800147 internal: rewrite **Repalce impl Trait** assist to mutable syntax trees 2021-05-09 18:20:37 +03:00
Aleksey Kladov
d9c9f6dc2c cleanups 2021-05-09 17:58:03 +03:00
Aleksey Kladov
8a7904127d minor: remove dead code 2021-05-08 23:28:36 +03:00
Aleksey Kladov
1755b57e1a internal: pull_assignment_up uses mutable trees 2021-05-08 23:11:42 +03:00
Aleksey Kladov
880ddddfe6 dead code 2021-05-08 20:02:48 +03:00
Aleksey Kladov
1fdc9d8e9e internal: remove one more syntax rewriter 2021-05-08 14:47:14 +03:00
Jonas Schievink
e2b664e9fd fix: use raw idents in make::name{_ref} with keywords 2021-05-07 17:22:54 +02:00
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
bors[bot]
63bbdb31e5
Merge #6897
6897: Basic support for macros 2.0 r=jonas-schievink a=jonas-schievink

This adds support for (built-in-only) macros 2.0, and removes some hacks used for builtin derives, which are declared via macros 2.0 in libcore.

First steps for https://github.com/rust-analyzer/rust-analyzer/issues/2248.

Blocked on https://github.com/rust-analyzer/ungrammar/pull/16.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-12-16 16:52:46 +00:00
Lukas Wirth
dd496223f5 Node-ify lifetimes 2020-12-16 14:16:09 +01:00
bors[bot]
ece626fe81
Merge #6894
6894: Parenthesize composite if condition before inverting in invert-if assist r=matklad a=Jesse-Bakker

Fixes #6867

Co-authored-by: Jesse Bakker <github@jessebakker.com>
2020-12-16 08:20:11 +00:00
Jonas Schievink
c31c3246a8 Basic support for decl macros 2.0 2020-12-15 18:43:34 +01:00
Jesse Bakker
0f42a71806 Parenthesize composite if condition before inverting in invert-if assist 2020-12-15 16:25:57 +01:00
Jonas Schievink
479babf874 Reject visibilities on macro_rules! 2020-12-15 15:37:49 +01:00
Jonas Schievink
c1cb595382 Move to upstream macro_rules! model 2020-12-15 15:37:37 +01:00
Jeremy Kolb
26a1675764 Remove some redundant allocations 2020-12-12 12:27:09 -05:00
Aleksey Kladov
3d5be5ba5b Fix accidently quadratic syntax rewriter
Switching from SyntaxNode to GreenNode is a costly operation (b/c
dereferencing a synax ptr in `with_green` is linear), so we should
avoid that.
2020-12-10 20:07:37 +03:00
Lukas Wirth
f8823e8cbc Properly fetch inner and outer docs on hir-level 2020-12-09 09:22:41 +01:00
Lukas Wirth
3174e941db Simplify ast::Comment api surface 2020-12-08 14:15:41 +01:00
Lukas Wirth
b064f6da9e Keep doc attribute order 2020-12-07 20:38:28 +01:00
bors[bot]
03b886de53
Merge #6719
6719: Use items can also have doc comments r=matklad a=Veykril

Prior to this change modules show more docs than they have cause they inherit the docs from documented use items inside of them.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-07 18:48:35 +00:00
Lukas Wirth
44c76d6550 Add replace_match_with_if_let assist 2020-12-05 15:41:36 +01:00
Lukas Wirth
a1c8bdecfd Use items can also have doc comments 2020-12-04 17:09:40 +01:00
bors[bot]
dc09d97fb2
Merge #6649
6649: Accept more than just the standard rust literal suffixes in *Number::suffix r=matklad a=Veykril

I am not entirely sure whether to keep or remove the `SUFFIXES` but I figured we can always bring them back once they are needed.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-02 13:13:01 +00:00
kjeremy
0a95201243 bump lexer 2020-11-30 09:29:09 -05:00
Lukas Wirth
49fbfffb48 Add ast::*Number::suffix tests unit tests 2020-11-28 16:22:28 +01:00
Kirill Bulatov
b2e6ca46ca Profile completions better 2020-11-27 18:00:03 +02:00
Lukas Wirth
347da74eda Avoid allocation in ast::String::value if the string needs no unescaping 2020-11-27 12:03:58 +01:00
Lukas Wirth
931493e949 Accept more than just the standard rust literal suffixes in *Number::suffix 2020-11-27 00:00:18 +01:00
David Tolnay
8a11da40a7
Parse unsafe extern block 2020-11-22 20:44:56 -08:00
bors[bot]
e17d604888
Merge #6558
6558: format string highlighting: handle hex + debug type specifier r=matklad a=ruabmbua

Should fix https://github.com/rust-analyzer/rust-analyzer/issues/6427


Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-11-16 11:07:29 +00:00
Roland Ruckerbauer
a15dda48c6 format string highlighting: handle hex + debug type specifier 2020-11-15 17:43:14 +01:00
Lukas Wirth
e55a44a831 Use shorthand record syntax when renaming struct initializer field 2020-11-14 17:51:09 +01:00
Aleksey Kladov
a27186636d Fix attachment of inner doc comments 2020-11-12 12:09:12 +01:00
Aleksey Kladov
81ac99f60a Simplify code 2020-11-12 11:45:18 +01:00
kjeremy
3b9d164043 Update crates 2020-11-11 11:17:48 -05:00
bors[bot]
ada5a88f8f
Merge #6512
6512: Don't replace parent node when inserting as first child in algo::diff r=SomeoneToIgnore a=Veykril

This makes the diff a bit more detailed.

See https://github.com/rust-analyzer/rust-analyzer/pull/6287#issuecomment-723889267 for context
cc @SomeoneToIgnore 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-09 23:41:43 +00:00
Lukas Wirth
a61bb4abb5 Don't replace parent node when inserting as first child in algo::diff 2020-11-09 20:10:49 +01:00
Aleksey Kladov
e72cd4600e Fix debug for SyntaxRewriter 2020-11-09 14:09:49 +01:00
bors[bot]
dac7060382
Merge #6476
6476: Add missing AssocItems in add_custom_impl assist r=matklad a=Veykril

```rust
use std::fmt;

#[derive(Debu<|>g)]
struct Foo {
    bar: String,
}
```
->
```rust
use std::fmt;

struct Foo {
    bar: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        ${0:todo!()}
    }
}
```

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-07 18:21:11 +00:00
Aleksey Kladov
5db789df9c Cleanup API 2020-11-06 22:52:42 +01:00
Aleksey Kladov
6158304f8b Simplify 2020-11-06 22:30:58 +01:00
Aleksey Kladov
5ba4f949c2 Kill RAW_ literals
Syntactically, they are indistinguishable from non-raw versions, so it
doesn't make sense to separate then *at the syntax* level.
2020-11-06 22:23:14 +01:00
Aleksey Kladov
6725dcf847 Minor, cleanup style 2020-11-06 21:09:37 +01:00
Aleksey Kladov
eb46033390 More orthogonal API 2020-11-06 19:09:01 +01:00
Aleksey Kladov
735aaa7b39 Move int parsing to IntNumber token 2020-11-06 18:54:01 +01:00
Aleksey Kladov
6bcc33e5b7 Better imports 2020-11-06 18:39:09 +01:00
Aleksey Kladov
3820b26a93 Generate token for ints and floats 2020-11-06 18:19:24 +01:00
Lukas Wirth
19443c1fa3 Add missing AssocItems in add_custom_impl assist 2020-11-05 23:41:46 +01:00
bors[bot]
bd6eeffb2f
Merge #6456
6456: Support record variants in extract_struct_from_enum_variant r=matklad a=Veykril

As requested :)

This also prevents the assist from being disabled if a definition in the value namespace exists with the same name as our new struct since that won't cause a collision

#4468

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-04 12:37:29 +00:00
Lukas Wirth
6145234450 Support struct variants in extract_struct_from_enum_variant 2020-11-03 20:57:04 +01:00
bors[bot]
7c94f1cb5e
Merge #6454
6454: Fix overflow panic in convert_interger_literal assist r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-03 18:59:15 +00:00
Aleksey Kladov
9349353e04 Fix overflow panic in convert_interger_literal assist
This also seizes the opportunity to move integer literal parsing to
the syntax crate, were it logically belongs.

Note though that this is still done in an ad hoc manner -- we probably
should split kitchen sink ast::Literal into a separate APIs for
strings, ints, etc
2020-11-03 19:57:57 +01:00
Lukas Wirth
cd349dbbc4 Make insert_use return a SyntaxRewriter 2020-11-02 21:40:52 +01:00
bors[bot]
173e45f872
Merge #6365
6365: Do insertion lookahead in algo::diff r=matklad a=Veykril

This is the last blocker for #6287 after this I can update that PR to properly fix things through using `SyntaxRewriter`.

This PR also shuffles tests around a bit and adds some more.

Ideally this is just a hack until we implement a "proper" diff algorithm that approximates a minimal diff. Maybe something like [gumtree](https://github.com/GumTreeDiff/gumtree)?

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-02 17:47:08 +00:00
kjeremy
0403e82d91 Bump chalk and lexer 2020-11-02 12:00:58 -05:00
Aleksey Kladov
b610118453 Deny unreachable-pub
It's very useful when `pub` is equivalent to "this is crate's public
API", let's enforce this!

Ideally, we should enforce it for local `cargo test`, and only during
CI, but that needs https://github.com/rust-lang/cargo/issues/5034.
2020-11-02 14:07:08 +01:00
Pavan Kumar Sunkara
c070146a83
Update Cargo.toml 2020-10-31 08:49:57 +01:00
Lukas Wirth
750ab54573 Do insertion lookahead in algo::diff 2020-10-26 16:03:37 +01:00
bors[bot]
a0f1346864
Merge #6333
6333: Don't interpret type path as part of visibility. r=matklad a=ArifRoktim

This closes #5902.
I only check that the next token isn't equal to `T![:]`, instead of the next two not being equal to `T![::]`. Is that ok?

Co-authored-by: Arif Roktim <arifrroktim@gmail.com>
2020-10-26 14:34:00 +00:00
bors[bot]
1a84cadc88
Merge #6347
6347: Support insertion in SyntaxRewriter r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-26 14:08:47 +00:00
Lukas Wirth
45860d5207 Remove InsertPos::Before variant in Syntax Rewriter 2020-10-24 21:58:03 +02:00
bors[bot]
bf84e4958e
Merge #6331 #6342
6331: correct hover text for items with doc attribute with raw strings r=matklad a=JoshMcguigan

Fixes #6300 by improving the handling of raw string literals in attribute style doc comments.

This still has a bug where it could consume too many `"` at the start or end of the comment text, just as the original code had. Not sure if we want to fix that as part of this PR or not? If so, I think I'd prefer to add a unit test for either the `as_simple_key_value` function (I'm not exactly sure where this would belong / how to set this up) or create a `fn(&SmolStr) -> &SmolStr` to unit test by factoring out the `trim` operations from `as_simple_key_value`. Thoughts on this? 

6342: Shorter dependency chain r=matklad a=popzxc

Continuing implementing suggestions from the `Completion refactoring` zulip thread.

This PR does the following:

- Removes dependency of `completions` on `assists` by moving required functionality into `ide_db`.
- Moves completely `call_info` crate into `ide_db` as it looks like it fits perfect there.
- Adds a bunch of new tests and docs.
- Adds the re-export of `base_db` to the `ide_db` and removes direct dependency on `base_db` from other crates.

The last point is controversial, I guess, but I noticed that in places where `ide_db` is used, `base_db` is also *always* used. Thus I think the dependency on the `base_db` is implied by the fact of `ide_db` interfaces, and thus it makes sense to just provide `base_db` out of the box.


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
2020-10-24 19:08:12 +00:00
Lukas Wirth
aca2735d1e Support insertion in SyntaxRewriter 2020-10-24 20:53:16 +02:00
Laurențiu Nicola
4834015fd1 Bump rustc_lexer 2020-10-24 17:11:58 +03:00
Arif Roktim
0a9ff04270 Don't interpret type path as part of visibility. 2020-10-24 02:20:45 -04:00
Josh Mcguigan
4e76e884bd correct hover for items with doc attribute with raw strings 2020-10-23 19:36:30 -07:00
Lukas Wirth
0059188e77 algo::diff tests 2020-10-22 14:48:24 +02:00
Lukas Wirth
d86863aeb4 Rewrite algo::diff to support insertion and deletion 2020-10-22 09:51:11 +02:00
bors[bot]
989de9e309
Merge #6172
6172: Add qualify path assist r=matklad a=Veykril

This implements a `qualify_path` assist which works quite similar to the `auto_import` assist but instead of adding imports to the file it well, qualifies the path. This PR also moves out the `AutoImportAssets` struct and functions from `auto_import` into a utils submodule as most of this is now shared between `auto_import` and `qualify_path`.

Changes made to `AutoImportAssets` are solely in its `search_for_imports` function which now takes a prefixed parameter to discern between using `find_use_path_prefixed` and `find_use_path` as the former is the required behavior by `auto_import` and the latter by this assist.

For missing imported traits instead of importing this will qualify the path with a trait cast as in:
```rust
test_mod::TestStruct::TEST_CONST<|>
```
becomes
```rust
<test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST
```

and for trait methods ideally it would do the following:
```rust
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
```
becomes
```rust
let test_struct = test_mod::TestStruct {};
test_mod::TestTrait::test_method(&test_struct)
```

Fixes #4124.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-20 17:03:19 +00:00
Igor Aleksanov
9e7c952bbd Extract call_info and completion into separate crates 2020-10-18 13:09:00 +03:00
Lukas Wirth
bc11475a2a Properly qualify trait methods in qualify_path assist 2020-10-15 18:31:33 +02:00
Laurențiu Nicola
9937c0d50a Bump rustc_lexer 2020-10-13 18:06:23 +03:00
Benjamin Coenen
3bfa3e8123 when generating new function, focus on return type instead of body
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-08 20:57:18 +02:00
kjeremy
13bb0404a8 Bump rustc_lexer, cfg-if to 1.0 and add new license to check 2020-10-08 10:39:02 -04:00
Aleksey Kladov
fd8622e1ec Cleanup 2020-10-07 11:55:20 +02:00
bors[bot]
a184c83535
Merge #6160
6160: Add validation check for ambiguous trait objects r=matklad a=Veykril

Fixes #285.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-07 09:12:09 +00:00
Lukas Wirth
6f38552edb Add validation check for ambiguous trait objects 2020-10-06 23:52:00 +02:00
Aleksey Kladov
d7991f5f21 Document privacy invariant of SyntaxPtr 2020-10-06 20:06:14 +02:00
bors[bot]
e535489f03
Merge #6104
6104: Minor clippy performance suggestions r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-10-02 08:07:42 +00:00
kjeremy
ff678e1349 Up rustc-ap-rustc_lexer to 681
cargo update as well
2020-10-01 15:21:13 -04:00
kjeremy
82d6cfd495 Minor clippy performance suggestions 2020-09-30 15:22:49 -04:00
bors[bot]
18c62c8a39
Merge #6019
6019: Remove make::path_from_text r=matklad a=Veykril

This removes the `make::path_from_text` function, which according to a note should've been private. I removed it since it didn't really serve a purpose as it was simply wrapping `make::ast_from_text`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-29 10:29:33 +00:00
Matt Hooper
7d90bb1f47 Rename impl edit method to be more explicit 2020-09-21 10:01:50 +01:00
Matt Hooper
ae7c982421 Add make utility for empty associated item lists 2020-09-21 00:39:17 +01:00
Matt Hooper
4362297a0b Add edit utility for adding an associated item list to a impl def 2020-09-21 00:38:18 +01:00
Lukas Wirth
f2ae412ccf Remove make::path_from_text 2020-09-16 21:36:10 +02:00
Lukas Wirth
45298b5d2a Add make::glob_use_tree function to create star-only UseTree 2020-09-16 20:33:08 +02:00
Lukas Wirth
a898752881 Reimplement import merging by making it recursive properly nesting all levels 2020-09-12 19:19:19 +02:00
Pavan Kumar Sunkara
4d97f5f037 Rename record_field_pat to record_pat_field 2020-09-10 18:56:04 +02:00
bors[bot]
0275b08d15
Merge #5940
5940: Implement "Replace `impl Trait` function argument with the named generic" assist. r=matklad a=alekseysidorov

Fixes #5085 

Co-authored-by: Aleksei Sidorov <gorthauer87@yandex.ru>
2020-09-04 21:54:42 +00:00
Aleksei Sidorov
e1b8d836a9 Remove unnecessary comma 2020-09-04 22:58:50 +03:00
Aleksei Sidorov
ef0a1b2e58 Fix tests 2020-09-04 17:55:27 +03:00
Aleksei Sidorov
477fa75cfb Fix nitpicks 2020-09-04 15:24:36 +03:00