Commit Graph

5738 Commits

Author SHA1 Message Date
Aleksey Kladov
b1cf95f691 Generalize call parenthesis insertion 2020-04-03 21:01:18 +02:00
Aleksey Kladov
adbcedde18 Remove the second code-path for completing names in patterns 2020-04-03 21:00:15 +02:00
Aleksey Kladov
da8eb29a2f Macro patterns are not confused with expressions.
We treat macro calls as expressions (there's appropriate Into impl),
which causes problem if there's expresison and non-expression macro in
the same node (like in the match arm).

We fix this problem by nesting macor patterns into another node (the
same way we nest path into PathExpr or PathPat). Ideally, we probably
should add a similar nesting for macro expressions, but that needs
some careful thinking about macros in blocks: `{ am_i_expression!() }`.
2020-04-03 16:12:38 +02:00
Aleksey Kladov
0e46ed8420 Cleanups 2020-04-03 15:44:06 +02:00
Edwin Cheng
9a2114b0dd Add doc comment on main.rs 2020-04-03 19:16:54 +08:00
Edwin Cheng
84fb9b44c3 Introduce ra_proc_macro_srv 2020-04-03 19:01:44 +08:00
bors[bot]
77462bba62
Merge #3746
3746: Add create_function assist r=flodiebold a=TimoFreiberg

The function part of #3639, creating methods will come later

- [X] Function arguments
     - [X] Function call arguments
     - [x] Method call arguments
     - [x] Literal arguments
     - [x] Variable reference arguments
- [X] Migrate to `ast::make` API
    Done, but there are some ugly spots.

Issues to handle in another PR:
- function reference arguments: Their type isn't printed properly right now.
    The "insert explicit type" assist has the same issue and this is probably a relatively rare usecase.

- generating proper names for all kinds of argument expressions (if, loop, ...?)
    Without this, it's totally possible for the assist to generate invalid argument names.
    I think the assist it's already helpful enough to be shipped as it is, at least for me the main usecase involves passing in named references.
    Besides, the Rust tooling ecosystem is immature enough that some janky behaviour in a new assist probably won't scare anyone off.

- select the generated placeholder body so it's a bit easier to overwrite it

- create method (`self.foo<|>(..)` or `some_foo.foo<|>(..)`) instead of create_function.
    The main difference would be finding (or creating) the impl block and inserting the `self` argument correctly

- more specific default arg names for literals.
    So far, every generated argument whose name can't be taken from the call site is called `arg` (with a number suffix if necessary).

- creating functions in another module of the same crate.
    E.g. when typing `some_mod::foo<|>(...)` when in `lib.rs`, I'd want to have `foo` generated in `some_mod.rs` and jump there.
    Issues: the mod could exist in `some_mod.rs`, in `lib.rs` as `mod some_mod`, or inside another mod but be imported via `use other_mod::some_mod`.

- refer to arguments of the generated function with a qualified path if the types aren't imported yet
    (alternative: run autoimport. i think starting with a qualified path is cleaner and there's already an assist to replace a qualified path with an import and an unqualified path)

- add type arguments of the arguments to the generated function

- Autocomplete functions with information from unresolved calls (see https://github.com/rust-analyzer/rust-analyzer/pull/3746#issuecomment-605281323)
    Issues: see https://github.com/rust-analyzer/rust-analyzer/pull/3746#issuecomment-605282542. The unresolved call could be anywhere. But just offering this autocompletion for unresolved calls in the same module would already be cool.

Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
2020-04-03 08:23:44 +00:00
bors[bot]
2cee8531c5
Merge #3814
3814: Add impl From for enum variant assist r=flodiebold a=mattyhall

Basically adds a From impl for tuple enum variants with one field. It was recommended to me on the zulip to maybe try using the trait solver, but I had trouble with that as, although it could resolve the trait impl, it couldn't resolve the variable unambiguously in real use. I'm also unsure of how it would work if there were already multiple From impls to resolve - I can't see a way we could get more than one solution to my query.

Fixes #3766

Co-authored-by: Matthew Hall <matthew@quickbeam.me.uk>
2020-04-03 07:46:46 +00:00
veetaha
c0cf60dca2 Apply cargo xtask format 2020-04-02 21:12:28 +03:00
veetaha
6190caeeae Migrate to privacy as per review commets 2020-04-02 21:09:03 +03:00
veetaha
bef899aa78 Less mutability 2020-04-02 21:07:05 +03:00
veetaha
a90401aeed Migrate to iters some more 2020-04-02 21:07:05 +03:00
veetaha
987fb26a5b Migrate to iterators 2020-04-02 21:07:05 +03:00
veetaha
b7d5172f69 Simpify workspace handling 2020-04-02 21:07:05 +03:00
veetaha
4b2bf9cf66 Don't clone where you can copy 2020-04-02 21:07:05 +03:00
Matthew Hall
6a2127be28 Cleanup checking for existing impls in impl From assist
Use the trait solver to check if there's an existing implementation of
From<type_in_enum_variant> for the enum.
2020-04-02 18:42:30 +01:00
bors[bot]
23c4ef5aef
Merge #3811
3811: Add inference for literal and range patterns r=kjeremy a=flodiebold

(cc @JoshMcguigan )

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-04-02 15:14:44 +00:00
Aleksey Kladov
8a788c764f Allow fully overriding check and fmt commands 2020-04-02 14:35:51 +02:00
Aleksey Kladov
7a4ebd2c8d Remove vscode_lldb setting 2020-04-02 12:56:14 +02:00
Aleksey Kladov
e21bf1b2b9 Siplify 2020-04-02 12:50:34 +02:00
Aleksey Kladov
48c58309cc Lean onto default implementation of configs 2020-04-02 12:47:58 +02:00
Aleksey Kladov
e4cf40a152 New config in package.json 2020-04-02 12:27:09 +02:00
Aleksey Kladov
0dde0f92de Reorder fields 2020-04-02 11:33:49 +02:00
bors[bot]
98f7842e40
Merge #3820
3820: Remove old syntax highlighting r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-02 07:55:11 +00:00
Aleksey Kladov
309fc70155 Remove old syntax highlighting 2020-04-02 09:52:27 +02:00
o0Ignition0o
f643b4b5f5 Unique package by name and version.
This commit is a fixup of a bug I introduced by using a PackageId to refer to a crate when its name conflicts with a dependency.
It turns out the package id currently is `name version path` while cargo expects `name:version` as argument.
2020-04-02 09:00:44 +02:00
Matthew Hall
1fee60181f Add impl From for enum variant assist
Basically adds a From impl for tuple enum variants with one field. Added
to cover the fairly common case of implementing your own Error that can
be created from another one, although other use cases exist.
2020-04-01 22:26:41 +01:00
Timo Freiberg
10667753c7 Use ast::make API in add_function assist 2020-04-01 23:06:14 +02:00
Timo Freiberg
e5fc42cbc1 Add create_function assist 2020-04-01 23:06:14 +02:00
Florian Diebold
b392a732d3 Add inference for literal and range patterns 2020-04-01 20:27:47 +02:00
bors[bot]
0a41412ced
Merge #3806
3806: lower bool literal value r=flodiebold a=JoshMcguigan

Following up on #3805, this PR adds the literal value to `ast::LiteralKind` so when we lower we can use the actual value from the source code rather than the default value for the type. Ultimately I plan to use this for exhaustiveness checking in #3706.

I didn't include this in the previous PR because I wasn't sure if it made sense to add this information to `ast::LiteralKind` or provide some other mechanism to get this from `ast::Literal`.

For now I've only implemented this for boolean literals, but I think it could be easily extended to other types. A possible exception to this are string literals, since we may not want to clone around an owned string to hold onto in `ast::LiteralKind`, and it'd be nice to avoid adding a generic lifetime as well. Perhaps we won't ever care about the actual value of a string literal? 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-04-01 17:38:00 +00:00
Aleksey Kladov
1225f719fe Fix pointer syntax 2020-04-01 19:27:45 +02:00
Aleksey Kladov
1ac345a9f6 Centralize defaults 2020-04-01 18:56:47 +02:00
Aleksey Kladov
4936abdd49 Reduce scope of deserialization 2020-04-01 18:51:16 +02:00
Aleksey Kladov
e870cbc23d Centralize client capabilities 2020-04-01 18:46:26 +02:00
Aleksey Kladov
a97e5eb85d Centralize all config 2020-04-01 18:41:43 +02:00
Aleksey Kladov
1e012eb991 Move all config to config 2020-04-01 17:22:56 +02:00
Aleksey Kladov
797cd34c7c Reduce feature flags 2020-04-01 17:00:37 +02:00
bors[bot]
facdf56cf6
Merge #3807
3807: Generalize rustfmt config r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-01 12:34:31 +00:00
Aleksey Kladov
b9bf29019d Move config to config.rs 2020-04-01 14:32:04 +02:00
Aleksey Kladov
6ac9668998 Generalize rustfmt config 2020-04-01 14:26:08 +02:00
bors[bot]
a0cc66475a
Merge #3797
3797: Don't show chaining hints for record literals and unit structs r=matklad a=lnicola

Fixes #3796 

r? @Veetaha

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-04-01 12:18:34 +00:00
Josh Mcguigan
d0b6b2ee2f lower bool literal with the value from source code rather than default bool value 2020-04-01 04:47:41 -07:00
bors[bot]
67351a011b
Merge #3805
3805: lower literal patterns r=JoshMcguigan a=JoshMcguigan

While working on #3706 I discovered literal patterns weren't being lowered. This PR implements that lowering.

Questions for reviewers:

1. This re-uses the existing conversion from `ast::LiteralKind` to `Literal`, but `ast::LiteralKind` doesn't include information about the actual value of the literal, which causes `Literal` to be created with the default value for the type (rather than the actual value in the source code). Am I correct in thinking that we'd eventually want to change things in such a way that we could initialize the `Literal` with the actual literal value? Is there an existing issue for this, or else perhaps I should create one to discuss how it should be implemented? My main question would be whether `ast::LiteralKind` should be extended to hold the actual value, or if we should provide some other way to get that information from `ast::Literal`?
2. I couldn't find tests which directly cover this, but it does seem to work in #3706. Do we have unit tests for this lowering code?
3. I'm not sure why `lit.literal()` returns an `Option`. Is returning a `Pat::Missing` in the `None` case the right thing to do? 
4. I was basically practicing type-system driven development to figure out the transformation from `ast::Pat::LiteralPat` to `Pat::Lit`. I don't have an immediate question here, but I just wanted to ensure this section is looked at closely during review. 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-04-01 11:22:31 +00:00
Josh Mcguigan
a9d0c9b2a4 lower literal patterns 2020-04-01 04:18:46 -07:00
Aleksey Kladov
cc8113dd46 Simplify error handing 2020-04-01 13:14:38 +02:00
Aleksey Kladov
f01846b8ee Generalize Flycheckconfig 2020-04-01 13:14:38 +02:00
bors[bot]
aad0e63d74
Merge #3779
3779: Complete only missing fields in pats r=matklad a=SomeoneToIgnore

A follow-up for https://github.com/rust-analyzer/rust-analyzer/pull/3694

Same name vs string [issue](https://github.com/rust-analyzer/rust-analyzer/pull/3694#discussion_r396986819) persists here, now I'm able to obtain `ast::Name`, but I see no way to convert it into `hir::Name` or vice versa.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-04-01 10:41:46 +00:00
bors[bot]
ab284f30ce
Merge #3803
3803: Cleanup r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-01 10:34:36 +00:00
Aleksey Kladov
65c89c3a20 Cleanup 2020-04-01 12:34:12 +02:00