Commit graph

9156 commits

Author SHA1 Message Date
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
Aleksey Kladov
2b108133ac Don't stack overflow on circular modules
closes #6453
2020-11-04 15:31:35 +01:00
bors[bot]
bd6eeffb2f
Merge #6456
6456: Support record variants in extract_struct_from_enum_variant r=matklad a=Veykril

As requested :)

This also prevents the assist from being disabled if a definition in the value namespace exists with the same name as our new struct since that won't cause a collision

#4468

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-04 12:37:29 +00:00
bors[bot]
99a8e59f68
Merge #6458
6458: Qualify trait impl created by add_custom_impl assist r=matklad a=Veykril

When we find at least one trait with the same name as the derive accessible from the current module we now generate a qualified path to that trait in the generated impl.
If we don't find any we just do what was done before and emit the trait name in the generated impl.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-04 12:30:09 +00:00
Lukas Wirth
db5c529781 Support multiple file edits in AssistBuilder 2020-11-04 12:34:33 +01:00
Lukas Wirth
4992b75e51 Qualify trait impl created by add_custom_impl assist 2020-11-03 23:41:35 +01:00
Lukas Wirth
6145234450 Support struct variants in extract_struct_from_enum_variant 2020-11-03 20:57:04 +01:00
bors[bot]
7c94f1cb5e
Merge #6454
6454: Fix overflow panic in convert_interger_literal assist r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-11-03 18:59:15 +00:00
Aleksey Kladov
9349353e04 Fix overflow panic in convert_interger_literal assist
This also seizes the opportunity to move integer literal parsing to
the syntax crate, were it logically belongs.

Note though that this is still done in an ad hoc manner -- we probably
should split kitchen sink ast::Literal into a separate APIs for
strings, ints, etc
2020-11-03 19:57:57 +01:00
Lukas Wirth
dc9842b64f only check type namespace in extract_struct_from_enum_variant for collisions 2020-11-03 19:55:14 +01:00
bors[bot]
060c8b2c96
Merge #6287
6287: Don't replace entire module and file nodes when inserting imports r=matklad a=Veykril

This change minifies the resulting diff of import insertions by inserting or replacing the produced use tree directly through an `action` return value instead replacing the entire container node. This action has to be applied by the caller now. This unfortunately pulls the `AssistBuilder` into scope of `insert_use` back again but I tried to at least keep it away from the `insert_use` fn itself.

I'm open to more/better ideas regarding this :)

Fixes #6196

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-03 17:34:59 +00:00
bors[bot]
5e62233277
Merge #6401
6401: Only show `self` ident when showing parameter self hints r=matklad a=Veykril

This just hints all self parameters with the `self` token, this is therefor equal to how all other parameters are displayed, but given the self param special in how its defined in a function signature it might make sense to keep the `&`/`&mut` parts as well as emitting those tokens for explict `Self` types that are taken by ref like `self: &Rc<Self>`?

Fixes #6400

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-03 16:43:26 +00:00
bors[bot]
8ad01d863b
Merge #6435
6435: Test Fixture ExplicitRoot + ModuleResolutionRelativePathOutsideRoot. r=matklad a=rickvanprim

Updates `module_resolution_relative_path_outside_root` test to check valid paths outside of the root, by moving the root to a subpath so that paths outside of it are possible.  If this would be more appropriate as a new test, or if the original check for an invalid path should be left, I'm happy to update.

Co-authored-by: James Leitch <rickvanprim@gmail.com>
2020-11-03 16:36:34 +00:00
bors[bot]
07c7f35eff
Merge #6430
6430: Move completions rendering into a separate module r=popzxc a=popzxc

This PR extracts rendering-related things from `Completions` structure to the new `render` module.

`render` module declares a `Render` structure (which is a generic renderer interface), `RenderContext` (interface for data/methods not required for completions generating, but required for rendering), and a bunch of smaller `*Render` structures which encapsulate logic behind rendering a certain item.

This is just a step in full separation direction, since the following this are still to be done:

- Move some data from `CompletionContext` to the `RenderContext`;
- Forbid any kind of rendering outside of `render` module;
- Extract score computing into a separate module.

This PR is already pretty big, so not to make it even harder to review I decided to split this process into several subsequent PRs.


Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
2020-11-03 07:54:45 +00:00
Igor Aleksanov
8efe43245b Remove intra-crate facade from completions 2020-11-03 10:36:01 +03:00
Igor Aleksanov
4d333ebb63 Get rid of do-er antipattern 2020-11-03 10:33:13 +03:00
Igor Aleksanov
caf0fa20a7 Provide only explicit constructor for RenderContext 2020-11-03 10:17:59 +03:00
Igor Aleksanov
2a214e15d3 Add doc-comments to the new files 2020-11-03 10:16:35 +03:00
Igor Aleksanov
af7175f332 Make structures order more logical in render.rs 2020-11-03 10:16:35 +03:00
Igor Aleksanov
97a504805d Move rendering tests to the render module 2020-11-03 10:16:35 +03:00
Igor Aleksanov
15b16917fc Add TypeAliasRender 2020-11-03 10:16:35 +03:00
Igor Aleksanov
944ccf6075 Add ConstRender 2020-11-03 10:16:35 +03:00
Igor Aleksanov
fc8a1cd800 Introduce render module 2020-11-03 10:16:35 +03:00
Igor Aleksanov
dd2febf05a Improve decl_check module readability 2020-11-03 10:13:49 +03:00
Igor Aleksanov
9e172ffeb7 Remove numbers from comments in decl_check.rs 2020-11-03 10:11:02 +03:00
Igor Aleksanov
bdfe12df8f Check for allow(..) attributes for case diagnostic 2020-11-03 10:11:02 +03:00
Lukas Wirth
74c82ca8ce Only show self ident when showing parameter self hints 2020-11-02 21:56:16 +01:00
Lukas Wirth
cd349dbbc4 Make insert_use return a SyntaxRewriter 2020-11-02 21:40:52 +01:00
James Leitch
ff87726074 Feedback. 2020-11-02 10:57:31 -07:00
bors[bot]
245e1b533b
Merge #6445
6445: Fix coalescing of prime_caches updates r=jonas-schievink a=jonas-schievink

The previous implementation could try to create a progress bar when one
was already registered.

bors r+ 🤖 

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-11-02 17:54:01 +00:00
Jonas Schievink
285960aa6b Fix coalescing of prime_caches updates
The previous implementation could try to create a progress bar when one
was  already registered
2020-11-02 18:49:54 +01:00
bors[bot]
173e45f872
Merge #6365
6365: Do insertion lookahead in algo::diff r=matklad a=Veykril

This is the last blocker for #6287 after this I can update that PR to properly fix things through using `SyntaxRewriter`.

This PR also shuffles tests around a bit and adds some more.

Ideally this is just a hack until we implement a "proper" diff algorithm that approximates a minimal diff. Maybe something like [gumtree](https://github.com/GumTreeDiff/gumtree)?

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-02 17:47:08 +00:00
bors[bot]
d021dbeb4f
Merge #6393 #6399
6393: Remove repetitive inlay hints (take 2) r=matklad a=lnicola



6399: Keep generic annotations when qualifying things r=matklad a=Veykril

The `qualify_path` assists currently eats up already annotated generics in all but one cases which can be annoying if one already pre-fills generics of a type before it's been qualified.

Co-authored-by: Matthew Sanetra <matthewsanetra@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-11-02 17:40:47 +00:00
Jonas Schievink
58e3fd8e8e Remove unnecessary clone 2020-11-02 18:33:46 +01:00
bors[bot]
eb4e84ff51
Merge #6441
6441: Coalesce prime_caches updates r=matklad a=jonas-schievink

This reduces the number of progress bar updates we send to the client by collapsing subsequent updates into one. This doesn't work as well as I'd hoped (which is that we end up sending *no* updates, or only `start` and `end`, when the cache is already fresh), but it does reduce the number considerably: instead of ~720 updates on the rust-analyzer codebase, we now only send ~60.

It uses the same approach that is already in use for coalescing VFS events.

Hopefully this is enough to fix https://github.com/rust-analyzer/rust-analyzer/issues/6413.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-11-02 17:12:08 +00:00
kjeremy
0403e82d91 Bump chalk and lexer 2020-11-02 12:00:58 -05:00
Jonas Schievink
a968cb6aef Remove debug print 2020-11-02 17:24:35 +01:00
Jonas Schievink
6e8ddac165 Coalesce prime_caches updates 2020-11-02 17:24:35 +01:00
Aleksey Kladov
ba8d6d1e4e Remove more unreachable pubs 2020-11-02 16:58:33 +01:00
Aleksey Kladov
b610118453 Deny unreachable-pub
It's very useful when `pub` is equivalent to "this is crate's public
API", let's enforce this!

Ideally, we should enforce it for local `cargo test`, and only during
CI, but that needs https://github.com/rust-lang/cargo/issues/5034.
2020-11-02 14:07:08 +01:00
James Leitch
d2d7a4403c Test Fixture ExplicitRoot + ModuleResolutionRelativePathOutsideRoot. 2020-11-01 17:20:55 -07:00
Pavan Kumar Sunkara
c070146a83
Update Cargo.toml 2020-10-31 08:49:57 +01:00
bors[bot]
dd84b7a24d
Merge #6416
6416: Respond with JSON-RPC error if we failed to deserialize request r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-30 19:07:29 +00:00
Aleksey Kladov
3b9548e163 Respond with JSON-RPC error if we failed to deserialize request
Historically, we intentinally violated JSON-RPC spec here by hard
crashing. The idea was to poke both the clients and servers to fix
stuff.

However, this is confusing for server implementors, and falls down in
one important place -- protocol extension are not always backwards
compatible, which causes crashes simply due to version mismatch. We
had once such case with our own extension, and one for semantic
tokens.

So let's be less adventerous and just err on the err side!
2020-10-30 19:57:52 +01:00
Florian Diebold
bca51e3519 Upgrade Chalk to 0.36
Quite a few changes, because Chalk got rid of the `ApplicationTy` nesting.
2020-10-30 18:57:55 +01:00
yuqing
6c4bb30e95 remove FIXME after rust 1.47 comes out 2020-10-30 14:58:59 +08:00
Lukas Wirth
042413c35f Keep generic annotations when qualifying things 2020-10-29 10:25:15 +01:00
Benjamin Coenen
7322a69cf6 refactor(hir_ty): do not override DisplayTarget in hir_fmt
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 17:58:16 +01:00
bors[bot]
e34183218c
Merge #6387
6387: do not use associated types placeholder for inlay hint  r=flodiebold a=bnjjj


close #6191

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 14:54:00 +00:00
Benjamin Coenen
ec3638adb9 do not use associated types placeholder for inlay hint
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 15:42:51 +01:00
Benjamin Coenen
0aca7b78de do not use associated types placeholder for inlay hint
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 15:23:23 +01:00
bors[bot]
85cda15b62
Merge #6384
6384: add doctest runnables on struct r=lnicola a=bnjjj

I will check for how to do the same on trait implementation on another PR.

#6356

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 13:15:28 +00:00
Benjamin Coenen
ef2f7bb243 do not use associated types placeholder for inlay hint
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 14:07:12 +01:00
Matthew Sanetra
05723cb50d Add check if param name is similar to fn name 2020-10-28 14:45:45 +02:00
Benjamin Coenen
8762b797fd do not use associated types placeholder for inlay hint
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-28 11:20:05 +01:00
Benjamin Coenen
73161cc9cd do not use associated types placeholder for inlay hint #6191
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-27 20:23:09 +01:00
bors[bot]
53c7aead8f
Merge #6379
6379: Highlight never type as BuiltinType r=matklad a=Veykril

Fixes #6374

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-27 14:49:37 +00:00
Benjamin Coenen
3bbc2e95e4 add doctest runnables on struct #6356
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-27 14:11:27 +01:00
bors[bot]
8cfc1cd95b
Merge #6376
6376: Avoid impls_fnonce to return true when the trait solving is ambiguous  r=flodiebold a=GrayJack

This PR should fix #6375 

This adds a variation of `method_resolution::implements_trait` called `method_resolution::implements_trait_unique`, that only returns true when the trait solving is unique, and also change `impls_fnonce` to use the later instead.

I also added a test just to be sure.

Co-authored-by: GrayJack <gr41.j4ck@gmail.com>
2020-10-27 09:51:49 +00:00
Benjamin Coenen
94b2330f55 add doctest runnables on struct #6356
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-27 10:07:33 +01:00
bors[bot]
7f346f9ae1
Merge #6257
6257: Don't suggest extracting out 1-tuple enum variants r=matklad a=repnop

Fixes #6241.

Co-authored-by: Wesley Norris <repnop@outlook.com>
2020-10-26 21:40:56 +00:00
Wesley Norris
b9790a23bf Don't suggest extracting out 1-tuple enum variants
Fixes #6241.
2020-10-26 17:38:23 -04:00
Lukas Wirth
269e67312d Highlight never type as BuiltinType 2020-10-26 22:27:30 +01:00
Aleksey Kladov
b2ccef60b4 Better ordering of assists 2020-10-26 21:59:28 +01:00
GrayJack
ae6376d74c
Fix test 2020-10-26 17:23:29 -03:00
bors[bot]
d10e2a04c8
Merge #6351
6351: Organized completions r=popzxc a=popzxc

This PR continues the work on refactoring of the `completions` crate.

In this episode:

- Actual completions methods are encapsulated into `completions` module, so they aren't mixed with the rest of the code.
- Name duplication was removed (`complete_attribute` => `completions::attribute`, `completion_context` => `context`).
- `Completions` structure was moved from `item` module to the `completions`.
- `presentation` module was removed, as it was basically a module with `impl` for `Completions`.
- Code approaches were a bit unified here and there.


Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
2020-10-26 19:06:34 +00:00
GrayJack
40a875ab7a
Add test to avoid regression 2020-10-26 15:28:56 -03:00
GrayJack
08e95a5dc1
Fix case where non FnOnce variables is marked callable 2020-10-26 15:20:33 -03:00
Igor Aleksanov
357bf0cedc Reduce visibility of some methods 2020-10-26 20:37:19 +03:00
bors[bot]
d01e412eb1
Merge #6367
6367: Handle #![cfg] in crate root r=jonas-schievink a=jonas-schievink

Now we correctly skip analysis of winapi on non-Windows platforms.

bors r+ 🤖

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-10-26 15:05:10 +00:00
Jonas Schievink
cd3c632cfc Handle #![cfg] in crate root 2020-10-26 16:04:08 +01:00
Lukas Wirth
750ab54573 Do insertion lookahead in algo::diff 2020-10-26 16:03:37 +01:00
bors[bot]
42df7cc0c8
Merge #6313
6313: Latest proposed LSP 3.16.0 and refresh semantic tokens r=matklad a=kjeremy

Needs: https://github.com/gluon-lang/lsp-types/pull/183

Co-authored-by: kjeremy <kjeremy@gmail.com>
Co-authored-by: Jeremy A. Kolb <jkolb@ara.com>
2020-10-26 14:49:07 +00:00
bors[bot]
a0f1346864
Merge #6333
6333: Don't interpret type path as part of visibility. r=matklad a=ArifRoktim

This closes #5902.
I only check that the next token isn't equal to `T![:]`, instead of the next two not being equal to `T![::]`. Is that ok?

Co-authored-by: Arif Roktim <arifrroktim@gmail.com>
2020-10-26 14:34:00 +00:00
bors[bot]
1a84cadc88
Merge #6347
6347: Support insertion in SyntaxRewriter r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-26 14:08:47 +00:00
Jeremy A. Kolb
8982c0610f Update tests 2020-10-26 09:57:46 -04:00
kjeremy
2d4be2ef2a Request a refresh of semantic tokens if things are loaded up 2020-10-26 09:23:34 -04:00
kjeremy
5cb6fafd36 Latest proposed LSP 3.16.0
Needs: https://github.com/gluon-lang/lsp-types/pull/183
2020-10-26 09:23:34 -04:00
bors[bot]
29f5154d1c
Merge #6350
6350: Make IncorrectDiagnostic match rustc by copying rustc's code. r=popzxc a=ArifRoktim

This closes #6343 and closes #6345.

The old algorithm which used a `DetectedCase` enum, didn't match how rustc thinks of cases. Some inputs can be interpreted as more than 1 case depending on the situation. For example, to rustc:
- `ABCD`: Can be both camel case and upper snake case
- `X86_64`: Can be both camel case and upper snake case

I could've made `detect_case` return a collection of `DetectedCase` and then modified the other code as such, but I think using the same code rustc uses is simpler and a surefire way to achieve the same diagnostics as rustc.

Co-authored-by: Arif Roktim <arifrroktim@gmail.com>
2020-10-26 13:20:57 +00:00
bors[bot]
35ed3d2c00
Merge #6360
6360: Fix unary minus highlighting r=matklad a=Veykril

Fixes #6358

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-26 13:07:25 +00:00
Lukas Wirth
c9af469b85 Fix unary minus highlighting 2020-10-25 23:05:30 +01:00
Lukas Wirth
551bf65e6d Keep parens around in remove-dbg for range expressions 2020-10-25 15:36:02 +01:00
Lukas Wirth
3182c06752 Don't keep parens around in remove-dbg 2020-10-25 15:12:21 +01:00
Lukas Wirth
6675d4c576 Don't keep parens around with remove-dbg when encountering method chaining 2020-10-25 14:28:44 +01:00
Florian Diebold
39dfca23f1 Add tracing to main rust-analyzer binary 2020-10-25 13:53:38 +01:00
Florian Diebold
6b5f82bcea Get rid of FAKE_PLACEHOLDER
The lifetime placeholder can be replaced by the static lifetime, and for array
sizes we should just be using a concrete const.
2020-10-25 12:42:38 +01:00
Igor Aleksanov
1759f2fc17 Add a module doc-comment for completions module 2020-10-25 11:40:00 +03:00
Igor Aleksanov
9822acac0d Remove presentation module 2020-10-25 11:32:41 +03:00
Igor Aleksanov
f731d910cb Move Completions structure definition into completions module 2020-10-25 11:26:38 +03:00
Igor Aleksanov
19c1067202 Reorganize completions structure 2020-10-25 10:59:15 +03:00
Arif Roktim
afb2166aeb Make IncorrectDiagnostic match rustc by copying rustc's code. 2020-10-24 19:21:53 -04:00
Lukas Wirth
45860d5207 Remove InsertPos::Before variant in Syntax Rewriter 2020-10-24 21:58:03 +02:00
bors[bot]
bf84e4958e
Merge #6331 #6342
6331: correct hover text for items with doc attribute with raw strings r=matklad a=JoshMcguigan

Fixes #6300 by improving the handling of raw string literals in attribute style doc comments.

This still has a bug where it could consume too many `"` at the start or end of the comment text, just as the original code had. Not sure if we want to fix that as part of this PR or not? If so, I think I'd prefer to add a unit test for either the `as_simple_key_value` function (I'm not exactly sure where this would belong / how to set this up) or create a `fn(&SmolStr) -> &SmolStr` to unit test by factoring out the `trim` operations from `as_simple_key_value`. Thoughts on this? 

6342: Shorter dependency chain r=matklad a=popzxc

Continuing implementing suggestions from the `Completion refactoring` zulip thread.

This PR does the following:

- Removes dependency of `completions` on `assists` by moving required functionality into `ide_db`.
- Moves completely `call_info` crate into `ide_db` as it looks like it fits perfect there.
- Adds a bunch of new tests and docs.
- Adds the re-export of `base_db` to the `ide_db` and removes direct dependency on `base_db` from other crates.

The last point is controversial, I guess, but I noticed that in places where `ide_db` is used, `base_db` is also *always* used. Thus I think the dependency on the `base_db` is implied by the fact of `ide_db` interfaces, and thus it makes sense to just provide `base_db` out of the box.


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
2020-10-24 19:08:12 +00:00
bors[bot]
11e18c31df
Merge #6344
6344: Bump deps r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-24 18:58:02 +00:00
Lukas Wirth
aca2735d1e Support insertion in SyntaxRewriter 2020-10-24 20:53:16 +02:00
Florian Diebold
bc65200105 Fix indentation of inserted use statements 2020-10-24 18:25:23 +02:00
Laurențiu Nicola
c81d044622 Bump chalk 2020-10-24 17:14:05 +03:00
Laurențiu Nicola
4834015fd1 Bump rustc_lexer 2020-10-24 17:11:58 +03:00
Laurențiu Nicola
09468ce370 Bump deps 2020-10-24 17:10:36 +03:00
Igor Aleksanov
19cce08662 Re-export base_db from ide_db 2020-10-24 11:39:57 +03:00
Igor Aleksanov
2c787676c9 Add tests for traits functions in ide_db 2020-10-24 11:29:16 +03:00
Igor Aleksanov
b6ea56ea09 Make call_info a part of ide_db 2020-10-24 11:07:10 +03:00
Igor Aleksanov
8d3d509af7 Remove dependency on 'assists' from 'completion' crate 2020-10-24 10:47:23 +03:00
Arif Roktim
66a1de7d20 Allow assist move_arm_cond_to_match_guard inside blocks 2020-10-24 02:20:45 -04:00
Arif Roktim
0a9ff04270 Don't interpret type path as part of visibility. 2020-10-24 02:20:45 -04:00
Josh Mcguigan
4e76e884bd correct hover for items with doc attribute with raw strings 2020-10-23 19:36:30 -07:00
bors[bot]
2fa942ad30
Merge #6251 #6310
6251: Semantic Highlight: Add Callable modifier for variables r=matklad a=GrayJack

This PR added the `HighlightModifier::Callable` variant and assigned it to variables and parameters that are fn pointers, closures and implements FnOnce trait.

This allows to colorize these variables/parameters when used in call expression.



6310: Rewrite algo::diff to support insertion and deletion r=matklad a=Veykril

This in turn also makes `algo::diff` generate finer diffs(maybe even minimal diffs?) as insertions and deletions aren't always represented as as replacements of parent nodes now.

Required for #6287 to go on.

Co-authored-by: GrayJack <gr41.j4ck@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-23 22:12:15 +00:00
bors[bot]
c483212f27
Merge #6339
6339: Diagnose #[cfg]s in bodies r=matklad a=jonas-schievink

This PR threads diagnostics through body lowering using the `BodySourceMap`, and emits `InactiveCode` diagnostics for expressions, statements, and match arms that are `#[cfg]`d out.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-10-23 22:05:25 +00:00
bors[bot]
ea25ae614b
Merge #6336
6336: Improve Chalk debugging r=matklad a=flodiebold

 - add panic context for the trait goal if CHALK_DEBUG is set
 - print the Chalk program even if we're panicking
 - log goal/solution while TLS is still set

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-10-23 21:54:45 +00:00
Aleksey Kladov
f9b81369e2 Complete variants when only enun name is typed
This allows the client to filter `Foo::Bar` when *either* `Foo` or
`Bar` is typed.
2020-10-23 23:41:47 +02:00
Jonas Schievink
5350c15e27 Fix name of InactiveCode diagnostic 2020-10-23 19:31:11 +02:00
Jonas Schievink
93dc6f511b Diagnose #[cfg]s in bodies 2020-10-23 19:27:04 +02:00
Florian Diebold
baeb16e83f Improve Chalk debugging
- add panic context for the trait goal if CHALK_DEBUG is set
 - print the Chalk program even if we're panicking
 - log goal/solution while TLS is still set
2020-10-23 15:28:02 +02:00
bors[bot]
dd8a75b2cf
Merge #6335
6335: Fix panic context r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-23 13:19:09 +00:00
Aleksey Kladov
1a74f25f90 Fix panic context 2020-10-23 15:18:33 +02:00
bors[bot]
81609960fa
Merge #6324
6324: Improve #[cfg] diagnostics r=jonas-schievink a=jonas-schievink

Unfortunately I ran into https://github.com/rust-analyzer/rust-analyzer/issues/4058 while testing this on https://github.com/nrf-rs/nrf-hal/, so I didn't see much of it in action yet, but it does seem to work.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-10-23 10:38:30 +00:00
Jonas Schievink
a246d4f599 cfg: move tests to separate file
that way we don't have to re-check the entire project when a test is
changed
2020-10-23 12:14:58 +02:00
Jonas Schievink
dab8870f5c Reorder items 2020-10-23 12:12:03 +02:00
Jonas Schievink
bfe1efca26 Use format_to
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-23 12:12:03 +02:00
adamrk
3dbbcfca67 Insert ref for completions 2020-10-22 22:45:14 +02:00
bors[bot]
3d349597fd
Merge #6326
6326: hide paramater inlay hints for cloned vars if applicable r=SomeoneToIgnore a=Veykril

This causes `foo.clone()` parameters to be handled as if they were just `foo` parameters for inlay hint logic.

Fixes #6315 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-22 18:09:43 +00:00
Jonas Schievink
dbd6266bc9
Update crates/cfg/src/cfg_expr.rs
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-22 20:08:27 +02:00
Lukas Wirth
78c3e4a23c Hide paramater inlay hints for cloned vars if applicable 2020-10-22 19:44:52 +02:00
Jonas Schievink
3421b645e6 Emit better #[cfg] diagnostics 2020-10-22 19:19:18 +02:00
Jonas Schievink
978cc93649 Fix typo 2020-10-22 19:19:05 +02:00
Jonas Schievink
68b17986c7 Implement DNF-based #[cfg] introspection 2020-10-22 17:57:00 +02:00
bors[bot]
31db677a94
Merge #6319
6319: Properly identify camel cased acronyms as UpperCamelCase r=popzxc a=ArifRoktim

This closes #6305.

Co-authored-by: Arif Roktim <arifrroktim@gmail.com>
2020-10-22 14:24:10 +00:00
Lukas Wirth
0059188e77 algo::diff tests 2020-10-22 14:48:24 +02:00
bors[bot]
ab53bb8718
Merge #6320 #6321
6320: Textmate grammar: prevent line comments from breaking block comments (closes #6281) r=matklad a=dustypomerleau

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6281.

Previously, line comments were able to break block comments by essentially commenting out the closing `*/`, resulting in a never-ending comment. This PR splits block comments into a separate repository group to fix this problem.

Since the comment scopes also include ignored parameters and inferred types, I've added the change proposed by @bnjjj in https://github.com/rust-analyzer/rust-analyzer/pull/6317, in order to close https://github.com/rust-analyzer/rust-analyzer/issues/6311 as well.

6321: Fix opening module documentation opening parent documentation instead r=matklad a=zacps

The whole path/URL joining code is kind of ugly which is what led to
this, but at the same time I don't really want to rewrite it right
now...

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6286

Co-authored-by: Dusty Pomerleau <dustypomerleau@users.noreply.github.com>
Co-authored-by: Zac Pullar-Strecker <zacmps@gmail.com>
2020-10-22 12:04:50 +00:00
bors[bot]
af75a08116
Merge #6314
6314: generate assist respect cfg attributes  r=matklad a=bnjjj

close #6312

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-22 11:58:11 +00:00
Lukas Wirth
d86863aeb4 Rewrite algo::diff to support insertion and deletion 2020-10-22 09:51:11 +02:00
Benjamin Coenen
f1fda43485 generate_impl assist respect cfg attributes #6312
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-22 09:48:48 +02:00
Zac Pullar-Strecker
68c67efa68 Fix opening module documentation opening parent documentation instead
The whole path/URL joining code is kind of ugly which is what led to
this, but at the same time I don't really want to rewrite it right
now...
2020-10-22 17:33:52 +13:00
Arif Roktim
854b133181 Properly identify camel cased acronyms as UpperCamelCase 2020-10-21 17:10:22 -04:00
bors[bot]
9eb6cbb80b
Merge #6307
6307: Add whitelist of safe intrinsics r=frazar a=frazar

This PR should fix #5996, where intrinsic operations where all marked as unsafe.

I'm rather new to this codebase, so I might be doing something *very* wrong. Please forgive me!

In particular, I'm not sure how to "check that we are in extern `rust-intrinsics`" as mentioned [in this comment](https://github.com/rust-analyzer/rust-analyzer/issues/5996#issuecomment-709234802). 

Co-authored-by: Francesco Zardi <frazar@users.noreply.github.com>
2020-10-21 20:09:11 +00:00
Francesco Zardi
aff04d81ba Refactor is_intrinsic_fn_unsafe() and make it private 2020-10-21 21:53:37 +02:00
Francesco Zardi
0be21b05d6 Move safe intrinsic tests 2020-10-21 21:53:05 +02:00
Francesco Zardi
f3aa44b01d Fix typo in comment 2020-10-21 21:51:53 +02:00
Jonas Schievink
2bc4c1ff31 Simplify cfg representation 2020-10-21 13:57:12 +02:00
Francesco Zardi
a9d996a7c5 Add whitelist of safe intrinsics 2020-10-21 09:06:05 +02:00
GrayJack
a35ff6edf4
Add tests for callable modifier 2020-10-21 01:54:51 -03:00
Jeremy Kolb
f64f569483 Update crates
This brings in a number of new dependencies though.
2020-10-20 17:36:02 -04:00
Benjamin Coenen
aa031e91f4 add completions for clippy lint in attributes
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-20 21:29:31 +02:00
bors[bot]
c00339509d
Merge #6256
6256: Assist: replace string with char r=bnjjj a=bnjjj

close #6252 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2020-10-20 19:03:25 +00:00
Coenen Benjamin
9883435e4e
Update crates/assists/src/handlers/replace_string_with_char.rs
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-20 20:07:39 +02:00
bors[bot]
989de9e309
Merge #6172
6172: Add qualify path assist r=matklad a=Veykril

This implements a `qualify_path` assist which works quite similar to the `auto_import` assist but instead of adding imports to the file it well, qualifies the path. This PR also moves out the `AutoImportAssets` struct and functions from `auto_import` into a utils submodule as most of this is now shared between `auto_import` and `qualify_path`.

Changes made to `AutoImportAssets` are solely in its `search_for_imports` function which now takes a prefixed parameter to discern between using `find_use_path_prefixed` and `find_use_path` as the former is the required behavior by `auto_import` and the latter by this assist.

For missing imported traits instead of importing this will qualify the path with a trait cast as in:
```rust
test_mod::TestStruct::TEST_CONST<|>
```
becomes
```rust
<test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST
```

and for trait methods ideally it would do the following:
```rust
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
```
becomes
```rust
let test_struct = test_mod::TestStruct {};
test_mod::TestTrait::test_method(&test_struct)
```

Fixes #4124.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-20 17:03:19 +00:00
bors[bot]
20d369a826
Merge #6299
6299: Diagnose items that are #[cfg]d out r=jonas-schievink a=jonas-schievink

This emits a hint-level diagnostic with `Unnecessary` tag to "gray out" any items whose `#[cfg]` attributes remove the item before name resolution.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-10-20 16:35:05 +00:00
Jonas Schievink
74ac83a5ac Fixup botched rename 2020-10-20 18:29:47 +02:00
Jonas Schievink
3fa04f35d2 More detailed message 2020-10-20 18:23:55 +02:00
Jonas Schievink
4cb3cf352f Rename UnconfiguredCode -> InactiveCode 2020-10-20 18:22:31 +02:00
Aleksey Kladov
a3a8ad8bc4 Don't rely on display names in inlay_hints 2020-10-20 18:14:14 +02:00
Jonas Schievink
80d2741401 Add a (hint) diagnostic for unconfigured items 2020-10-20 17:53:04 +02:00
Jonas Schievink
a54e481646 Simplify diagnostic construction, add unused field 2020-10-20 17:53:04 +02:00
Aleksey Kladov
f753c3ecd2 Support Display name in project.json 2020-10-20 17:13:15 +02:00
Aleksey Kladov
3b1a648539 More type safety around names 2020-10-20 17:09:03 +02:00
Aleksey Kladov
a85c4280bf Introduce CrateDisplayName 2020-10-20 16:00:51 +02:00
Benjamin Coenen
c22c039578 Assist: replace string with char
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-20 15:57:50 +02:00
Aleksey Kladov
af4e75533f Rename declaration_name -> display_name
Declaration names sounds like a name of declaration -- something you
can use for analysis. It empathically isn't, and is just a label
displayed in various UI. It's important not to confuse the two, least
we accidentally mix semantics with UI (I believe, there's already a
case of this in the FamousDefs at least).
2020-10-20 15:38:11 +02:00
bors[bot]
be762ccccd
Merge #6294
6294: Add a hacky remidy for #6038 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-20 10:36:28 +00:00
Aleksey Kladov
7a21e9302e Add a hacky remidy for #6038
The proper fix I think is:

* move rust-lang/rust library crates to a separate workspace
* when packaging rust-src component, vendor sources of external deps
2020-10-20 12:34:39 +02:00
Igor Aleksanov
2a20e7795c Add descriptions for diagnostics parseable by xtask 2020-10-19 20:55:16 +03:00
Aleksey Kladov
4fbb602b2d Minor, rename feature 2020-10-19 15:53:48 +02:00
Aleksey Kladov
8421115354 Try to fix publishing
This errro specifically:

Updating crates.io index
	 error: failed to select a version for the requirement `ra_ap_stdx = "^0.0.0"`
	 candidate versions found which didn't match: 0.0.20
	 location searched: /home/runner/work/rust-analyzer/rust-analyzer/crates/stdx
	 required by package `ra_ap_completion v0.0.20 (/home/runner/work/rust-analyzer/rust-analyzer/crates/completion)`
	 error: unable to update Cargo.lock
	 Error: Process completed with exit code 1.
2020-10-19 15:18:28 +02:00
Aleksey Kladov
604caedeb2 Change visibility works for type aliases 2020-10-18 17:04:12 +02:00
Igor Aleksanov
9e7c952bbd Extract call_info and completion into separate crates 2020-10-18 13:09:00 +03:00
Aleksey Kladov
6c7769a2e3 update deps 2020-10-18 01:53:01 +02:00
Aleksey Kladov
13451d3dc4 Complete methods when receiver is a macro 2020-10-17 23:43:13 +02:00
Aleksey Kladov
4fe4c30436 Improve readability 2020-10-17 23:35:21 +02:00
Igor Aleksanov
99c435939c Scan all ancestors for the impl trait block check 2020-10-17 11:17:58 +03:00
Igor Aleksanov
6f573bd84f Allow hints after 'fn' keyword if it's an impl trait block 2020-10-17 11:03:07 +03:00
Igor Aleksanov
8f303daf45 Add test for new pattern functions 2020-10-17 10:56:00 +03:00
Igor Aleksanov
6ae4c70a0a Improve test_no_completions_required test 2020-10-17 10:47:35 +03:00
Igor Aleksanov
70157f07d9 Remove redundant completions 2020-10-17 10:27:59 +03:00
Benjamin Coenen
62192cede3 replace_string_with_char #6252
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-16 20:21:16 +02:00
Lukas Wirth
1d612a6ec4 De-duplicate add_group callsite in qualify_path 2020-10-16 16:04:00 +02:00
bors[bot]
1af6275f20
Merge #6246
6246: Follow symlinks when walking project trees r=lnicola a=dfoxfranke

Fixes #3691.

~~WIP pending further testing~~:

- [X] Verify that symlinked files get indexed.
- [x] Verify that files in symlinked directories get indexed.
- [x] Verify that inotify events are properly received and handled when the target of a symlink resides outside the project tree.

Co-authored-by: Daniel Fox Franke <dfoxfranke@gmail.com>
2020-10-16 12:53:10 +00:00
GrayJack
a483b5545d
Add Callable modifier for variables that implements Fnonce 2020-10-16 07:52:18 -03:00
GrayJack
83d6bc7113
Add HighlightModifier::Callable and add it for locals 2020-10-16 06:38:32 -03:00
Daniel Fox Franke
e821aa842b Follow symlinks when walking project trees
Fixes #3691
2020-10-15 14:22:36 -04:00
bors[bot]
0d45802d67
Merge #6220
6220: implement binary operator overloading type inference r=flodiebold a=ruabmbua

Extend type inference of *binary operator expression*, by adding support for operator overloads.

Before this merge request, the type inference of binary expressions could only resolve operations done on built-in primitive types. This merge requests adds a code path, which is executed in case the built-in inference could not get any results. It resolves the proper operator overload trait in *core::ops* via lang items, and then resolves the associated *Output* type.

```rust
struct V2([f32; 2]);

#[lang = "add"]
pub trait Add<Rhs = Self> {
    /// The resulting type after applying the `+` operator.
    type Output;

    /// Performs the `+` operation.
    #[must_use]
    fn add(self, rhs: Rhs) -> Self::Output;
}

impl Add<V2> for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}

fn test() {
    let va = V2([0.0, 1.0]);
    let vb = V2([0.0, 1.0]);

    let r = va + vb; // This infers to V2 now
}
```

There is a problem with operator overloads, which do not explicitly set the *Rhs* type parameter in the respective impl block. 

**Example:**

```rust
impl Add for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}
```

In this case, the trait solver does not realize, that the *Rhs* type parameter is actually self in the context of the impl block. This stops type inference in its tracks, and it can not resolve the associated *Output* type.

I guess we can still merge this back, because it increases the amount of resolved types, and does not regress anything (in the tests).

Somewhat blocked by https://github.com/rust-analyzer/rust-analyzer/issues/5685
Resolves  https://github.com/rust-analyzer/rust-analyzer/issues/5544

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-10-15 18:02:27 +00:00
Lukas Wirth
bc11475a2a Properly qualify trait methods in qualify_path assist 2020-10-15 18:31:33 +02:00
Aleksey Kladov
c5868a4879 Clarify the names one more time 2020-10-15 17:38:51 +02:00
Aleksey Kladov
56e67e3a39 More idiomatic classification API 2020-10-15 17:38:17 +02:00
Aleksey Kladov
f9c1336873 More clarifications 2020-10-15 17:37:55 +02:00
Aleksey Kladov
bc287b8f9b Unconfuse expression and pattern field init shorthands 2020-10-15 17:37:36 +02:00
Aleksey Kladov
fa3c449d8f Clarify NameClass names a bit 2020-10-15 17:37:36 +02:00
bors[bot]
7fadc78ebb
Merge #6242
6242: Diagnost shorthand in patterns r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 15:11:36 +00:00
Aleksey Kladov
3086fb2ef4 Move field_shorthand to a separate module 2020-10-15 17:10:06 +02:00
Aleksey Kladov
1022672af0 Diagnose shorthand in patterns as well 2020-10-15 17:03:52 +02:00
Aleksey Kladov
e9903a91cd flatten 2020-10-15 16:51:55 +02:00
Aleksey Kladov
c8cbd398e4 Prepare for pat_field_shorthand 2020-10-15 16:48:25 +02:00
bors[bot]
8090799aa2
Merge #6234
6234: Fix hover over field pattern shorthand r=matklad a=Vlad-Shcherbina

Instead of the information about the field, it now shows the information
about the local.

Fixes #6146

Co-authored-by: Vlad Shcherbina <vlad.shcherbina@gmail.com>
2020-10-15 13:09:27 +00:00
Lukas Wirth
f8a7cc678d Document auto_import as a feature 2020-10-15 14:57:19 +02:00
bors[bot]
3a38554f86
Merge #6231
6231: Factor macro_rules and format-string highlighting out into submodules r=Veykril a=Veykril

This moves `format`-like macro string highlighting and macro_rules highlight skipping out of the main module.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-14 20:52:41 +00:00
Lukas Wirth
bab29e65eb Default::default the highlighters 2020-10-14 22:50:26 +02:00
Vlad Shcherbina
e6fbb94edd Fix hover over field pattern shorthand
Instead of the information about the field, it now shows the information
about the local.

Fixes #6146
2020-10-14 21:22:00 +03:00
Lukas Wirth
d983f18df7 Add mark tests to qualify_path assist 2020-10-14 20:04:57 +02:00
Lukas Wirth
9f41f074be Add qualify path assist 2020-10-14 19:56:20 +02:00
Lukas Wirth
8c6dc5f28a Factor macro_rules! highlighting out 2020-10-14 19:23:59 +02:00
Lukas Wirth
df87be88d8 Factor format string highlighting out 2020-10-14 19:23:45 +02:00
Roland Ruckerbauer
0e9d1e17d6 binary operator overload type inference: add test mark 2020-10-14 19:00:04 +02:00