]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoMerge #7618
bors[bot] [Tue, 9 Feb 2021 20:37:26 +0000 (20:37 +0000)]
Merge #7618

7618: Show qualified variant pattern completions r=Veykril a=Veykril

![UTMZyplssw](https://user-images.githubusercontent.com/3757771/107425157-e9c31800-6b1e-11eb-8963-96653115f8e0.gif)
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoShow qualified variant pattern completions
Lukas Wirth [Tue, 9 Feb 2021 20:32:05 +0000 (21:32 +0100)]
Show qualified variant pattern completions

3 years agoMerge #7616
bors[bot] [Tue, 9 Feb 2021 19:38:39 +0000 (19:38 +0000)]
Merge #7616

7616: Show `Self` pattern and Self-prefixed enum-variant completions r=Veykril a=Veykril

![jDfQXNE0qZ](https://user-images.githubusercontent.com/3757771/107413514-1ff99b00-6b11-11eb-88b3-126cd106b514.gif)
![JpogVIgloq](https://user-images.githubusercontent.com/3757771/107413519-212ac800-6b11-11eb-8282-51115468dccc.gif)

Variant pattern completions are to be done still.

Closes #6549, at least that should address all that's left from that issue from what I can see.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #7615
bors[bot] [Tue, 9 Feb 2021 18:53:27 +0000 (18:53 +0000)]
Merge #7615

7615: Add parsing benchmark r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd parsing benchmark
Aleksey Kladov [Tue, 9 Feb 2021 18:52:34 +0000 (21:52 +0300)]
Add parsing benchmark

3 years agoShow Self pattern completions for Adts if inside impls
Lukas Wirth [Tue, 9 Feb 2021 18:47:21 +0000 (19:47 +0100)]
Show Self pattern completions for Adts if inside impls

3 years agoShow completions for enum variant with self prefix if inside impl
Lukas Wirth [Tue, 9 Feb 2021 18:04:39 +0000 (19:04 +0100)]
Show completions for enum variant with self prefix if inside impl

3 years agoMerge #7614
bors[bot] [Tue, 9 Feb 2021 18:01:04 +0000 (18:01 +0000)]
Merge #7614

7614: Unleash inner item resolution to users r=jonas-schievink a=jonas-schievink

![Peek 2021-02-09 17-30](https://user-images.githubusercontent.com/1786438/107394800-8627f300-6afc-11eb-8662-ed07226bc58f.gif)

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoRemove unneeded return
Jonas Schievink [Tue, 9 Feb 2021 17:40:05 +0000 (18:40 +0100)]
Remove unneeded return

3 years agoMerge #7613
bors[bot] [Tue, 9 Feb 2021 17:35:53 +0000 (17:35 +0000)]
Merge #7613

7613: Benchmarking infrastructure r=matklad a=matklad

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoInfra for "unit" benchmarking
Aleksey Kladov [Tue, 9 Feb 2021 16:29:40 +0000 (19:29 +0300)]
Infra for "unit" benchmarking

3 years agoRemove `pub`
Jonas Schievink [Tue, 9 Feb 2021 16:36:10 +0000 (17:36 +0100)]
Remove `pub`

3 years agoUse `block_def_map` in `Resolver`
Jonas Schievink [Tue, 9 Feb 2021 16:27:04 +0000 (17:27 +0100)]
Use `block_def_map` in `Resolver`

This required a few changes to not bail out immediately if a
`ModuleScope` doesn't resolve a path.

The `LocalItemsScope` hack is now removed.

3 years agoTeach `find_path` about inner items
Jonas Schievink [Tue, 9 Feb 2021 16:25:03 +0000 (17:25 +0100)]
Teach `find_path` about inner items

3 years agoAdd another block def map test
Jonas Schievink [Tue, 9 Feb 2021 16:24:43 +0000 (17:24 +0100)]
Add another block def map test

3 years agoMake `with_ancestor_maps` public
Jonas Schievink [Tue, 9 Feb 2021 16:23:25 +0000 (17:23 +0100)]
Make `with_ancestor_maps` public

3 years agoAdd `TestDB::module_at_position`
Jonas Schievink [Tue, 9 Feb 2021 16:22:57 +0000 (17:22 +0100)]
Add `TestDB::module_at_position`

3 years agoAdd expression scopes for blocks
Jonas Schievink [Tue, 9 Feb 2021 16:11:44 +0000 (17:11 +0100)]
Add expression scopes for blocks

3 years agoMerge #7611
bors[bot] [Tue, 9 Feb 2021 15:30:09 +0000 (15:30 +0000)]
Merge #7611

7611: Cleanups r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agorestore accidentally deleted test
Aleksey Kladov [Tue, 9 Feb 2021 15:29:15 +0000 (18:29 +0300)]
restore accidentally deleted test

3 years agoMore precise navigation to parent
Aleksey Kladov [Tue, 9 Feb 2021 15:21:09 +0000 (18:21 +0300)]
More precise navigation to parent

3 years agoCleanup tests
Aleksey Kladov [Tue, 9 Feb 2021 15:13:11 +0000 (18:13 +0300)]
Cleanup tests

3 years agoMerge #7597
bors[bot] [Tue, 9 Feb 2021 14:58:14 +0000 (14:58 +0000)]
Merge #7597

7597: Set remote branch on xtask promote r=matklad a=lnicola

to hopefully fix this:

```
$ git switch master
Already on 'master'
Your branch is up to date with 'upstream/master'.
$ git fetch upstream
$ git reset --hard upstream/master
HEAD is now at 921ec4b3fca Auto merge of #81313 - LeSeulArtichaut:revert-32558, r=jyn514
$ git submodule update --recursive
Submodule path 'src/tools/rust-analyzer': checked out '1a59f75cdaa730c16a694a4294eccf6dfe6fe0ad'
$ git switch -c rust-analyzer-2021-02-08
Switched to a new branch 'rust-analyzer-2021-02-08'
$ git fetch origin
$ git reset --hard origin/release
HEAD is now at 336909b63 Merge #7587
$ git add src/tools/rust-analyzer
$ git commit "-m:arrow_up: rust-analyzer"
[rust-analyzer-2021-02-08 1774ec1a683] :arrow_up: rust-analyzer
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git push
fatal: The current branch rust-analyzer-2021-02-08 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin rust-analyzer-2021-02-08

Error: command `git push` failed, exit code: 128
```

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
3 years agoTrack remote branch on xtask promote
Laurențiu Nicola [Mon, 8 Feb 2021 14:20:42 +0000 (16:20 +0200)]
Track remote branch on xtask promote

3 years agoMerge #7610
bors[bot] [Tue, 9 Feb 2021 14:49:02 +0000 (14:49 +0000)]
Merge #7610

7610: Cleanup test r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoCleanup test
Aleksey Kladov [Tue, 9 Feb 2021 14:48:25 +0000 (17:48 +0300)]
Cleanup test

3 years agoFix highlighting of injected attributes
Aleksey Kladov [Tue, 9 Feb 2021 14:41:12 +0000 (17:41 +0300)]
Fix highlighting of injected attributes

3 years agoModernize tests
Aleksey Kladov [Tue, 9 Feb 2021 14:23:35 +0000 (17:23 +0300)]
Modernize tests

3 years agoMerge #7602
bors[bot] [Mon, 8 Feb 2021 18:22:35 +0000 (18:22 +0000)]
Merge #7602

7602: Check for dyn impls in method resolution r=flodiebold a=Veykril

Fixes #6777

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoCheck for dyn impls in method resolution
Lukas Wirth [Mon, 8 Feb 2021 18:13:54 +0000 (19:13 +0100)]
Check for dyn impls in method resolution

3 years agoMerge #7600
bors[bot] [Mon, 8 Feb 2021 16:49:45 +0000 (16:49 +0000)]
Merge #7600

7600: Update crates r=flodiebold a=kjeremy

Pulls in https://github.com/rust-lang/chalk/pull/682

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoUpdate crates
kjeremy [Mon, 8 Feb 2021 16:38:51 +0000 (11:38 -0500)]
Update crates

Pulls in https://github.com/rust-lang/chalk/pull/682

3 years agoMerge #7599
bors[bot] [Mon, 8 Feb 2021 16:08:31 +0000 (16:08 +0000)]
Merge #7599

7599: Add emacs guide r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd emacs guide
Aleksey Kladov [Mon, 8 Feb 2021 16:08:02 +0000 (19:08 +0300)]
Add emacs guide

3 years agoMerge #7595
bors[bot] [Mon, 8 Feb 2021 10:34:46 +0000 (10:34 +0000)]
Merge #7595

7595: Add `config: &CargoConfig` parameter to `fn load_cargo(…)` r=matklad a=regexident

For projects using rust-analyzer as a library it is desirable to be able to provide a custom-config to `fn load_cargo(…)` to pass features, etc, rather than having to copy & paste `fn load_cargo(…)` into one's project and maintain a fork of it and keep it in sync with upstream.

Co-authored-by: Vincent Esche <regexident@gmail.com>
3 years agoConsolidate `fn load_cargo(…)` parameters into `struct LoadCargoConfig { … }`
Vincent Esche [Mon, 8 Feb 2021 10:30:16 +0000 (11:30 +0100)]
Consolidate `fn load_cargo(…)` parameters into `struct LoadCargoConfig { … }`

3 years agoAdd `config: &CargoConfig` parameter to `fn load_cargo(…)`
Vincent Esche [Mon, 8 Feb 2021 10:00:55 +0000 (11:00 +0100)]
Add `config: &CargoConfig` parameter to `fn load_cargo(…)`

3 years agoMerge #7592
bors[bot] [Mon, 8 Feb 2021 09:16:01 +0000 (09:16 +0000)]
Merge #7592

7592: [Doc] Note about Eclipse IDE support r=lnicola a=mickaelistria

Co-authored-by: Mickael Istria <mistria@redhat.com>
3 years ago[Doc] Note about Eclipse IDE support
Mickael Istria [Sun, 7 Feb 2021 20:37:22 +0000 (21:37 +0100)]
[Doc] Note about Eclipse IDE support

3 years agoMerge #7593
bors[bot] [Mon, 8 Feb 2021 08:00:41 +0000 (08:00 +0000)]
Merge #7593

7593: fix: add for keyword in completion #7588 r=lnicola a=gowrizrh

Fixes #7588
bors r+

Co-authored-by: Gowri <gowri.sankar@aligent.com.au>
Co-authored-by: Gowri <gowrizrh@gmail.com>
3 years agochore: swap order of placeholders
Gowri [Mon, 8 Feb 2021 07:52:46 +0000 (18:22 +1030)]
chore: swap order of placeholders

3 years agoMerge #7549
bors[bot] [Mon, 8 Feb 2021 04:38:34 +0000 (04:38 +0000)]
Merge #7549

7549:  Documentation: Explain how initial configuration is sent over LSP and document vim-lsp r=ilya-bobyr a=ilya-bobyr

This request contains two related but independent changes.
The first explains `rust-analyzer` initial configuration over LSP.
The second - adds documentation on `vim-lsp` Vim plugin and provides an example of the initial configuration for `rust-analyzer` when using this particular LSP client.

Let me know if you would prefer the changes to be reviewed in two separate pull requests.

Co-authored-by: Ilya Bobyr <ilya.bobyr@gmail.com>
3 years agoVim docs: vim-lsp with initial configuration.
Ilya Bobyr [Thu, 4 Feb 2021 02:49:59 +0000 (18:49 -0800)]
Vim docs: vim-lsp with initial configuration.

`vim-lsp` is another popular LSP client for Vim.  And, as there is no
`rust-analyzer` specific UI, it is non-trivial to figure out how the
initial configuration is performed.

3 years agoExplain how initial configuration is sent over LSP.
Ilya Bobyr [Thu, 4 Feb 2021 02:33:19 +0000 (18:33 -0800)]
Explain how initial configuration is sent over LSP.

3 years agoci: update relevant test case expected values
Gowri [Sun, 7 Feb 2021 23:46:20 +0000 (10:16 +1030)]
ci: update relevant test case expected values

3 years agofix: add for keyword in completion #7588
Gowri [Sun, 7 Feb 2021 23:27:16 +0000 (09:57 +1030)]
fix: add for keyword in completion #7588

3 years agoMerge #7587
bors[bot] [Sun, 7 Feb 2021 11:15:26 +0000 (11:15 +0000)]
Merge #7587

7587: AdtDef -> Adt r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdtDef -> Adt
Aleksey Kladov [Sun, 7 Feb 2021 11:15:02 +0000 (14:15 +0300)]
AdtDef -> Adt

3 years agoMerge #7586
bors[bot] [Sun, 7 Feb 2021 07:59:24 +0000 (07:59 +0000)]
Merge #7586

7586: Add a section on entry points r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd a section on entry points
Aleksey Kladov [Sun, 7 Feb 2021 07:49:45 +0000 (10:49 +0300)]
Add a section on entry points

3 years agoFixing architecture image on dark theme
Erick Tovar [Sat, 6 Feb 2021 20:52:38 +0000 (12:52 -0800)]
Fixing architecture image on dark theme

3 years agoMerge #7585
bors[bot] [Sun, 7 Feb 2021 04:54:31 +0000 (04:54 +0000)]
Merge #7585

7585: More information for mbe in architecture.md r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoRemove redunacny
Edwin Cheng [Sun, 7 Feb 2021 04:53:54 +0000 (12:53 +0800)]
Remove redunacny

3 years agoMore information for mbe
Edwin Cheng [Sun, 7 Feb 2021 04:49:02 +0000 (12:49 +0800)]
More information for mbe

3 years agoMerge #7584
bors[bot] [Sun, 7 Feb 2021 04:33:15 +0000 (04:33 +0000)]
Merge #7584

7584: Update architecture.md for mbe and proc-macro r=edwin0cheng a=edwin0cheng

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoUpdate architecture.md for mbe and proc-macro
Edwin Cheng [Sun, 7 Feb 2021 04:31:33 +0000 (12:31 +0800)]
Update architecture.md for mbe and proc-macro

3 years agoMerge #7583
bors[bot] [Sat, 6 Feb 2021 22:52:42 +0000 (22:52 +0000)]
Merge #7583

7583: Update architecture.md r=bjorn3 a=aTuck

Typo

Co-authored-by: Adam Tuck <tuckaet@gmail.com>
3 years agoUpdate architecture.md
Adam Tuck [Sat, 6 Feb 2021 22:40:23 +0000 (14:40 -0800)]
Update architecture.md

Typo

3 years agoMerge #7578
bors[bot] [Sat, 6 Feb 2021 00:25:23 +0000 (00:25 +0000)]
Merge #7578

7578: Add a semantic token type for char literals r=Veykril a=petr-tik

Fixes #7530

The LSP spec doesn't recognise character literals, so
had to extend the suported types to our own custom type

Co-authored-by: petr-tik <petr-tik@users.noreply.github.com>
3 years agoAdd a semantic token type for char literals
petr-tik [Fri, 5 Feb 2021 23:46:39 +0000 (23:46 +0000)]
Add a semantic token type for char literals

The LSP spec doesn't recognise character literals, so
had to extend the suported types to our own custom type

3 years agoMerge #7577
bors[bot] [Fri, 5 Feb 2021 20:45:52 +0000 (20:45 +0000)]
Merge #7577

7577: cargo update r=kjeremy a=kjeremy

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoMerge #7576
bors[bot] [Fri, 5 Feb 2021 20:35:51 +0000 (20:35 +0000)]
Merge #7576

7576: Fix resolveCodeAction trying to edit files before creating them r=Veykril a=Veykril

Fixes #7208
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agocargo update
kjeremy [Fri, 5 Feb 2021 20:35:45 +0000 (15:35 -0500)]
cargo update

3 years agoFix resolveCodeAction trying to edit files before creating them
Lukas Wirth [Fri, 5 Feb 2021 20:26:14 +0000 (21:26 +0100)]
Fix resolveCodeAction trying to edit files before creating them

3 years agoMerge #7575
bors[bot] [Fri, 5 Feb 2021 18:26:51 +0000 (18:26 +0000)]
Merge #7575

7575: Fix resolution of `self` module within blocks r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoTest `super` resolution too
Jonas Schievink [Fri, 5 Feb 2021 18:25:50 +0000 (19:25 +0100)]
Test `super` resolution too

3 years agoFix resolution of `self` module within blocks
Jonas Schievink [Fri, 5 Feb 2021 18:24:03 +0000 (19:24 +0100)]
Fix resolution of `self` module within blocks

3 years agoMerge #7572
bors[bot] [Fri, 5 Feb 2021 17:18:02 +0000 (17:18 +0000)]
Merge #7572

7572: Add `find_or_create_impl_block` to assist utils r=matklad a=yoshuawuyts

This is another continuation of https://github.com/rust-analyzer/rust-analyzer/pull/7562, introducing a small util to either find an `impl` block, or create a new one if none exists. I copied this code from the `generate_new` assist into https://github.com/rust-analyzer/rust-analyzer/pull/7562, and this unifies both into a helper.

It doesn't feel super polished in its current state, but my hope is that this is enough of a starting point that it can be expanded on later. For example something that would be useful would be a flag which either returns the index of the start of the block, or the end of the block.

Anyway, I hope this is useful. Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoAdd `find_or_create_impl_block` to assist utils
Yoshua Wuyts [Fri, 5 Feb 2021 15:32:34 +0000 (16:32 +0100)]
Add `find_or_create_impl_block` to assist utils

3 years agoMerge #7573
bors[bot] [Fri, 5 Feb 2021 16:14:55 +0000 (16:14 +0000)]
Merge #7573

7573: Do not overwrite lock file r=kjeremy a=kjeremy

Use `npm ci` instead of `npm install`. `npm install` will overwrite
the lock file if you have a newer npm version than the one that
generated the package-lock.json

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoMerge #7574
bors[bot] [Fri, 5 Feb 2021 16:04:50 +0000 (16:04 +0000)]
Merge #7574

7574: Remove various redundant clones r=kjeremy a=yoshuawuyts

I noticed when running clippy through RA that there are a few instances where `clone` is called where it's not actually needed. I figured a small patch to remove these might be welcome here.

Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoDo not overwrite lock file
kjeremy [Fri, 5 Feb 2021 15:57:36 +0000 (10:57 -0500)]
Do not overwrite lock file

Use `npm ci` instead of `npm install`. `npm install` will overwrite
the lock file if you have a newer npm version than the one that
generated the package-lock.json

3 years agoRemove redundant clones
Yoshua Wuyts [Fri, 5 Feb 2021 15:57:26 +0000 (16:57 +0100)]
Remove redundant clones

3 years agoMerge #7505
bors[bot] [Fri, 5 Feb 2021 15:31:25 +0000 (15:31 +0000)]
Merge #7505

7505: Widen Highlights root range to covering element r=Veykril a=Veykril

There have been a few issues about/containing spurious syntax highlighting panics, which all seem to come from the `rust_analyzer::handlers::handle_semantic_tokens_range` request, which I believe this to be the cause of as the text range we want to highlight here is currently potentially smaller than that of the covering element, so we might highlight something that is inside the covering element, but outside of the text range we wish to highlight causing the assert to fail.
Unfortunately this isn't really easy to test since I have yet to find a reproducible cause(#7504 doesn't work for me cause I can't seem to checkout the given commit).

See #7504, #7298, #7299 and #7416, all of those contain an assertion failure in syntax highlighting, but only in the range request.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #7570 #7571
bors[bot] [Fri, 5 Feb 2021 15:17:41 +0000 (15:17 +0000)]
Merge #7570 #7571

7570: Add doc gen to the `generate_enum_match_method` assist r=yoshuawuyts a=yoshuawuyts

Implements a small extension to https://github.com/rust-analyzer/rust-analyzer/pull/7562, generating default comments. I wasn't sure if this would fit the goals of Rust-Analyzer, so I chose to split it into a separate PR. This is especially useful when writing code in a codebase which uses `#![warn(missing_docs)]` lint, as many production-grade libraries do.

The comments we're generating here are similar to the ones found on [`Option::is_some`](https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some) and [`Result::is_err`](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err). I briefly considered only generating these for `pub` types, but they seem small and unobtrusive enough that they're probably useful in the general case. Thanks!

## Example

__input__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```

__output__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    /// Returns `true` if the variant is [`Minor`].
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

This opens up the path to adding an assist for generating these comments on existing `is_` methods. This would make it both easy to document new code, and update existing code with documentation.

7571: Cleanup decl_check r=Veykril a=Veykril

bors r+

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoCleanup decl_check
Lukas Wirth [Fri, 5 Feb 2021 15:09:45 +0000 (16:09 +0100)]
Cleanup decl_check

3 years agoAdd doc gen to the `generate_enum_match_method` assist
Yoshua Wuyts [Fri, 5 Feb 2021 14:35:24 +0000 (15:35 +0100)]
Add doc gen to the `generate_enum_match_method` assist

3 years agoMerge #7569
bors[bot] [Fri, 5 Feb 2021 14:45:59 +0000 (14:45 +0000)]
Merge #7569

7569: Add howtos r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd howtos
Aleksey Kladov [Fri, 5 Feb 2021 14:44:04 +0000 (17:44 +0300)]
Add howtos

3 years agoMerge #7562
bors[bot] [Fri, 5 Feb 2021 14:28:25 +0000 (14:28 +0000)]
Merge #7562

7562: add `generate_enum_match` assist r=matklad a=yoshuawuyts

This adds a `generate_enum_match` assist, which generates `is_` variants for enums (e.g. `Option::{is_none,is_some}` in std). This is my first attempt at contributing to Rust-Analyzer, so I'm not sure if I've gotten everything right. Thanks!

## Example

**Input**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```
**Output**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

I made this as a stepping stone for some of the more involved refactors (e.g. #5944). I'm not sure yet how to create, use, and test `window.showQuickPick`-based asssists in RA. But once that's possible, it'd probably be nice to be able to generate match methods in bulk through the quickpick UI rather than one-by-one:

```
[x] Select enum members to generate methods for. (3 selected) [ OK ]
---------------------------------------------------------------------------
[x] Undefined
[x] Minor
[x] Major
```

Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoMerge #7568
bors[bot] [Fri, 5 Feb 2021 14:16:12 +0000 (14:16 +0000)]
Merge #7568

7568: Fix merging of `segment_index` in path resolution r=jonas-schievink a=jonas-schievink

This caused associated item lookup to fail when modifying `resolver.rs` to handle block expressions with inner items.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoFix merging of `segment_index` in path resolution
Jonas Schievink [Fri, 5 Feb 2021 14:14:33 +0000 (15:14 +0100)]
Fix merging of `segment_index` in path resolution

3 years agoMerge #7567
bors[bot] [Fri, 5 Feb 2021 14:03:52 +0000 (14:03 +0000)]
Merge #7567

7567: Remove unnecessary allocs in case_conv r=Veykril a=Veykril

and some replace unwraps

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoRemove unnecessary allocs in case_conv
Lukas Wirth [Fri, 5 Feb 2021 14:02:39 +0000 (15:02 +0100)]
Remove unnecessary allocs in case_conv

3 years agoMove `find_struct_impl` to assist utils
Yoshua Wuyts [Fri, 5 Feb 2021 13:36:07 +0000 (14:36 +0100)]
Move `find_struct_impl` to assist utils

3 years agoadd `generate-enum-match` assist
Yoshua Wuyts [Fri, 5 Feb 2021 00:57:39 +0000 (01:57 +0100)]
add `generate-enum-match` assist

3 years agoMerge #7535
bors[bot] [Fri, 5 Feb 2021 02:55:56 +0000 (02:55 +0000)]
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>
3 years agoallow extracted body to be indented(dedent it)
Vladyslav Katasonov [Fri, 5 Feb 2021 02:00:53 +0000 (05:00 +0300)]
allow extracted body to be indented(dedent it)

3 years agoallow transitive `&mut` access for fields in extract_function
Vladyslav Katasonov [Fri, 5 Feb 2021 01:35:41 +0000 (04:35 +0300)]
allow transitive `&mut` access for fields in extract_function

3 years agoadd tests for extracting if/match/while/for exprs
Vladyslav Katasonov [Thu, 4 Feb 2021 23:30:34 +0000 (02:30 +0300)]
add tests for extracting if/match/while/for exprs

3 years agodocument extract_function assist implementation
Vladyslav Katasonov [Thu, 4 Feb 2021 23:14:32 +0000 (02:14 +0300)]
document extract_function assist implementation

3 years agouse `&T` for non copy params of extracted function
Vladyslav Katasonov [Thu, 4 Feb 2021 22:18:45 +0000 (01:18 +0300)]
use `&T` for non copy params of extracted function

Use shared ref if param is not `T: Copy` and is used after body

3 years agoMerge #7561
bors[bot] [Thu, 4 Feb 2021 21:42:57 +0000 (21:42 +0000)]
Merge #7561

7561: Avoid using ModPath's fields directly r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoAvoid using ModPath's fields directly
Jonas Schievink [Thu, 4 Feb 2021 21:42:21 +0000 (22:42 +0100)]
Avoid using ModPath's fields directly

3 years ago split extract_function into pieces and order them
Vladyslav Katasonov [Thu, 4 Feb 2021 21:35:28 +0000 (00:35 +0300)]
 split extract_function into pieces and order them

3 years agoMerge #7559
bors[bot] [Thu, 4 Feb 2021 19:59:21 +0000 (19:59 +0000)]
Merge #7559

7559: Make `ModPath`'s representation private r=jonas-schievink a=jonas-schievink

This lets us switch out the `Vec` for something more efficient

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoMake `ModPath`'s representation private
Jonas Schievink [Thu, 4 Feb 2021 19:49:24 +0000 (20:49 +0100)]
Make `ModPath`'s representation private

3 years agoMerge #7558
bors[bot] [Thu, 4 Feb 2021 19:46:01 +0000 (19:46 +0000)]
Merge #7558

7558: Update thread_local r=kjeremy a=kjeremy

Pulls in https://github.com/Amanieu/thread_local-rs/pull/30 which fixes
a leak when dropping ThreadLocal.

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoUpdate thread_local
kjeremy [Thu, 4 Feb 2021 19:42:45 +0000 (14:42 -0500)]
Update thread_local

Pulls in https://github.com/Amanieu/thread_local-rs/pull/30 which fixes
a leak when dropping ThreadLocal.

3 years agoMerge #7557
bors[bot] [Thu, 4 Feb 2021 18:33:57 +0000 (18:33 +0000)]
Merge #7557

7557: Intern `TypeRef`s in the containing `ItemTree` r=jonas-schievink a=jonas-schievink

This reduces the memory used by `ItemTreeQuery` by ~20%. As it turns out, `TypeRef` is very heavy, and is used a lot in `ItemTree`:

* Many types are frequently repeated throughout the same file. This is what this PR addresses by storing identical `TypeRef`s only once per `ItemTree`.
* The vast majority of `TypeRef` consist of a plain path with only a single element. "Type anchors" like in `<Ty>::func` are used incredibly rarely, and even multi-segment paths are much rarer than single-segment paths.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>