Commit Graph

15103 Commits

Author SHA1 Message Date
Aleksey Kladov
2cb4ac9eb4 Prepare for utf-8 offsets 2021-02-16 19:17:32 +03:00
bors[bot]
cc49502ab4
Merge #7695
7695: Bump lsp-types r=matklad a=kjeremy

Nothing to see here...

Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-02-16 14:32:33 +00:00
kjeremy
88a5e1d036 Bump lsp-types 2021-02-16 09:21:07 -05: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
bors[bot]
00d5a9563a
Merge #7685
7685: cargo update r=kjeremy a=kjeremy

Removes redundant redox_syscall

Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-02-15 14:50:49 +00:00
kjeremy
2cb0544c20 cargo update 2021-02-15 09:49:36 -05:00
bors[bot]
3142814fe3
Merge #7684
7684: Actually fix runnable order r=lnicola a=ivan770

Changes
![image](https://user-images.githubusercontent.com/14003886/107956771-51a6b200-6fa8-11eb-91aa-f4190d6a8ccd.png)
to
![image](https://user-images.githubusercontent.com/14003886/107956926-903c6c80-6fa8-11eb-8fb9-8bf7bb1879ac.png)

Sorry for missing this one in original PR. This was an issue before ee049b256a, and I fixed it, yet *somehow* order got reversed (to a logical one)

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-02-15 14:22:33 +00:00
ivan770
66de90b85a
Actually fix runnable order 2021-02-15 16:09:50 +02:00
bors[bot]
7435b9e98c
Merge #7661
7661: Start LSP 3.17 support r=kjeremy a=kjeremy

Companion to https://github.com/gluon-lang/lsp-types/pull/199 which <strike>has not been merged yet</strike>  has been merged.

This doesn't opt into any 3.17 functionality yet.

Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2021-02-14 19:52:38 +00:00
Jeremy Kolb
8105418b25 Start LSP 3.17 support 2021-02-14 14:51:29 -05:00
bors[bot]
a0fa585515
Merge #7678
7678: Simplify find_crlf r=matklad a=michalmuskala

This is both simpler to read and compiles to better code: https://rust.godbolt.org/z/MxKodv

Co-authored-by: Michał Muskała <michal@muskala.eu>
2021-02-14 19:28:14 +00:00
Michał Muskała
e640fa967c Simplify find_crlf
This is both simpler to read and compiles to better code:
https://rust.godbolt.org/z/MxKodv
2021-02-14 20:20:14 +01:00
bors[bot]
425c56aa52
Merge #7676
7676: Make it clear which client-side commands we use r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-02-14 16:40:44 +00:00
Aleksey Kladov
9852537809 Make it clear which client-side commands we use 2021-02-14 19:36:44 +03:00
bors[bot]
a0322defc3
Merge #7656
7656: Implement constructor usage search for almost all items r=matklad a=Veykril

This PR moves the filering for enum constructors to the HIR, with this unprefixed variants as well as when the enum has been renamed via use will then still show up properly.
We now walk the ast of the `NameRef` up until we find a `PathExpr`(which also handles `CallExpr` for tuple-type structs and variants already) or a `RecordExpr`. For enum search we then take the `path` out of that expression and do a resolution on it to compare it with the definition enum.
With this PR we now support searching for all constructor literals, Unit-, Tuple- and Record-Structs, Unit-, Tuple- and Record-Variants as well as Unions.

There is one shortcoming due to how the search is triggered. Unit Variants constructors can't be searched as we have no position for it to kick off the search(since a comma doesn't have to exist for the last variant).

Closes #2549 though it doesn't implement it as outlined in the issue since the reference kind was removed recently, though I believe the approach taken here is better personally.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 16:17:03 +00:00
bors[bot]
d50a37d3aa
Merge #7643 #7663
7643: Automatically detect the rustc-src directory (fixes #3517) r=matklad a=bnjbvr

If the configured rustcSource was not set, then try to automatically
detect a source for the sysroot rustc directory.

I wasn't sure how to do it in the case of the project.json file, though.

7663: Tolerate spaces in nix binary patching r=matklad a=CertainLach

If path to original file contains space (I.e on code insiders, where
default data directory is ~/Code - Insiders/), then there is syntax
error evaluating src arg.

Instead pass path as str, and coerce to path back in nix expression

Co-authored-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Yaroslav Bolyukin <iam@lach.pw>
2021-02-14 15:42:07 +00:00
bors[bot]
63c5c92856
Merge #7668
7668: Finalize rename infra rewrite r=matklad a=Veykril

This should be the final PR in regards to rewriting rename stuff, #4290.

It addresses 3 things:
	- Currently renaming import aliases causes some undesired behavior(see #5198) which is why this PR causes us to just return an error if an attempt at renaming an alias is made for the time being. Though this only prevents it from happening when the alias import is renamed, so its not too helpful.
	- Fixes #6898
	- If we are inside a macro file simply rename the input name node as there isn't really a way to do any of the fancy shorthand renames and similar things as for that we would have to exactly know what the macro generates and what not.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 15:29:00 +00:00
Lukas Wirth
7b64622780 Don't rename field record patterns directly 2021-02-13 23:47:21 +01:00
bors[bot]
8638bcbfe7
Merge #7667
7667: strip type parameter defaults when generating impl generics r=Veykril a=jDomantas

Fixes #5666

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-02-13 22:46:37 +00:00
Domantas Jadenkus
150ed80c51 strip type parameter defaults when generating impl generics 2021-02-13 23:59:51 +02:00
bors[bot]
84c9970db5
Merge #7664
7664: refactor impl generation in assists r=Veykril a=jDomantas

Follow-up to #7659: all impl generation in assists (at least what I found) is now done through `utils::{generate_impl_text, generate_trait_impl_text}`.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-02-13 21:37:35 +00:00
bors[bot]
7f751d6413
Merge #7665
7665: Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute r=Veykril a=Veykril

bors r+
Closes #6389

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-13 21:12:49 +00:00
Lukas Wirth
403a63d2b4 Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute 2021-02-13 22:11:31 +01:00
Domantas Jadenkus
7f100fff92 cargo fmt 2021-02-13 22:51:48 +02:00
Domantas Jadenkus
36e8a55bee use generate_impl_text in replace_derive_with_manual_impl 2021-02-13 22:51:07 +02:00
Domantas Jadenkus
3364ac8b11 use generate_impl_text in generate_impl 2021-02-13 22:45:22 +02:00
Lukas Wirth
9b04506924 Fallback to renaming input NameRef node for macros when inside macro 2021-02-13 21:41:04 +01:00
Domantas Jadenkus
ff7ea7c308 use generate_impl_text in generate_from_impl 2021-02-13 22:27:57 +02:00
Yaroslav Bolyukin
471795b019
fix: tolerate spaces in nix binary patching
If path to original file contains space (I.e on code insiders, where
default data directory is ~/Code - Insiders/), then there is syntax
error evaluating src arg.

Instead pass path as str, and coerce to path back in nix expression

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
2021-02-13 23:11:00 +03:00
Lukas Wirth
1901172841 Prevent aliases from being renamed for now 2021-02-13 20:49:04 +01:00
Vladyslav Katasonov
37a8cec638 expose hir::Type::type_paramters
Used to get E parameter from `Result<T, E>`
2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
4be260d693 allow try expr? with return None in extracted function 2021-02-13 22:04:52 +03: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
Vladyslav Katasonov
0ad3d7938f migrate body span to {parent,text_range}
This simplifies api as we are not duplicating code from syntax crate
2021-02-13 22:04:52 +03:00
bors[bot]
3fdc556632
Merge #7662
7662: Group generate getter/setter assist r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-13 18:59:52 +00:00
Lukas Wirth
ed1f2b58f7 Group generate getter/setter assist 2021-02-13 19:58:58 +01:00
bors[bot]
205e72f34d
Merge #7596
7596: Move CodeLens to ide crate r=ivan770 a=ivan770

Closes #7579

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-02-13 17:50:55 +00:00
ivan770
13e9d9809a
Remove CodeLensResolveData mention from lsp-extensions.md 2021-02-13 19:36:29 +02:00
Benjamin Bouvier
4a6e602c94 Allow automatically detect the rustc-src directory (fixes #3517).
If the configured rustcSource is set to "discover", try to automatically
detect a source from the sysroot rustc directory.
2021-02-13 18:20:46 +01:00
ivan770
4c2b201b7d
Make annotations tests similar to those in runnables 2021-02-13 19:18:13 +02:00
Lukas Wirth
8ac6041bcf Only use HIR when searching for enum constructors, otherwise fall back to AST 2021-02-13 17:57:14 +01:00
bors[bot]
2967e783ac
Merge #7659
7659: Improve "Generate From impl" r=Veykril a=jDomantas

* Allows any field type. Previously it was restricted to path types, but I don't see why it couldn't apply to all other types too. (the main reason for is PR is that I'm too lazy to write out `From<&'static str>` by hand 😄)
* More correct handling for generic enums - previously it wouldn't emit generic params on the impl.
* Also accepts variants with named field.

The impl generation code got mostly copy-pasted from generate_impl assist - please tell if there's an easy way to avoid this duplication.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-02-13 15:56:17 +00:00
ivan770
ee049b256a
Improve runnable annotations order, fix incorrect ignore detection 2021-02-13 15:47:53 +02:00
Domantas Jadenkus
b07f530e3a cargo fmt 2021-02-13 15:34:40 +02:00
ivan770
c46b32c449
Added annotation tests 2021-02-13 15:27:04 +02:00
Domantas Jadenkus
375c13cd44 make it work for record-style variants 2021-02-13 14:57:06 +02:00
Domantas Jadenkus
6799088579 update doc 2021-02-13 14:46:41 +02:00