Commit Graph

8495 Commits

Author SHA1 Message Date
bors[bot]
0fb069c5b0
Merge #6216
6216: Bump deps r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-13 15:13:55 +00:00
Laurențiu Nicola
9937c0d50a Bump rustc_lexer 2020-10-13 18:06:23 +03:00
Laurențiu Nicola
017a04f424 Bump crossbeam-channel and lsp-server in rust-analyzer 2020-10-13 18:05:06 +03:00
Laurențiu Nicola
db7813ef2c Bump crossbeam-channel in crates 2020-10-13 16:57:01 +03:00
Lukas Wirth
2620b8d42f Fix MergeBehaviour::Full not working when merging nested long paths 2020-10-13 10:44:16 +02:00
bors[bot]
c518fe7f6c
Merge #6130 #6135
6130: Items case quick fix (snake_case / UPPER_SNAKE_CASE / CamelCase) r=matklad a=popzxc

Resolves #4598.

After a third try, it finally works. Boy, it appeared tougher than it seemed.

Initially I thought like "Ha, `rustc` already tells us where idents are named incorrectly. It shouldn't be that hard, should it?".

Well, the problems with the information provided by `rustc` appeared shortly:

- `rustc` warnings are `flycheck` warnings, which are slightly aside from our diagnostics with fixes.
  When we map flycheck diagnostic to LSP, we can convert it into a fix, but only if it's marked as `Applicability::MachineApplicable`.
  Name case fix is marked `Applicability::MaybeIncorrect`, and for a reason: it only suggest to rename symbol under cursor, without tracking any references.
- Warning spawned by `rustc` are identified by string labels rather than enum. It means that if one day the diagnostic will be renamed in `rustc`, `rust-analyzer` code will still compile, but won't find the required diagnostic by name anymore. If by chance this will happen when some unlucky guy will decide to create their first pull request, they'll be confused by suddenly failing tests  (likely) not related to their changes.
- Even if we'll try to build fixes atop of `rustc` warnings, we'll have to do it in the `rust_analyzer::diagnostics::to_proto` module, which is far less
  convenient for that matter than `ide` crate.

That's why I decided that it's worth a separate `rust-analyzer` diagnostic, which will implement `DiagnosticWithFix` trait.

After that, I discovered that currently `hir_ty::diagnostics` only check `DefWithBody` types, like function bodies. I had to add support for diagnostics
which look at any `ModuleDef`.

And of course, since I'd added a lot of new functionality, it required extensive testing.

That explains why the diff is so big for a (looking) relatively small feature.

I hope that this PR doesn't only add a small feature, but also creates a base for building another features.

## Example:

![case_quick_fix](https://user-images.githubusercontent.com/12111581/95008475-e07ee780-0622-11eb-9978-62a9ea0e7782.gif)

P.S. My eyes were bleeding when I had to write the code for the example...


6135: when generating new function, focus on return type instead of body r=matklad a=bnjjj

I made a little change when we use the assist to generate a new function, instead of focusing on the function body, it will focus on return type

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-12 16:00:13 +00:00
bors[bot]
ef33953c70
Merge #6205
6205: Fix iterator hint shortening heuristic r=SomeoneToIgnore a=Veykril

Turns out I made a mistake with the heuristic check which is always true, so all iterators exposed from `core` were shortened, including things like ranges. 😅 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 15:53:32 +00:00
bors[bot]
05faeb50f3
Merge #6153
6153: Improve prime_caches and display its progress r=matklad a=jonas-schievink

It now computes the `CrateDefMap` of all crates, which is generally a reasonable approximation for "IDE features ready". There is still some delay after this finishes, I suspect mostly due to impl collection, which takes a while, but this should be an improvement already.

For more accurate progress reports, this topologically sorts all crates before starting this operation. ~~Because that is also the ordering in which parallelization makes sense (which was previously attempted in https://github.com/rust-analyzer/rust-analyzer/pull/3529), I decided to throw that into the mix as well. It still doesn't provide *that* much of a performance boost, but it does scale beyond the current single-core architecture, and adding it was very easy.~~

~~Unfortunately, as written, this will not tell the user which crate is actually causing slowdowns, since the displayed crate is the last one that was *started*, not the one we are currently *blocked* on, but that seems fairly difficult to implement unless I'm missing something.~~

(I have removed rayon for now since it does not work correctly with cancellation.)

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-10-12 15:21:39 +00:00
Lukas Wirth
ed59512d02 Fix iterator hint shortening heuristic 2020-10-12 17:18:21 +02:00
bors[bot]
fac59f4f28
Merge #6195
6195: Shorten iterators in associated params r=matklad a=SomeoneToIgnore

Applies the same iterator-shortening logic to the iterator associated types, recursively.

Before: 
![image](https://user-images.githubusercontent.com/2690773/95662735-e6ecf200-0b41-11eb-8e54-28493ad4e644.png)

After:
<img width="1192" alt="image" src="https://user-images.githubusercontent.com/2690773/95662894-e9038080-0b42-11eb-897d-527571ccac58.png">


Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-10-12 15:06:45 +00:00
bors[bot]
44df0e2a9f
Merge #6198
6198: Skip macro matcher fragment name semantic highlighting r=matklad a=Veykril

Implements a small state-machine for macro_rules! highlighting to separate out the matcher part of its rules. This skips semantically highlighting names of metavariables in the matcher and expander. This might even allow for more fun macro highlighting things in the future.

Fixes #4380.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 14:44:34 +00:00
bors[bot]
93de4918ea
Merge #6199
6199: Fix `mut self` not emitting mutable binding on `self` use r=matklad a=Veykril

Prior to this, when `self` in a function is taken by value and bound mutably, its use inside of the method body won't be marked `mutably`. 

Fixes #5461

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 14:24:18 +00:00
Jonas Schievink
cde7392ec8 Improve prime_caches and display its progress 2020-10-12 13:35:01 +02:00
Igor Aleksanov
991d019096 Use TextRange::contains_inclusive in fixes check 2020-10-12 11:32:22 +03:00
Igor Aleksanov
fb0ab9f745 Keep SyntaxNodePtr::range private 2020-10-12 11:05:00 +03:00
Igor Aleksanov
66cea8cbaa Replace 'if let' with 'match' in decl_check.rs 2020-10-12 11:05:00 +03:00
Igor Aleksanov
559cc97073 Add to_upper_snake_case function to stdx 2020-10-12 11:05:00 +03:00
Igor Aleksanov
ebd30033b3 Fix compilation error 2020-10-12 11:05:00 +03:00
Igor Aleksanov
f2c91fc5a8 Apply suggestions from code review
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 11:05:00 +03:00
Igor Aleksanov
9ea57cac0e Fix code style issues 2020-10-12 11:05:00 +03:00
Igor Aleksanov
50a147dcdf Apply case check diagnostic to impl items 2020-10-12 11:05:00 +03:00
Igor Aleksanov
2a72f876d6 Fix issues with match arm bindings 2020-10-12 11:05:00 +03:00
Igor Aleksanov
45ac2b2ede Code style adjustments 2020-10-12 11:05:00 +03:00
Igor Aleksanov
cfbee8d3a3 Remove previously added parameter names from the function data 2020-10-12 11:05:00 +03:00
Igor Aleksanov
b42562b5de Make incorrect case diagnostic work inside of functions 2020-10-12 11:05:00 +03:00
Igor Aleksanov
9ec1741b65 Refactor string helpers for decl_check module 2020-10-12 11:05:00 +03:00
Igor Aleksanov
fb96bba878 Add diagnostics for enum names and variants 2020-10-12 11:05:00 +03:00
Igor Aleksanov
e24e22f288 Add fix for incorrect case diagnostic 2020-10-12 11:04:59 +03:00
Igor Aleksanov
17f1026c46 Improve string helpers functions 2020-10-12 10:59:54 +03:00
Igor Aleksanov
21dd704b6b Check structure fields to be snake_case 2020-10-12 10:59:54 +03:00
Igor Aleksanov
329626124f Add check for structure names to be CamelCase 2020-10-12 10:59:54 +03:00
Igor Aleksanov
1773c6d154 Extract helper functions into a separate module 2020-10-12 10:59:54 +03:00
Igor Aleksanov
f5cea35986 Add checks for function parameters 2020-10-12 10:59:54 +03:00
Igor Aleksanov
4039176ec6 Create basic support for names case checks and implement function name case check 2020-10-12 10:59:54 +03:00
bors[bot]
518f6d7724
Merge #5917
5917: Add a command to open docs for the symbol under the cursor r=matklad a=zacps

#### Todo

- [ ] Decide if there should be a default keybind or context menu entry
- [x] Figure out how to get the documentation path for methods and other non-top-level defs
- [x] Design the protocol extension. In future we'll probably want parameters for local/remote documentation URLs, so that should maybe be done in this PR?
- [x] Code organisation
- [x] Tests


Co-authored-by: Zac Pullar-Strecker <zacmps@gmail.com>
2020-10-12 07:38:24 +00:00
kjeremy
a7d6674e4d Update crates 2020-10-11 18:01:50 -04:00
Lukas Wirth
9909ccb4f4 Fix mut self not emitting mutable binding on self use 2020-10-11 18:39:03 +02:00
Lukas Wirth
1416413d69 Skip macro matcher fragment name semantic highlighting 2020-10-10 23:21:12 +02:00
Kirill Bulatov
2bb80a4f03 Also replace the associated types with iter 2020-10-10 21:39:57 +03:00
Kirill Bulatov
9a72b7bccd Add a test 2020-10-10 20:02:38 +03:00
Rüdiger Herrmann
e90931a204 Show reason for failed rename refactoring
Return an error with a meaningful message for requests to
`textDocument/rename` if the operation cannot be performed.
Pass errors raised by rename handling code to the LSP runtime.

As a consequence, the VS Code client shows and logs the request
as if a server-side programming error occured.

Resolves https://github.com/rust-analyzer/rust-analyzer/issues/3981
2020-10-10 13:46:10 +02:00
bors[bot]
05261f5aeb
Merge #6176
6176: add eprintln in fmt-like postfix r=SomeoneToIgnore a=bnjjj



Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-09 23:16:19 +00:00
Jonas Schievink
5dcbf03d0f adt: correctly inherit field visibility from enum
Previously, "find all references" on a variant field wouldn't find any
references outside the defining module. This is because variant fields
were incorrectly assumed to be private, like struct fields without
explicit visibility, but they actually inherit the enum's visibility.
2020-10-09 20:46:45 +02:00
Jonas Schievink
210456aeaa Treat ast::Name in field patterns as use 2020-10-09 19:56:54 +02:00
Jonas Schievink
55ecfbb99b
Update crates/project_model/src/sysroot.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-10-09 16:17:05 +02:00
Jonas Schievink
7d0772e796 Add note if RUST_SRC_PATH is likely to be wrong 2020-10-09 16:11:16 +02:00
Jonas Schievink
468b804856 Fix source_to_def for named enum variant fields 2020-10-09 02:57:35 +02: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
Benjamin Coenen
36459284c7 add eprintln in fmt-like postfix
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-08 20:53:39 +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