Commit graph

927 commits

Author SHA1 Message Date
Aleksey Kladov
dec207f56a minor: simplify 2021-06-13 19:27:24 +03:00
Aleksey Kladov
a1940d8c75 internal: check diagnostics in all files and not just the first one 2021-06-13 19:23:37 +03:00
Aleksey Kladov
4af7a35197 internal: remove def-level diagnostics tests 2021-06-13 18:45:38 +03:00
Aleksey Kladov
00303284b5 internal: refactor macro error 2021-06-13 18:41:04 +03:00
Aleksey Kladov
1e4aaee7bb internal: refactor unresolved proc macro diagnostic 2021-06-13 17:51:44 +03:00
Aleksey Kladov
f85e383b94 internal: refactor inactive code diagnostics 2021-06-13 17:29:25 +03:00
Aleksey Kladov
fa9ed4e0ce internal: refactor unresolved macro call diagnostic 2021-06-13 17:08:54 +03:00
Aleksey Kladov
6d104de15a internal: refactor unresolved import diagnostic 2021-06-13 16:42:34 +03:00
Aleksey Kladov
39f190b72c internal: refactor unresolved extern crate diagnostic 2021-06-13 16:05:43 +03:00
Aleksey Kladov
6383252cc2 internal: unified missing fields diagnostic 2021-06-13 15:48:54 +03:00
Aleksey Kladov
c6509a4592 internal: move missing_fields diagnostics 2021-06-13 15:27:15 +03:00
Aleksey Kladov
efa069d288 internal: start new diagnostics API
At the moment, this moves only a single diagnostic, but the idea is
reafactor the rest to use the same pattern. We are going to have a
single file per diagnostic. This file will define diagnostics code,
rendering range and fixes, if any. It'll also have all of the tests.
This is similar to how we deal with assists.

After we refactor all diagnostics to follow this pattern, we'll probably
move them to a new `ide_diagnostics` crate.

Not that we intentionally want to test all diagnostics on this layer,
despite the fact that they are generally emitted in the guts on the
compiler. Diagnostics care to much about the end presentation
details/fixes to be worth-while "unit" testing. So, we'll unit-test only
the primary output of compilation process (types and name res tables),
and will use integrated UI tests for diagnostics.
2021-06-13 14:55:45 +03:00
Aleksey Kladov
0eafc88079 minor: put a mark back 2021-06-13 11:49:32 +03:00
Maan2003
5ac6804bb3
cargo fmt 2021-06-13 09:48:15 +05:30
Maan2003
c50b4579ec
clippy::useless_return 2021-06-13 09:35:29 +05:30
Maan2003
75370312fb
clippy::redundant_closure 2021-06-13 09:29:36 +05:30
Maan2003
705f7e6e26
clippy::clone_on_copy 2021-06-13 09:27:19 +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
Aleksey Kladov
7731714578 internal: move diagnostics infra to hir 2021-06-12 22:05:23 +03:00
Aleksey Kladov
6940cfed1e Move some hir_ty diagnostics to hir 2021-06-12 21:00:22 +03:00
Aleksey Kladov
0413d51317 internal: move missing unsafe diagnostic to hir 2021-06-12 17:39:46 +03:00
Aleksey Kladov
f8009666be internal: move inference diagnostics to hir 2021-06-12 17:17:23 +03:00
Lukas Wirth
e09723f0af Highlight tuple field accesses correctly 2021-06-11 21:19:19 +02:00
bors[bot]
863e23f00f
Merge #9219
9219: minor: Replace some AssocItem::containing_trait calls trait_or_trait_impl r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-11 17:56:00 +00:00
Lukas Wirth
db4a1fcab4 Replace some AssocItem::containing_trait calls trait_or_trait_impl 2021-06-11 19:55:24 +02:00
bors[bot]
21d4416235
Merge #9218
9218: Item search now respects trait impl items r=Veykril a=Veykril

Fixes #2977

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-11 17:33:34 +00:00
Lukas Wirth
48f65b3b15 Item search now respects trait impl items 2021-06-11 19:24:52 +02:00
Jonas Schievink
1d6eef1350 Update ungrammar 2021-06-11 18:34:30 +02:00
Kirill Bulatov
a6cdde0d0b Populate import maps eagerly 2021-06-11 01:27:20 +03:00
Lukas Wirth
26c869ddc0 Don't classify attributes on macro-calls are the macro itself 2021-06-10 00:26:15 +02:00
bors[bot]
5f592f4f58
Merge #9191
9191: fix: Don't descend MacroCall TokenTree delimiters r=jonas-schievink a=Veykril

Fixes #9190

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-09 13:17:38 +00:00
Lukas Wirth
3c40b15d62 Don't descend MacroCall TokenTree delimiters 2021-06-09 15:02:11 +02:00
Jonas Schievink
fcf22d68d4 Prefer attr macros in "expand macro recursively" 2021-06-08 22:26:01 +02:00
bors[bot]
2f376f7475
Merge #9169
9169: internal: steps towards attribute macro token mapping r=jonas-schievink a=jonas-schievink

This doesn't work yet, but we seem to be getting a bit further along (for example, we now stop highlighting `use` items inside item with attribute macros as if they were written verbatim).

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-07 17:37:48 +00:00
Jonas Schievink
33be5762e5 Attempt to track attr macros during highlighting 2021-06-07 19:32:28 +02:00
Jonas Schievink
33e747d786 Make "expand macro" command work with attribute macros 2021-06-07 16:05:36 +02:00
Jade
34ce05781f feat: goto def on impl items also goes to the defn in the trait
It was trivial to extend this to associated consts/associated types and
I just didn't think of it.
2021-06-06 21:52:00 -07:00
Jade
8a57c73640 feat: goto definition on an impl fn goes to that fn in the trait
e.g. if you have a trait T and `impl T for S` for some struct, if you
goto definition on some function name inside the impl, it will go to the
definition of that function inside the `trait T` block, rather than the
current behaviour of not going anywhere at all.
2021-06-06 21:51:17 -07:00
bors[bot]
d616a6a456
Merge #9149
9149: feat: Support goto-definition for include macros input path r=Veykril a=Veykril

![0l6l9iWPNE](https://user-images.githubusercontent.com/3757771/120891155-3fa85800-c607-11eb-9b20-7ac330dceb4b.gif)
Fixes #5871


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 19:26:33 +00:00
Lukas Wirth
5391f9c63c Support goto-definition for include macro paths 2021-06-05 19:04:50 +02:00
Lukas Wirth
d30f2d43db Prevent renaming of aliases on usages 2021-06-05 13:15:07 +02:00
bors[bot]
98395f29a4
Merge #9138
9138: feat: Implement hover for lints r=Veykril a=Veykril

fixes https://github.com/rust-analyzer/rust-analyzer/issues/8857, fixes https://github.com/rust-analyzer/rust-analyzer/issues/3941

![URXBanNxYe](https://user-images.githubusercontent.com/3757771/120830905-4bd8da80-c55f-11eb-9f55-ff5a321726fa.gif)

We also generate the default lints(and lint groups 🎉) instead now by invoking `rustc -W help` and parsing the output from that.


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-04 17:45:37 +00:00
Lukas Wirth
0c89f38378 Replace - with _ in generated lint names 2021-06-04 19:10:52 +02:00
Lukas Wirth
343df88ac7 Generate default lint completions 2021-06-04 18:35:19 +02:00
Lukas Wirth
5d17b6a687 Implement hover for lints 2021-06-04 17:03:18 +02:00
Lukas Wirth
07394316ff Add function references hover action 2021-06-04 15:54:55 +02:00
Lukas Wirth
5f1fac44c5 Cleanup parameter_hint_heuristics inlay hints test 2021-06-04 14:09:20 +02:00
Lukas Wirth
b0f6d8868c Reorganize inlay_hints tests 2021-06-04 13:47:39 +02:00
bors[bot]
7f9c4a59d9
Merge #9130
9130: Prefix/suffix parameter inlay hint hiding heuristic is more strict r=Veykril a=Veykril

Instead of just plainly checking prefix/suffix of the argument string to the parameter name we only check for prefixes and suffixes if they are split apart via an underscore meaning, with the argument `foo`, it will be hidden for the parameter name `foo_bar` but not for `foobar`.

bors r+
Closes https://github.com/rust-analyzer/rust-analyzer/issues/8878

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-03 14:26:07 +00:00
Lukas Wirth
cc762c30df Prefix/suffix parameter inlay hint hiding heuristic is more strict 2021-06-03 16:22:24 +02:00
Lukas Wirth
841feef79e Allow expand-macro to be invoked anywhere inside a macro call 2021-06-02 21:42:49 +02:00
bors[bot]
10b15b27f2
Merge #8952
8952: add support of impl block for doctest into runnables r=matklad a=bnjjj

close #6356 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-05-31 15:48:41 +00:00
bors[bot]
e9a797748d
Merge #8866
8866: Update salsa r=matklad a=jonas-schievink

This updates salsa to include https://github.com/salsa-rs/salsa/pull/265, and removes all cancellation-related code from rust-analyzer

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-31 12:42:32 +00:00
Jonas Schievink
cb5454db86 Diagnose unimplemented built-in macros 2021-05-30 04:19:47 +02:00
Lukas Wirth
a6b92a8cc0 simplify 2021-05-28 20:46:09 +02:00
bors[bot]
b5d41ba0e2
Merge #9038
9038: Folding range for return types r=Veykril a=MozarellaMan

For issue #8957 

![return type fold](https://user-images.githubusercontent.com/48062697/119979082-5c62e100-bfb2-11eb-9729-1dea1ce74de1.gif)


Co-authored-by: Ayomide Bamidele <48062697+MozarellaMan@users.noreply.github.com>
2021-05-28 12:16:18 +00:00
Ayomide Bamidele
b4e936f8f0 Test for correct amount of emitted folds 2021-05-28 13:10:41 +01:00
Ayomide Bamidele
156d995423 Folding range for return types 2021-05-28 12:39:02 +01:00
Lukas Wirth
61b4456752 Move runnable lenses below attributes 2021-05-28 13:02:42 +02:00
Jonas Schievink
33debc4065 Update salsa 2021-05-27 15:05:41 +02:00
bors[bot]
d0a4ba294c
Merge #8997
8997: internal: stop expanding UseTrees during ItemTree lowering r=jonas-schievink a=jonas-schievink

Closes https://github.com/rust-analyzer/rust-analyzer/issues/8908

Messy diff, but `ItemTree` lowering got simpler, since we now have a strict 1-to-1 mapping between `ast::Item` and `ModItem`.

The most messy part is mapping a single `UseTree` back to its `ast::UseTree` counterpart for diagnostics, but I think the ad-hoc source map built during lowering does the job.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-27 11:56:26 +00:00
Lukas Wirth
7ebfc3d410 Document semantic token tags 2021-05-26 15:23:05 +02:00
bors[bot]
5a1fd05760
Merge #9003
9003: minor: Document semantic token modifiers r=Veykril a=Veykril

Part of #6457

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-26 12:08:56 +00:00
Lukas Wirth
887dd2d5bb Document semantic token modifiers 2021-05-26 13:37:54 +02:00
bors[bot]
5701c553cb
Merge #9002
9002: Move annotations below item attributes r=Veykril a=Veykril

This moves annotations/code lenses below attributes in items, bringing them inline with functions where this is already the case. This is done by changing the annotations covering range to just the name node's range which is also more inline with what the lsp expects which is that the range should ideally only cover a single line. 

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9000
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-26 10:26:19 +00:00
Lukas Wirth
dfa47eaadb Move annotations below item attributes 2021-05-26 12:23:51 +02:00
bors[bot]
8483fb0f26
Merge #8996
8996: Fix bug where library functions were not highlighted as such r=arzg a=arzg

Sorry about forgetting to test this in my last PR.

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-05-25 23:28:02 +00:00
Aramis Razzaghipour
8960a08951
Fix bug where library functions were not highlighted as such 2021-05-26 09:26:13 +10:00
Jonas Schievink
b52df91877 Stop expanding UseTrees during ItemTree lowering 2021-05-26 01:01:58 +02:00
bors[bot]
5587d0a3e3
Merge #8973
8973: internal: move diagnostics to hir r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-25 20:33:21 +00:00
Aleksey Kladov
5c9f31d4c2 internal: move diagnostics to hir
The idea here is to eventually get rid of `dyn Diagnostic` and
`DiagnosticSink` infrastructure altogether, and just have a `enum
hir::Diagnostic` instead.

The problem with `dyn Diagnostic` is that it is defined in the lowest
level of the stack (hir_expand), but is used by the highest level (ide).

As a first step, we free hir_expand and hir_def from `dyn Diagnostic`
and kick the can up to `hir_ty`, as an intermediate state. The plan is
then to move DiagnosticSink similarly to the hir crate, and, as final
third step, remove its usage from the ide.

One currently unsolved problem is testing. You can notice that the test
which checks precise diagnostic ranges, unresolved_import_in_use_tree,
was moved to the ide layer. Logically, only IDE should have the infra to
render a specific range.

At the same time, the range is determined with the data produced in
hir_def and hir crates, so this layering is rather unfortunate. Working
on hir_def shouldn't require compiling `ide` for testing.
2021-05-25 17:49:59 +03:00
Jade
0292efd363 Also do goto implementation on assoc consts
I forgot to put this into #8988, sorry.

Goto implementation on a const on the trait will go to the
implementations with their respective definitions of the const, if
present.
2021-05-25 06:27:41 -07:00
Jade
3e4dfaf97a feat: go to implementation on trait functions
Fix #8537.

GIF:
https://user-images.githubusercontent.com/6652840/119501981-45a45c00-bd1e-11eb-8336-9145f2888643.gif
2021-05-25 05:46:15 -07:00
Jade
ff585e4730 Add go to type definition for struct fields within struct
Example:

```rust
struct A;

struct B {
    a/*<- cursor*/: A,
}
```

Go to type definition used to not work on this position. It now goes to
`A` as expected.
2021-05-25 04:06:54 -07:00
bors[bot]
8b049ec393
Merge #8942
8942: Add `library` semantic token modifier to items from other crates r=arzg a=arzg

Closes #5772.

A lot of code here is pretty repetitive; please let me know if you have any ideas how to improve it, or whether it’s fine as-is.

Side-note: How can I add tests for this? I don’t see a way for the test Rust code in `test_highlighting` to reference other crates to observe the new behaviour.


Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-05-25 02:30:47 +00:00
Aramis Razzaghipour
d75277b66b
Refactor application of library semantic token modifier 2021-05-25 12:20:12 +10:00
Benjamin Coenen
629ab18994 add support of impl block for doctest into runnables
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-05-24 19:17:25 +02:00
Laurențiu Nicola
47afa4a5fc Bump misc deps 2021-05-24 16:31:54 +03:00
Aramis Razzaghipour
eca4b764e4
Remove superfluous early-returns 2021-05-24 14:54:48 +10:00
Aramis Razzaghipour
e51188cd09
Rename ‘foreign’ semantic token modifier to ‘library’ 2021-05-24 14:54:48 +10:00
Aramis Razzaghipour
fa0d0bfb7f
Add testing of foreign item highlighting 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
b4cddc0705
Highlight foreign modules as such 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
c32428571c
Remove hir krate methods 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
4fd5248749
Add highlighting of items from other crates 2021-05-24 14:53:48 +10:00
Lukas Tobias Wirth
da74c66947 Correctly resolve crate name in use paths when import shadows itself 2021-05-23 19:37:01 +02:00
Aleksey Kladov
7283163bb9 Minor: fix comment style
See https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#documentation
2021-05-23 19:50:23 +03:00
Aramis Razzaghipour
4d4dbcfead
Give ‘unsafe’ semantic token modifier to unsafe traits 2021-05-23 21:45:10 +10:00
Aleksey Kladov
188b0f96f9 Add more docs 2021-05-22 16:53:47 +03:00
Jonas Schievink
271ec6b990 Add a "Debug ItemTree" LSP request 2021-05-21 23:59:52 +02:00
Lukas Tobias Wirth
2c7a8c4857 Fix prepare_rename failing for modules 2021-05-19 14:19:44 +02:00
rainy-me
e0b01f34bb Add pub mod option for UnlinkedFile 2021-05-18 08:11:07 +09:00
Aleksey Kladov
75a0123614 fix: don't add extra whitespace around fields
closes #8785
2021-05-17 12:45:01 +03:00
Aleksey Kladov
21918c6f5e minor: add missing tests 2021-05-17 12:37:22 +03:00
Aleksey Kladov
fa7fc0e5cb internal: scalable module structure for fixits 2021-05-17 12:04:17 +03:00
Aleksey Kladov
db8fbb99ce minor: extract fix to file 2021-05-17 11:40:34 +03:00
bors[bot]
ef6df1d994
Merge #8853
8853: Tag Self in impls as a TypeAlias r=matklad a=Veykril

bors r+
Fixes #4398

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-16 17:35:40 +00:00
Aleksey Kladov
1859df37fd internal: use mutable syntax trees when filling fields 2021-05-16 18:10:56 +03:00
Lukas Wirth
90230e882d Tag Self in impls as a TypeAlias 2021-05-16 15:12:58 +02: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