Commit graph

9156 commits

Author SHA1 Message Date
bors[bot]
a0fa522fda
Merge #6733
6733: Update attributes completion list r=jonas-schievink a=Veykril

Might be nice to have them grouped for readability/maintainability similar to how the [reference](https://doc.rust-lang.org/reference/attributes.html#built-in-attributes-index) does it but that would require the use of a `OnceCell` for sorting the entries back after construction.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-06 16:00:03 +00:00
Lukas Wirth
2ff1ebe8f3 Update attributes completion list 2020-12-06 16:46:24 +01:00
Jonas Schievink
45b8b3d57f
Apply suggestions from code review
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-12-06 14:23:55 +01:00
Jonas Schievink
2a6c246184 Update expect tests 2020-12-06 01:39:52 +01:00
Jonas Schievink
9d96a6d7af Emit additional diagnostics for hints/help/etc 2020-12-06 01:24:37 +01:00
Lukas Wirth
44c76d6550 Add replace_match_with_if_let assist 2020-12-05 15:41:36 +01:00
Jonas Schievink
b9d947cc6f Add slightly more profiling details 2020-12-04 20:26:28 +01:00
bors[bot]
571f247fbc
Merge #6725
6725: Don't respawn proc macro server on crash r=jonas-schievink a=jonas-schievink

Now the thread managing IPC will exit when the server process crashes instead of respawning it.

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

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-04 19:12:49 +00:00
Jonas Schievink
869ad13cf1 Don't respawn proc macro server on crash 2020-12-04 20:11:56 +01:00
bors[bot]
2756abb167
Merge #6721
6721: Use METHOD semantic token type r=kjeremy a=lnicola

Closes #6685

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-12-04 18:46:44 +00:00
bors[bot]
b6def6575c
Merge #6724
6724: Fix `diagnostics` subcommand, look at all modules r=jonas-schievink a=jonas-schievink

The `diagnostics` subcommand used to only compute diagnostics for `lib.rs` / the root module of all workspace crates. This fixed it and makes it look at every module.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-04 18:39:04 +00:00
Jonas Schievink
e45ab7e0ec Fix diagnostics subcommand, look at all modules 2020-12-04 19:37:37 +01:00
Florian Diebold
e5fd550dfd Use correct, full substs for self type in impl
Without arbitrary self types, the self type could never refer to the method type
parameters, so this wasn't a problem; but with arbitrary self types, it can.

This fixes the crash from #6668; but it doesn't make method resolution work for
these methods.
2020-12-04 18:43:47 +01:00
Laurențiu Nicola
72f013b3b9 Use METHOD semantic token type 2020-12-04 18:27:10 +02:00
Lukas Wirth
a1c8bdecfd Use items can also have doc comments 2020-12-04 17:09:40 +01:00
Jonas Schievink
b857149720 Unwrap process.stdio() result
If this is ever `None` here, that's a bug
2020-12-04 14:03:06 +01:00
Jonas Schievink
2845ce5bc6 Destructure in for loop 2020-12-04 13:57:33 +01:00
Jonas Schievink
c50d9f3683 Remove unnecessary Option 2020-12-04 13:54:09 +01:00
Jonas Schievink
6e1c87eb92 Don't diagnose #[cfg] in macros 2020-12-03 20:46:16 +01:00
Jonas Schievink
957fb18799 Make compile_error! message match upstream rustc
It only consists of the argument passed to it
2020-12-03 19:07:37 +01:00
Jonas Schievink
3e6ffa5124 Fix proc macro token mapping 2020-12-03 18:38:05 +01:00
bors[bot]
d46fce88f5
Merge #6700
6700: More macro diagnostics improvements r=jonas-schievink a=jonas-schievink

This threads macro expansion errors through `eager.rs` and the `AsMacroCall` trait, improving macro diagnostics emitted during body lowering.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-03 16:55:15 +00:00
Jonas Schievink
bca1e5fcb8 Rename error_sink to diagnostic_sink 2020-12-03 17:54:43 +01:00
Daiki Ihara
f486640682 Extract tests module to file in ide_db crate 2020-12-04 00:05:39 +09:00
Jonas Schievink
883c8d177d Make compile_error! lazy and emit a diagnostic 2020-12-03 15:48:29 +01:00
Jonas Schievink
4634bfb332 Give better diagnostic if OUT_DIR is unset 2020-12-03 15:48:29 +01:00
Jonas Schievink
17542d08b4 Update/Fix tests 2020-12-03 15:48:29 +01:00
Jonas Schievink
a634243634 Propagate eager expansion errors 2020-12-03 15:48:29 +01:00
Jonas Schievink
6da651f5da Don't prime caches when just opening a file 2020-12-02 20:18:28 +01:00
Jonas Schievink
f4866bb05c Test macro diagnostics in body lowering 2020-12-02 15:03:21 +01:00
bors[bot]
3e1fb112af
Merge #6698
6698: Attach macro expansion errors to the right file r=jonas-schievink a=jonas-schievink

Previously it attached them to the result of the macro expansion (or, if no result was produced, to the file containing the invocation). Always use the file containing the invocation.

This doesn't seem to have any observable difference, but seems better in theory.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-02 13:25:54 +00:00
Jonas Schievink
319fcd01ac Attach macro expansion errors to the right file 2020-12-02 14:23:51 +01:00
bors[bot]
dc09d97fb2
Merge #6649
6649: Accept more than just the standard rust literal suffixes in *Number::suffix r=matklad a=Veykril

I am not entirely sure whether to keep or remove the `SUFFIXES` but I figured we can always bring them back once they are needed.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-02 13:13:01 +00:00
bors[bot]
1db60512b6
Merge #6673
6673: Show type of Self on hover r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-02 13:06:34 +00:00
bors[bot]
a8f04712d6
Merge #6679
6679: Extract tests module to file in vfs crate r=matklad a=sasurau4

Helps with #6522 

- [x] passed `cargo test`

Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
2020-12-02 12:34:19 +00:00
bors[bot]
14086e3118
Merge #6697
6697: Don't discard PathKind::Abs information in lower_use::convert_path r=matklad a=Veykril

Fixes #6694

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-02 12:16:19 +00:00
Lukas Wirth
7b456552b8 Don't discard PathKind::Abs information in lower_use::convert_path 2020-12-02 09:54:03 +01:00
kjeremy
e4ffd70c91 Fix OptionalVersionedTextDocumentIdentifier type
Fixes #6654
2020-12-01 08:33:21 -05:00
bors[bot]
a18392bd90
Merge #6689
6689: Trigger .let postfix snippet in the middle of the block r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-12-01 12:38:45 +00:00
Aleksey Kladov
21d962f0ac Trigger .let postfix snippet in the middle of the block 2020-12-01 15:38:06 +03:00
bors[bot]
eb7f969510
Merge #6683
6683: Emit macro diagnostics when lowering bodies r=matklad a=jonas-schievink

Changes `Expander::enter_expand` to return an `ExpandResult`, and adds any contained errors to the body diagnostic list.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-01 12:27:52 +00:00
Jonas Schievink
ea7b81fef9 Emit unresolved proc macro errors 2020-12-01 12:40:03 +01:00
Aleksey Kladov
9d94ffad44 Place cursor correctly when completing assoc fns with self 2020-12-01 14:28:50 +03:00
Aleksey Kladov
02955661a0 Fix typo 2020-12-01 13:56:46 +03:00
Aleksey Kladov
6f51f728a1 Type-safer API for dealing with parameter lists with optional self 2020-12-01 13:53:39 +03:00
Jonas Schievink
be50908a50 Emit macro diagnostics when lowering bodies 2020-11-30 20:26:35 +01:00
Jonas Schievink
92f52c5c9a builtin_macro: move to mbe::ExpandResult 2020-11-30 19:21:25 +01:00
bors[bot]
70eb170271
Merge #6680
6680: Fix use merging not using the first path segment r=Veykril a=Veykril

Finally figured out why nested imports don't properly merge in some cases

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-30 16:22:56 +00:00
Lukas Wirth
ec94657077 Fix use merging not using the first path segment 2020-11-30 17:21:07 +01:00
Daiki Ihara
59bd6e2eea Extract tests module to file in vfs crate 2020-12-01 00:10:12 +09:00
kjeremy
0a95201243 bump lexer 2020-11-30 09:29:09 -05:00
Aleksey Kladov
8c3472b6f9 Minor cleanup 2020-11-30 13:47:38 +03:00
Lukas Wirth
9349d9ee48 Show type of Self on hover 2020-11-29 22:49:12 +01:00
bors[bot]
ac30710ada
Merge #6665
6665: Support self in reference search r=matklad a=Veykril

The approach here is simply checking the descendants of the function body for `PathExpr` then checking whether it only contains a single `self` `PathSegment`, this is to prevent us from picking up `self` tokens from local `UseTree`s.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-29 20:03:44 +00:00
Lukas Wirth
de4ada22d4 Support self in reference search 2020-11-29 20:54:17 +01:00
bors[bot]
25ebcca224
Merge #6599
6599: Add attribute highlight modifier to all tokens inside attributes r=matklad a=Veykril

This has the side effect that we also emit `attribute.attribute` highlights now, as in, the tokens that get the attribute semantic type also get the attribute modifier. I personally don't think it's really a problem but maybe it is to some? It's just that it was really simple to implement it this way, which is why I just went this route for now.

Fixes #6536

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-29 19:35:12 +00:00
bors[bot]
f8726d781a
Merge #6601
6601: add let and letm postfix to turn expressions into variables r=matklad a=bnjjj

Partially resolve #6426 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-29 19:21:25 +00:00
Lukas Wirth
4c33ae33e9 Reject more cases of invalid parameter to self renames 2020-11-29 19:02:59 +01:00
Lukas Wirth
f4a77f34da Fix renaming owned self to parameter emitting ref 2020-11-29 17:56:44 +01:00
Florian Diebold
21d256de72 Align default importMergeBehaviour with VSCode 2020-11-29 16:43:46 +01:00
bors[bot]
05f75d601f
Merge #6666
6666: Support 'go to definition' for self r=jonas-schievink a=Veykril

Also reverts #6660, instead of showing the type it now works like it does for names by returning the declaration we are already on. This for example enables VSCode to show all references(#6665) when executing `go to definition` on the declaration.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-29 14:35:38 +00:00
Lukas Wirth
37438c3335 Support 'go to definition' for self 2020-11-29 12:28:47 +01:00
bors[bot]
c8a2ff6ecc
Merge #6664
6664: Show type of self param on hover r=jonas-schievink a=Veykril

Show the type of `self` when hovering the token in a `SelfParam`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-28 23:38:18 +00:00
Lukas Wirth
ee8afff714 Show type of self param on hover 2020-11-28 22:59:24 +01:00
Benjamin Coenen
474ebd60d1 add let and letm postfix to turn expressions into variables
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-28 17:38:16 +01:00
bors[bot]
a6f26ded00
Merge #6660
6660: Support "go to definition" for SelfParams r=jonas-schievink a=Veykril

Fixes #6657

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-28 16:04:35 +00:00
Lukas Wirth
49fbfffb48 Add ast::*Number::suffix tests unit tests 2020-11-28 16:22:28 +01:00
bors[bot]
e437e38d7a
Merge #6659
6659: Explain how we get precise spans for diagnostics. r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-28 15:16:33 +00:00
Aleksey Kladov
5a42e6bff5 Explain how we get precise spans for diagnostics. 2020-11-28 18:14:08 +03:00
bors[bot]
7f3ba7d57f
Merge #6645
6645: Publish diagnostics for macro expansion errors r=matklad a=jonas-schievink

This adds 2 new diagnostics, emitted during name resolution:

* `unresolved-proc-macro`, a weak warning that is emitted when a proc macro is supposed to be expanded, but was not provided by the build system. This usually means that proc macro support is turned off, but may also indicate setup issues when using rust-project.json. Being a weak warning, this should help set expectations when users see it, while not being too obstructive. We do not yet emit this for attribute macros though, just custom derives and `!` macros.
* `macro-error`, which is emitted when any macro (procedural or `macro_rules!`) fails to expand due to some error. This is an error-level diagnostic, but currently still marked as experimental, because there might be spurious errors and this hasn't been tested too well.

This does not yet emit diagnostics when expansion in item bodies fails, just for module-level macros.

Known bug: The "proc macro not found" diagnostic points at the whole item for custom derives, it should just point at the macro's name in the `#[derive]` list, but I haven't found an easy way to do that.

Screenshots:

![screenshot-2020-11-26-19:54:14](https://user-images.githubusercontent.com/1786438/100385782-f8bc2300-3023-11eb-9f27-e8f8ce9d6114.png)
![screenshot-2020-11-26-19:55:39](https://user-images.githubusercontent.com/1786438/100385784-f954b980-3023-11eb-9617-ac2eb0a0a9dc.png)


Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-11-28 15:10:00 +00:00
Lukas Wirth
b006856381 Support goto definition for ADT-SelfParams 2020-11-28 16:07:07 +01:00
bors[bot]
b7ece77af4
Merge #6650
6650: Make completion and assists module independent r=matklad a=SomeoneToIgnore

A follow-up of https://github.com/rust-analyzer/rust-analyzer/pull/6553#discussion_r524402907

Move the common code for both assists and completion modules into a separate crate.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-11-28 14:33:57 +00:00
Kirill Bulatov
3f612d37c6 Move the helpers into ide_db 2020-11-28 16:30:39 +02:00
Jonas Schievink
f52abbe62d Coalesce flycheck events 2020-11-27 22:52:22 +01:00
Jonas Schievink
e49ba0d1df Downgrade "failed to load" error to warning 2020-11-27 18:35:22 +01:00
Jonas Schievink
ec7d2bbe42 Add/Fix macro expansion profiling 2020-11-27 18:07:16 +01:00
Kirill Bulatov
7b145bd99c Rustdocs fixes 2020-11-27 19:05:10 +02:00
Kirill Bulatov
f75f07019b Group import data in a struct 2020-11-27 18:30:10 +02:00
Kirill Bulatov
f4ae3650d8 Extract the import code into the shared module 2020-11-27 18:28:41 +02:00
Kirill Bulatov
04cd4b17bb
Fix the profiling string
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-11-27 18:13:02 +02:00
Kirill Bulatov
b2e6ca46ca Profile completions better 2020-11-27 18:00:03 +02:00
Jonas Schievink
d171838d63 More accurately place proc-macro diagnostic 2020-11-27 16:29:40 +01:00
Jonas Schievink
0432aa0ed7 Publish diagnostics for macro expansion errors 2020-11-27 13:50:22 +01:00
Jonas Schievink
1b26520971 Add dedicated error for "proc macro not found" 2020-11-27 13:50:20 +01:00
bors[bot]
c66d477f5a
Merge #6648
6648: Avoid allocation in ast::String::value if the string needs no unescaping r=lnicola a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-27 11:14:14 +00:00
Lukas Wirth
347da74eda Avoid allocation in ast::String::value if the string needs no unescaping 2020-11-27 12:03:58 +01:00
bors[bot]
572081f1c4
Merge #6586
6586: Don't call a closure a function in the infer_function_return_type assist label r=lnicola a=Veykril

`Add this function's return type` becomes `Add this closure's return type` for closures. This makes it more obvious that we are indeed planning on modifying the closure and not its containing function.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-27 09:49:37 +00:00
Lukas Wirth
931493e949 Accept more than just the standard rust literal suffixes in *Number::suffix 2020-11-27 00:00:18 +01:00
Lukas Wirth
6501c9445e Don't use raw identifiers 2020-11-26 21:44:17 +01:00
bors[bot]
fc0354b280
Merge #6635
6635: Complete struct in irrefutable let r=Veykril a=Veykril

Fixes #6210

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-26 20:30:16 +00:00
Lukas Wirth
ee06c07f50 Complete struct in irrefutable let 2020-11-26 21:28:43 +01:00
Laurențiu Nicola
3aca697511 Simplify error formatting 2020-11-26 21:07:15 +02:00
Laurențiu Nicola
a5477d7f29 Remove unused import 2020-11-26 19:25:59 +02:00
Jonas Schievink
519d870c11 Don't store SyntaxNodePtr in CrateDefMap
It is volatile across reparses and makes incrementality worse.
2020-11-26 17:29:09 +01:00
Jonas Schievink
74cb3e96a5 Test def map invalidation with #[cfg] below change 2020-11-26 17:28:00 +01:00
Jonas Schievink
2c85db8eb6 Implement Display for macro expansion errors 2020-11-26 16:56:22 +01:00
Jonas Schievink
6a9338e979 Use ExpandResult instead of MacroResult
`MacroResult` is redundant
2020-11-26 16:48:17 +01:00
Jonas Schievink
c784c8ec76 Use named fields in ExpandResult 2020-11-26 16:04:23 +01:00
Jonas Schievink
9ed883f373 Publish diagnostics on file open
Diagnostics are sometimes only showing up when typing.
This should fix that.
2020-11-26 13:33:47 +01:00
bors[bot]
db6988d4e7
Merge #6614 #6632
6614: Improve autoimports on completion speed r=matklad a=SomeoneToIgnore

Presumably closes https://github.com/rust-analyzer/rust-analyzer/issues/6594
May help https://github.com/rust-analyzer/rust-analyzer/issues/6612

* Ignore modules eaferly
* Do less completion string rendering

6632: Pin cargo_metadata r=matklad a=kjeremy

See: https://github.com/oli-obk/cargo_metadata/pull/142#issuecomment-733653275

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-11-26 10:43:35 +00:00
kjeremy
9a3142664b Pin cargo_metadata 2020-11-25 10:11:53 -05:00
Kirill Bulatov
9812150047 Document experimental completions 2020-11-25 00:42:58 +02:00
Kirill Bulatov
4c95c6e25d Gate autoimports begind experimental completions flag 2020-11-25 00:30:28 +02:00
Jonas Schievink
9559bce311 Rename parse_macro to parse_macro_expansion
This does not parse macros, it expands a macro and parses the *result*
2020-11-24 21:57:51 +01:00
Jonas Schievink
f9d0d51101 hir_expand::db: reduce fn visibility 2020-11-24 21:55:08 +01:00
Jonas Schievink
9a3bb19d32 Remove fixed FIXME, propagate errors better 2020-11-24 21:52:19 +01:00
Jonas Schievink
d5e9bf80f9 hir_expand: propagate expansion errors 2020-11-24 19:00:23 +01:00
Lukas Wirth
377fa7db3f Check structs for match exhaustiveness 2020-11-24 18:50:56 +01:00
Lukas Wirth
4d841dc4e7 Add middle ellipsis missing arm text 2020-11-24 16:46:06 +01:00
Lukas Wirth
a4b5275656 Handle ellipsis in tuple patterns in match exhaustiveness checking 2020-11-24 16:43:28 +01:00
bors[bot]
67d45851bf
Merge #6618
6618: Properly infer tuple patterns when encountering ellipsis r=Veykril a=Veykril

We basically just split the subpatterns into two halves when the ellipsis is present and then offset the latter half to account for the ignored bindings.

Fixes #6616

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-24 15:13:25 +00:00
Lukas Wirth
a5efefd3d7 Properly infer tuple struct patterns when encountering ellipsis 2020-11-24 16:11:40 +01:00
kjeremy
e981485b76 New lsp-types to fix versioning
Fixes #6603
2020-11-24 08:52:24 -05:00
Lukas Wirth
35dd62e915 Properly infer tuple patterns when encountering ellipsis 2020-11-24 13:56:20 +01:00
Laurențiu Nicola
8af1ed6a09 Avoid string allocations in ignore_test 2020-11-24 12:08:54 +02:00
bors[bot]
6294286fee
Merge #6610
6610: add 'Re-enable this test' assist r=SomeoneToIgnore a=jakobhellermann

The `Ignore this test` assist previously allowed ignoring multiple times, each time adding a `#[ignore]` attribute.

This PR instead shows an assist to undo the ignoring.

Co-authored-by: Jakob Hellermann <jakob.hellermann@protonmail.com>
2020-11-24 00:54:53 +00:00
bors[bot]
2ff78cde31
Merge #6613
6613: Don't assume DidChangeTextDocument paths exist r=SomeoneToIgnore a=mjibson

Fixes #5933

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
2020-11-24 00:41:08 +00:00
Kirill Bulatov
4baac238a8 Improve autoimports on completion speed
* Ignore modules eaferly
* Do less completion string rendering
2020-11-24 02:28:45 +02:00
Matt Jibson
117c793e80 Don't assume DidChangeTextDocument paths exist
Fixes #5933
2020-11-23 16:35:34 -07:00
Jakob Hellermann
a172c2317c add 'Re-enable this test' assist 2020-11-23 20:31:57 +01:00
Aleksey Kladov
2c083c993f Minor, import style 2020-11-23 21:19:37 +03:00
David Tolnay
8a11da40a7
Parse unsafe extern block 2020-11-22 20:44:56 -08:00
Benjamin Coenen
775c69183c add let and letm postfix to turn expressions into variables
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-21 15:06:22 +01:00
Lukas Wirth
1f87a41989 Add attribute highlight modifier to all tokens inside attributes 2020-11-21 12:51:05 +01:00
Lukas Wirth
5d39f6a357 Don't wrap parens around expr in remove_dbg assist if its in conditions 2020-11-20 17:28:56 +01:00
Lukas Wirth
91a1a83601 Fill code_description for rust_analyzer diagnostics 2020-11-18 08:54:52 +01:00
Lukas Wirth
56a0021e61 update diagnostics test_data with code_description changes 2020-11-18 08:50:27 +01:00
Lukas Wirth
863fdcfa24 Link clippy lint codes in diagnostics 2020-11-18 08:50:27 +01:00
Lukas Wirth
132063ad96 Link rustc error codes in diagnostics 2020-11-18 08:50:27 +01:00
Lukas Wirth
e8282b37d4 Don't call a closure function in infer_function_return_type label 2020-11-17 22:34:15 +01:00
bors[bot]
156f7d6963
Merge #6553
6553: Auto imports in completion r=matklad a=SomeoneToIgnore

![completion](https://user-images.githubusercontent.com/2690773/99155339-ae4fb380-26bf-11eb-805a-655b1706ce70.gif)

Closes https://github.com/rust-analyzer/rust-analyzer/issues/1062 but does not handle the completion order, since it's a separate task for https://github.com/rust-analyzer/rust-analyzer/issues/4922 , https://github.com/rust-analyzer/rust-analyzer/issues/4922 and maybe something else.

2 quirks in the current implementation:

* traits are not auto imported during method completion

If I understand the current situation right, we cannot search for traits by a **part** of a method name, we need a full name with correct case to get a trait for it.

* VSCode (?) autocompletion is not as rigid as in Intellij Rust as you can notice on the animation.

Intellij is able to refresh the completions on every new symbol added, yet VS Code does not query the completions on every symbol for me.
With a few debug prints placed in RA, I've observed the following behaviour: after the first set of completion suggestions is received, next symbol input does not trigger a server request, if the completions contain this symbol.
When more symbols added, the existing completion suggestions are filtered out until none are left and only then, on the next symbol it queries for completions.
It seems like the only alternative to get an updated set of results is to manually retrigger it with Esc and Ctrl + Space.

Despite the eerie latter bullet, the completion seems to work pretty fine and fast nontheless, but if you have any ideas on how to make it more smooth, I'll gladly try it out.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-11-17 17:50:08 +00:00
bors[bot]
f4b4f17662
Merge #6582
6582: Fill the diagnostic code field in publish_diagnostics r=kjeremy a=Veykril

Fixes #6580
Before:
![Code_znn6VgLLH9](https://user-images.githubusercontent.com/3757771/99408084-213f7100-28f0-11eb-8317-3f5c2b93313d.png)
After:
![Code_c4jJsvzOEA](https://user-images.githubusercontent.com/3757771/99408096-23093480-28f0-11eb-9bb2-8ebf2fb3d5a1.png)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-17 15:47:36 +00:00
Lukas Wirth
c868f0255f Fill the diagnostic code field in publish_diagnostics 2020-11-17 16:23:53 +01:00
Aleksey Kladov
e88b5fe916 Simplify 2020-11-17 15:25:58 +01:00
Aleksey Kladov
bd4d375a64 Make code more readable 2020-11-17 15:25:58 +01:00
Aleksey Kladov
a0c4dbc399 Minor 2020-11-17 15:25:58 +01:00
Aleksey Kladov
db218006c9 Remove dead code 2020-11-17 15:25:57 +01:00
Aleksey Kladov
0d19ee1d70 Simplify 2020-11-17 15:25:57 +01:00
Aleksey Kladov
17e8a00b0b Use standard code style for test fixtures 2020-11-17 14:43:23 +01:00
Aleksey Kladov
8c6f933773 **Unwrap Block** supports stand-alone blocks 2020-11-17 14:33:30 +01:00
Aleksey Kladov
10fa9c595a Simplify 2020-11-17 14:33:30 +01:00
Aleksey Kladov
8dd0b7d2b5 Assist target should point at *existing* code 2020-11-17 14:33:30 +01:00
Aleksey Kladov
9a30707281 Add **Ignore Test** assist 2020-11-17 14:22:04 +01:00
Kirill Bulatov
16f0b2fdde Actually enable eager completion 2020-11-17 13:19:56 +02:00
bors[bot]
10e3a9879c
Merge #6571
6571: Cleanup project model r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-17 10:53:12 +00:00
Aleksey Kladov
0dc1742187 Remove needless alloc 2020-11-17 11:52:28 +01:00
Aleksey Kladov
e4927d52e2 Compress code 2020-11-17 11:52:28 +01:00
Aleksey Kladov
a6960fb3b8 simplify 2020-11-17 11:31:40 +01:00
Kirill Bulatov
d4128beb3d Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
kjeremy
233fdb12ce Latest LSP 3.16 protocol
Pulls in https://github.com/gluon-lang/lsp-types/pull/186
2020-11-16 15:10:13 -05:00
Kirill Bulatov
4109968934 Remove query aliases 2020-11-16 21:24:54 +02:00
Kirill Bulatov
d776c67226 Properly fill the completion settings 2020-11-16 21:19:06 +02:00
Kirill Bulatov
1de7848b57 Fix the other test 2020-11-16 21:19:06 +02:00
Kirill Bulatov
bbe1fbd178 Qualify autoimport completion suggestions 2020-11-16 21:19:06 +02:00
Kirill Bulatov
38ef1fd4ad Better filter mod paths 2020-11-16 21:19:06 +02:00
Kirill Bulatov
ee99620754 Move autoimport completion into the unqialified_path module 2020-11-16 21:19:06 +02:00
Kirill Bulatov
3b0fc4d7f2 Omit modules during autocompletion 2020-11-16 21:19:06 +02:00
Kirill Bulatov
46514448b7 Tweak the search limits a bit 2020-11-16 21:19:06 +02:00
Kirill Bulatov
1598740292 Reuse existing element rendering 2020-11-16 21:19:06 +02:00
Kirill Bulatov
4c8edd003a Use imports_locator 2020-11-16 21:19:06 +02:00
Kirill Bulatov
d1556550f8 Rename the module 2020-11-16 21:19:06 +02:00
Kirill Bulatov
0e050fc3eb Allow to configure the merge behavior 2020-11-16 21:19:06 +02:00
Kirill Bulatov
1e458efe62 Add braces to functions and macros 2020-11-16 21:19:06 +02:00
Kirill Bulatov
6ab97244b8 Tidy up the tests 2020-11-16 21:19:06 +02:00
Kirill Bulatov
6866a05e6f Use rewriter api to add both changes 2020-11-16 21:19:06 +02:00
Kirill Bulatov
f62e8616c8 Add imports in auto completion 2020-11-16 21:19:05 +02:00
Aleksey Kladov
682dd4dac0 Prepare to recompute completions on every keystroke
If we set `is_incomplete: true`, VS Code will re-query completions
after every keypress.
2020-11-16 17:27:36 +01:00
bors[bot]
789d9ca1d3
Merge #6563
6563: Don't complete keywords in struct initializers r=matklad a=Veykril

Fixes #6562

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-16 11:49:48 +00:00
Lukas Wirth
fb71185692 Don't complete keywords in struct literals 2020-11-16 12:23:18 +01:00
bors[bot]
e17d604888
Merge #6558
6558: format string highlighting: handle hex + debug type specifier r=matklad a=ruabmbua

Should fix https://github.com/rust-analyzer/rust-analyzer/issues/6427


Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-11-16 11:07:29 +00:00
bors[bot]
382361c252
Merge #6552
6552: Properly handle shorthands in destructure patterns when renaming r=SomeoneToIgnore a=Veykril

Fixes #6548 and #6551.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-15 18:51:23 +00:00
Roland Ruckerbauer
a15dda48c6 format string highlighting: handle hex + debug type specifier 2020-11-15 17:43:14 +01:00
Lukas Wirth
f3e297331c Cleanup edit_text_range_for_record_field_expr_or_pat 2020-11-15 16:11:06 +01:00
Lukas Wirth
cb60708274 Use shorthand field syntax in destructures 2020-11-14 21:08:20 +01:00
Lukas Wirth
924eecf4af Properly handle shorthands in destructure patterns when renaming 2020-11-14 19:11:09 +01:00
Lukas Wirth
e55a44a831 Use shorthand record syntax when renaming struct initializer field 2020-11-14 17:51:09 +01:00
bors[bot]
e8c803937c
Merge #6544
6544: add suggestion ..Default::default() for remaining struct fields in a constructor r=bnjjj a=bnjjj

I'm not sure I should import `assists` crate inside `completions`, maybe we should move out `FamousDefs` from `assists` ? Let me know :) 

close #6492

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-13 23:30:13 +00:00
Benjamin Coenen
9f15de77f9 add suggestion ..Default::default() for remaining struct fields in a constructor #6492
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-13 23:20:26 +01:00
Aleksey Kladov
b1377363df Remove dead code 2020-11-13 17:53:48 +01:00
Aleksey Kladov
4dfda64b39 Cleanup workspace loading a tiny bit 2020-11-13 17:38:26 +01:00
Benjamin Coenen
e73d140b51 add suggestion ..Default::default() for remaining struct fields in a constructor #6492
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-11-13 17:17:16 +01:00
Aleksey Kladov
aeda30e301 Move tricky workspace logic to a separate module 2020-11-13 16:44:48 +01:00
Aleksey Kladov
f0f13d8cfa cleanup 2020-11-13 16:32:57 +01:00
bors[bot]
b0ad492e3d
Merge #6519
6519: Add "Open Cargo.toml" action r=matklad a=p3achyjr

## What is it?

This adds an "open cargo.toml" action from the vscode shell, resolves #6462 

## Test

Ran ```cargo xtask install --server``` and ```cargo xtask install --client```, then ```Developer: Reload Window```.

![image](https://user-images.githubusercontent.com/8763808/98614382-2a578f00-22ad-11eb-9811-4a72a54ff6fb.png)

When clicked:

![image](https://user-images.githubusercontent.com/8763808/98618176-77d7fa00-22b5-11eb-8788-35256542f3a6.png)


Co-authored-by: Anatol Liu <axlui@anatols-mbp.lan>
2020-11-13 15:25:26 +00:00
Anatol Liu
b1b7727e04 add open Cargo.toml action 2020-11-12 17:48:07 -08:00
bors[bot]
ddccaecb79
Merge #6524
6524: Add support for loading rustc private crates r=matklad a=xldenis

This PR presents a solution to the problem of making`rustc_private` crates visible to `rust-analyzer`. 
Currently developers add dependencies to those crates behind a `cfg(NOT_A_TARGET)` target to prevent `cargo` from building them.
This solution is unsatisfactory since it requires modifying `Cargo.toml` and causes problems for collaboration or CI. 

The proposed solution suggested by @matklad is to allow users to give RA a path where the `rustc` sources could be found and then load that like a normal workspace. 

This PR implements this solution by adding a `rustcSource` configuration item and adding the cargo metadata to the crate graph if it is provided. 

------

I have no idea how this should be tested, or if this code is generally tested at all. I've locally run the extension with these changes and it correctly loads the relevant crates on a `rustc_private` project of mine. 

Co-authored-by: Xavier Denis <xldenis@gmail.com>
2020-11-12 17:55:32 +00:00
Xavier Denis
89ce6b6664 Address review comments 2020-11-12 18:49:22 +01:00
bors[bot]
cf73b6851b
Merge #6514
6514: Fix extract_struct_from_enum_variant not updating record references r=Veykril a=Veykril

Related to #6510

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-12 17:48:25 +00:00
Lukas Wirth
ccdcd52975 Add extra test to extract_struct_from_enum_variant 2020-11-12 18:44:37 +01:00
bors[bot]
13cf3b4886
Merge #6513
6513: Support qualified function calls in remove_unused_param r=Veykril a=Veykril

Also adds a test to check that it removes unused params across files.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-12 17:12:21 +00:00
Lukas Wirth
b6e2b28353 Support qualified function calls in remove_unused_param 2020-11-12 18:04:42 +01:00
Lukas Wirth
9454a9e536 Use Module::find_use_path_prefixed in extract_struct_from_enum_variant assist 2020-11-12 17:32:45 +01:00
Lukas Wirth
e24cc77cd1 Fix extract_struct_from_enum_variant not updating record references 2020-11-12 17:13:33 +01:00
Kirill Bulatov
07e633ef0a Remove the fixme 2020-11-12 13:52:24 +02:00
Kirill Bulatov
3481ea96bd Add a FIXME for non-unified inner attributes 2020-11-12 13:46:02 +02:00
Kirill Bulatov
335edf87bc Do not insert imports before inner comments 2020-11-12 13:46:02 +02:00
Aleksey Kladov
a27186636d Fix attachment of inner doc comments 2020-11-12 12:09:12 +01:00
Aleksey Kladov
81ac99f60a Simplify code 2020-11-12 11:45:18 +01:00
Aleksey Kladov
f73b874157 Update tests 2020-11-12 11:19:26 +01:00
kjeremy
3b9d164043 Update crates 2020-11-11 11:17:48 -05:00
Xavier Denis
16443760a3 Reorder rustc_private loading 2020-11-11 13:04:27 +01:00
Xavier Denis
8716087919 Add support for loading rustc private crates 2020-11-11 12:45:40 +01:00
Aleksey Kladov
731f7bfc02 Replace RacyFlag with OnceCell 2020-11-11 03:11:40 +01:00
Aleksey Kladov
0caa491893 Be more pedantic when checking codeAction/resolve support 2020-11-10 20:38:34 +01:00
Aleksey Kladov
7d2eb000b0 Switch to upstream protocol for resolving code action
Note that we have to maintain custom implementation on the client
side: I don't see how to marry bulitin resolve support with groups and
snippets.
2020-11-10 18:48:46 +01:00
bors[bot]
ada5a88f8f
Merge #6512
6512: Don't replace parent node when inserting as first child in algo::diff r=SomeoneToIgnore a=Veykril

This makes the diff a bit more detailed.

See https://github.com/rust-analyzer/rust-analyzer/pull/6287#issuecomment-723889267 for context
cc @SomeoneToIgnore 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-09 23:41:43 +00:00
bors[bot]
0a715cfbd2
Merge #6472
6472: Add `static` modifier for associated functions r=matklad a=p3achyjr

Adds static semantic token modifier to associated functions, resolves #6194 

## Info

- Associated functions are more-or-less equivalent to static methods in other languages. This PR checks, for each function, whether that function has a self_param, and whether it's enclosed in a trait/impl.

## Changes

- Added method ```is_associated``` to code_model::Function. This basically gets the source from the ast, and checks whether the enclosing scope is an impl or trait.
- Added `static` to HighlightModifiers
- Added unit test

## Tests

- Ran ```cargo test```

Co-authored-by: Anatol Liu <axlui@anatols-mbp.lan>
2020-11-09 21:13:51 +00:00
Anatol Liu
6b950d24d4 Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs

address comments
2020-11-09 13:09:20 -08:00
Lukas Wirth
a61bb4abb5 Don't replace parent node when inserting as first child in algo::diff 2020-11-09 20:10:49 +01:00
Lukas Wirth
949c580d1b Add multiple file edit tes to remove_unused_param assist 2020-11-09 19:06:11 +01:00
Aleksey Kladov
9634521abd . is an operator
closes #6498
2020-11-09 18:12:28 +01:00
Aleksey Kladov
4a16c228e7 Fix panic when extracting struct 2020-11-09 16:59:57 +01:00
Aleksey Kladov
018f826197 Support multi-file assist tests 2020-11-09 14:44:08 +01:00
Aleksey Kladov
e72cd4600e Fix debug for SyntaxRewriter 2020-11-09 14:09:49 +01:00
bors[bot]
73b08131df
Merge #6506
6506: Cleanup assists r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-09 12:28:57 +00:00
Aleksey Kladov
d31ce3b16c Use standard style for test code 2020-11-09 13:28:04 +01:00
Aleksey Kladov
3cecf78488 More consistent naming 2020-11-09 13:18:40 +01:00
Aleksey Kladov
29bf6bed9b More consistent naming 2020-11-09 13:07:18 +01:00
bors[bot]
2d3b0571bb
Merge #6465
6465: Support multiple file edits in AssistBuilder r=matklad a=Veykril

Fixes #6459

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-09 11:54:42 +00:00
bors[bot]
2f24714081
Merge #6501
6501: Remove text_edit_builder api from AssistBuilder r=matklad a=Veykril

Also fixes a small bug in `expand_glob_import` in regards to the very nice looking `something::{*}` import when only one item was used. Before it would duplicate the path and just append it, causing the following wrong import `something::something::UsedItem`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-09 11:40:08 +00:00
Lukas Wirth
4c03d98db4 Remove text_edit_builder api from AssistBuilder 2020-11-08 23:22:11 +01:00
Pavan Kumar Sunkara
ca3498bd84 Add some postfix snippet 2020-11-08 20:10:40 +01:00
Anatol Liu
90031a267a Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs

address comments
2020-11-08 00:01:02 -08:00
bors[bot]
dac7060382
Merge #6476
6476: Add missing AssocItems in add_custom_impl assist r=matklad a=Veykril

```rust
use std::fmt;

#[derive(Debu<|>g)]
struct Foo {
    bar: String,
}
```
->
```rust
use std::fmt;

struct Foo {
    bar: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        ${0:todo!()}
    }
}
```

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-07 18:21:11 +00:00
m-ysk
69ba62e6cd Minimize convert_integer_literal tests 2020-11-07 18:47:25 +09:00
Aleksey Kladov
5db789df9c Cleanup API 2020-11-06 22:52:42 +01:00
bors[bot]
7f12a1f225
Merge #6485
6485: Remove RAW literals r=matklad a=matklad

bors r+
🤖

closes https://github.com/rust-analyzer/rust-analyzer/issues/6308

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-06 21:39:02 +00:00
bors[bot]
cdddcaee85
Merge #6477
6477: Add infer_function_return_type assist r=matklad a=Veykril

This adds an assist to insert a functions return type if it hasn't been specified yet by inferring it from the functions tail expression. This assist only becomes active if the cursor is on the tail expression. See https://github.com/rust-analyzer/rust-analyzer/issues/6303#issuecomment-714657326

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-06 21:32:27 +00:00
Aleksey Kladov
6158304f8b Simplify 2020-11-06 22:30:58 +01:00
Aleksey Kladov
5ba4f949c2 Kill RAW_ literals
Syntactically, they are indistinguishable from non-raw versions, so it
doesn't make sense to separate then *at the syntax* level.
2020-11-06 22:23:14 +01:00
Lukas Wirth
186431e178 Adjust test-texts in infer_function_return_type 2020-11-06 21:51:15 +01:00
Lukas Wirth
4f0d02c276 Enable infer_function_return_type in return-type position 2020-11-06 21:49:03 +01:00
Aleksey Kladov
6725dcf847 Minor, cleanup style 2020-11-06 21:09:37 +01:00
bors[bot]
1faa9559fe
Merge #6480
6480: Support closure in change_return_type_to_result assist r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-06 19:41:13 +00:00
Lukas Wirth
e95a65ccaf Support closure in change_return_type_to_result assist 2020-11-06 20:40:03 +01:00
Aleksey Kladov
eb46033390 More orthogonal API 2020-11-06 19:09:01 +01:00
Aleksey Kladov
735aaa7b39 Move int parsing to IntNumber token 2020-11-06 18:54:01 +01:00
Aleksey Kladov
6bcc33e5b7 Better imports 2020-11-06 18:39:09 +01:00
Aleksey Kladov
3820b26a93 Generate token for ints and floats 2020-11-06 18:19:24 +01:00
Aleksey Kladov
85db47ac76 Ignore RUST_SRC_PATH if it is set to invalid value
Folks report a ton of hard-to-diagnose issues, the solution for which
is "unset RUST_SRC_PATH". Let's just ignore RUST_SRC_PATH when it
won't work anyway!
2020-11-06 11:30:57 +01:00
Lukas Wirth
c665884474 Wrap non-block expressions in closures with a block 2020-11-06 03:06:08 +01:00
Lukas Wirth
2e6e5d8f73 Ignore unit expressions in infer_function_return_type assist 2020-11-06 02:17:34 +01:00
Lukas Wirth
0a7c8512ff Support closures in infer_function_return_type assist 2020-11-06 02:15:13 +01:00
Lukas Wirth
a14df19d82 Add infer_function_return_type assist 2020-11-06 01:47:41 +01:00
Anatol Liu
3aa0e40726 Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs

address comments
2020-11-05 15:46:04 -08:00
Lukas Wirth
19443c1fa3 Add missing AssocItems in add_custom_impl assist 2020-11-05 23:41:46 +01:00
Anatol Liu
14b38e198c Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs
2020-11-04 23:41:02 -08:00
Anatol Liu
771c0d8c08 Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs
2020-11-04 21:55:44 -08:00
Anatol Liu
3baa526fb0 Add static semantic token modifier for associated functions with no &self 2020-11-04 20:08:46 -08:00
bors[bot]
4e8401af41
Merge #6467
6467: Don't stack overflow on circular modules r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-04 14:38:19 +00:00