Commit graph

9156 commits

Author SHA1 Message Date
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
Aleksey Kladov
1b3b8c7fda Log around sysroot discovery 2020-10-14 17:22:07 +02:00
Laurențiu Nicola
8cc175ee9b Add docs for dbgr and call 2020-10-14 16:23:51 +03:00
bors[bot]
3e450cf89f
Merge #6207 #6224 #6226 #6227
6207: Extract ImportAssets out of auto_import r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/pull/6172#issuecomment-707182140

I couldn't fully pull out `AssistContext` as `find_node_at_offset_with_descend`: 81fa00c5b5/crates/assists/src/assist_context.rs (L90-L92) requires the `SourceFile` which is private in it and I don't think making it public just for this is the right call?

6224: ⬆️ salsa r=matklad a=matklad

bors r+
🤖

6226: Add reminder to update lsp-extensions.md r=matklad a=matklad

bors r+
🤖

6227: Reduce bors timeout r=matklad a=matklad

bors r+
🤖

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 11:37:51 +00:00
Aleksey Kladov
41e2639f35 ⬆️ salsa 2020-10-14 12:40:48 +02:00
bors[bot]
b62f48f535
Merge #6217
6217: Bump pulldown-cmark r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-14 10:26:13 +00:00
Lukas Wirth
03b77b03fe Fix stackoverflow in insert_use::recursive_merge 2020-10-14 01:43:56 +02:00
Roland Ruckerbauer
4e49b2f731 Implement binary operator overloading type inference 2020-10-13 20:48:08 +02:00
Lukas Wirth
01b410c69a Slightly cleanup import_assets module 2020-10-13 20:02:14 +02:00
Laurențiu Nicola
e559066bed Bump pulldown-cmark 2020-10-13 20:41:49 +03:00
Lukas Wirth
02b844e9fb Adhere to style guidelines in import_assets 2020-10-13 18:58:37 +02:00
Lukas Wirth
256104d78e Extract ImportAssets out of auto_import 2020-10-13 18:58:37 +02:00
bors[bot]
0fb069c5b0
Merge #6216
6216: Bump deps r=matklad a=lnicola



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

Resolves #4598.

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

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

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

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

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

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

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

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

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

## Example:

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

Fixes #4380.

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

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

Fixes #5461

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

#### Todo

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


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

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

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



Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-09 23:16:19 +00:00
Jonas Schievink
5dcbf03d0f adt: correctly inherit field visibility from enum
Previously, "find all references" on a variant field wouldn't find any
references outside the defining module. This is because variant fields
were incorrectly assumed to be private, like struct fields without
explicit visibility, but they actually inherit the enum's visibility.
2020-10-09 20:46:45 +02:00
Jonas Schievink
210456aeaa Treat ast::Name in field patterns as use 2020-10-09 19:56:54 +02:00
Jonas Schievink
55ecfbb99b
Update crates/project_model/src/sysroot.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-10-09 16:17:05 +02:00
Jonas Schievink
7d0772e796 Add note if RUST_SRC_PATH is likely to be wrong 2020-10-09 16:11:16 +02:00
Jonas Schievink
468b804856 Fix source_to_def for named enum variant fields 2020-10-09 02:57:35 +02:00
Benjamin Coenen
3bfa3e8123 when generating new function, focus on return type instead of body
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-08 20:57:18 +02:00
Benjamin Coenen
36459284c7 add eprintln in fmt-like postfix
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-08 20:53:39 +02:00
kjeremy
13bb0404a8 Bump rustc_lexer, cfg-if to 1.0 and add new license to check 2020-10-08 10:39:02 -04:00
bors[bot]
e6a05e6566
Merge #5651
5651: Add track_env_var to the proc macro server r=kjeremy a=lnicola

See https://github.com/rust-lang/rust/pull/74653.

Fixes #6054.
Fixes #5640, maybe.

Should be merged when 1.47 is released.

Proc macros still don't work for me, but it no longer crashes.



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-08 14:27:30 +00:00
Laurențiu Nicola
3d169bd3f4 Add track_env_var to the proc macro server 2020-10-08 17:06:20 +03:00
Zac Pullar-Strecker
3bd4fe96dc Remove methodowner & fix formatting 2020-10-08 15:50:48 +13:00
Zac Pullar-Strecker
8af1dd7337 Rebase fixes 2020-10-08 15:22:57 +13:00
Zac Pullar-Strecker
d2c68809ea Changes from review 2020-10-08 15:05:24 +13:00
Zac Pullar-Strecker
e4a787fcbc Remove outdated part of doc_links module docs 2020-10-08 15:05:23 +13:00
Zac Pullar-Strecker
f6759ba3bb Add ignored test to demonstrate ImportMap bug 2020-10-08 15:05:23 +13:00
Zac Pullar-Strecker
6cae6b8f3c Fix namespace detection & function test 2020-10-08 15:04:57 +13:00
Zac Pullar-Strecker
37a4d060a7 Add tests 2020-10-08 15:04:57 +13:00
Zac Pullar-Strecker
ec75d8bd75 Update tests for new function field 2020-10-08 15:04:57 +13:00
Zac Pullar-Strecker
26086faab2 Change Option::Some bug to a fixme note
IMO this is too much work to be worth fixing at the moment.
2020-10-08 15:04:57 +13:00
Zac Pullar-Strecker
c648884397 Differentiate method/tymethod by determining 'defaultness'
Currently a method only has defaultness if it is a provided trait
method, but this will change when specialisation is available and may
need to become a concept known to hir.

I opted to go for a 'fewest changes' approach given specialisation is
still under development.
2020-10-08 15:04:21 +13:00
Zac Pullar-Strecker
974518fde7 Code reorganisation and field support 2020-10-08 15:04:20 +13:00
Zac Pullar-Strecker
a14194b428 Changes from review 2020-10-08 15:01:30 +13:00
Zac Pullar-Strecker
8c32bdea36 Rename ide::link_rewrite -> ide::doc_links & tidy imports 2020-10-08 15:01:30 +13:00
Zac Pullar-Strecker
a06d736b77 Add support for struct & trait methods 2020-10-08 14:59:31 +13:00
Zac Pullar-Strecker
bfda0d2583 WIP: Command to open docs under cursor 2020-10-08 14:59:31 +13:00
bors[bot]
e95e666b10
Merge #6161
6161: Bump chalk to use latest git to get upstream fix r=jonas-schievink a=Ameobea

 * Chalk very recently (like an hour ago) merged a fix that prevents rust analyzer from panicking.  This allows it to be usable again for code that hits those situations.  See #6134, #6145, Probably #6120

Co-authored-by: Casey Primozic <me@ameo.link>
2020-10-07 20:46:33 +00:00
Casey Primozic
37df2138ec
Switch from git to latest tagged release of chalk deps 2020-10-07 12:11:22 -07:00
bors[bot]
83a651b123
Merge #6154
6154: Shorten type hints for std::iter Iterators r=SomeoneToIgnore a=Veykril

Fixes #3750.

This re-exports the `hir_expand::name::known` module to be able to fetch the `Iterator` and `iter` names.
I'm not sure if there is anything to do with `Solution::Ambig` in `normalize_trait_assoc_type` or whether discarding those results is always wanted.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-07 11:52:05 +00:00
Lukas Wirth
783af171f7 Clean up inlay_hints 2020-10-07 13:18:12 +02:00
Aleksey Kladov
6219142c96 Better progress API
Percentage is a UI concern, the physical fact here is fraction. It's
sad that percentage bleeds into the protocol level, we even duplicated
this bad API ourselves!
2020-10-07 12:15:37 +02:00
Lukas Wirth
e106857e80 Shorten iterator hints for std::iter iterators behind references 2020-10-07 12:14:08 +02:00
Aleksey Kladov
fd8622e1ec Cleanup 2020-10-07 11:55:20 +02:00
bors[bot]
faddea9353
Merge #6158
6158: Fix for negative literals in macros r=matklad a=cutsoy

_This pull request fixes #6028._

When writing `-42.0f32` in Rust, it is usually parsed as two different tokens (a minus operator and a float literal).

But a procedural macro can also generate new tokens, including negative [float literals](https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.f32_suffixed):

```rust
#[proc_macro]
fn example_verbose(input: TokenStream) -> TokenStream {
    let literal = Literal::f32_suffixed(-42.0);
    quote! { #literal }
}
```

or even shorter

```rust
#[proc_macro]
fn example(input: TokenStream) -> TokenStream {
    let literal = -42.0f32;
    quote! { #literal }
}
```

Unfortunately, these currently cause RA to crash:

```
thread '<unnamed>' panicked at 'Fail to convert given literal Literal {
    text: "-42.0f32",
    id: TokenId(
        4294967295,
    ),
}', crates/mbe/src/subtree_source.rs:161:28
```

This pull request contains both a fix 8cf9362 and a unit test 27798ee. In addition, I installed the patched server with `cargo xtask install --server` and verified in VSCode that it no longer crashes when a procedural macro returns a negative number literal.

Co-authored-by: Tim <tim@glacyr.com>
2020-10-07 09:32:47 +00:00
Lukas Wirth
209e9b9926 Shorten iterator chain hints 2020-10-07 11:30:42 +02:00
bors[bot]
a184c83535
Merge #6160
6160: Add validation check for ambiguous trait objects r=matklad a=Veykril

Fixes #285.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-07 09:12:09 +00:00
Lukas Wirth
c133651e0a Move IntoIterator into FamousDefs 2020-10-07 10:14:42 +02:00
Casey Primozic
13bdadb515
Make unimplemented match variants explicit 2020-10-06 23:56:31 -07:00
Casey Primozic
f40e86e141
todo!() -> unimplemented!() // FIXME for CI 2020-10-06 15:19:34 -07:00
Casey Primozic
56a8a7645f
Bump chalk to use latest git to get fix
* Chalk very recently (like an hour ago) merged a fix that prevents rust analyzer from panicking.  This allows it to be usable again for code that hits those situations.  See #6134, #6145, Probably #6120
2020-10-06 15:05:20 -07:00
Lukas Wirth
6f38552edb Add validation check for ambiguous trait objects 2020-10-06 23:52:00 +02:00
Tim
27798ee575
Added unit test for negative number literals in macros. 2020-10-06 22:28:13 +02:00
Tim
8cf9362984
Fixed parsing of negative number literals in macros. 2020-10-06 22:28:13 +02:00
Lukas Wirth
c6f1de6ac5 Use FamousDefs for shorten_iterator hint 2020-10-06 21:25:39 +02:00
bors[bot]
bf1043cac2
Merge #6128
6128: Trim all trailing whitespace in onEnter r=matklad a=repnop

Fixes #5848

Co-authored-by: Wesley Norris <repnop@outlook.com>
2020-10-06 18:17:49 +00:00
Aleksey Kladov
d7991f5f21 Document privacy invariant of SyntaxPtr 2020-10-06 20:06:14 +02:00
bors[bot]
57735f2a32
Merge #6140
6140: honour hover.content_format client capability r=lnicola a=robinvd

This removes all markdown when the client does not support the markdown MarkupKind.

Otherwise the output on the editor will have some markdown boilerplate, making it less readable.

For example kak_lsp does not currently support markdown.
![image](https://user-images.githubusercontent.com/22073483/95112949-ef0ff080-0741-11eb-82a7-0594fa2cd736.png)

after:
![image](https://user-images.githubusercontent.com/22073483/95113089-2bdbe780-0742-11eb-94fa-bcfec6d7347a.png)



Co-authored-by: Robin van Dijk <robin@robinjint.nl>
2020-10-06 17:51:20 +00:00
Aleksey Kladov
801e5b453c Add test makr 2020-10-06 19:20:56 +02:00