Commit graph

595 commits

Author SHA1 Message Date
oxalica
455b418263
Update tests 2021-03-16 01:24:26 +08:00
oxalica
7c855c940a
Clean usage of ShortLabel 2021-03-16 01:05:56 +08:00
oxalica
87171238c6
Use hir formatter more 2021-03-16 01:04:33 +08:00
oxalica
ef416e0154
Impl HirDisplay for function hover message 2021-03-16 01:04:20 +08:00
oxalica
ef48d1ca3b
Add test for hover of macro expanded function 2021-03-16 01:01:24 +08:00
bors[bot]
5f6d71cf0c
Merge #8029
8029: Enable thread-local coverage marks r=JoshMcguigan a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-15 14:42:26 +00:00
bors[bot]
f2c39d0cdf
Merge #8020
8020: Power up goto_implementation r=matklad a=Veykril

by allowing it to be invoked on references of names, now showing all (trait)
implementations of the given type in all crates instead of just the defining
crate as well as including support for builtin types

![image](https://user-images.githubusercontent.com/3757771/111144403-52bb0700-8587-11eb-9205-7a2a5b8b75a3.png)
Example screenshot of `impl`s of Box in `log`, `alloc`, `std` and the current crate. Before you had to invoke it on the definition where it would only show the `impls` in `alloc`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 14:08:26 +00:00
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
bors[bot]
b245e8d115
Merge #8015
8015:  Introduce Semantics::visit_file_defs r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/issues/3538#issuecomment-798920601

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 13:18:26 +00:00
Aleksey Kladov
af2366acdf Goto definition works for S { a: } case
What happens here is that we lower `: ` to a missing expression, and
then correctly record that the corresponding field expression resolves
to a specific field. Where we fail is in the mapping of syntax to this
missing expression. Doing it via `ast_field.expr()` fails, as that
expression is `None`. Instead, we go in the opposite direcition and ask
each lowered field about its source.

This works, but has wrong complexity `O(N)` and, really, the
implementation is just too complex. We need some better management of
data here.
2021-03-15 15:12:39 +03:00
Lukas Wirth
41745f48d5 move Semantics::visit_file_defs to ide_db::helpers 2021-03-15 12:18:52 +01:00
Lukas Wirth
a1c96e04be Introduce Semantics::visit_file_defs 2021-03-15 12:14:34 +01:00
Lukas Wirth
6c782a5314 Power up goto_implementation
by allowing it to be invoked on references of names, showing all (trait)
implementations of the given type in all crates including builtin types
2021-03-15 12:10:18 +01:00
bors[bot]
5138baf2ac
Merge #8021 #8022
8021: Enable searching for builtin types r=matklad a=Veykril

Not too sure how useful this is for reference search overall, but for completeness sake it should be there 
![image](https://user-images.githubusercontent.com/3757771/111132711-f69db600-8579-11eb-8c90-22fd6862d11f.png)

Also enables document highlighting for them.


8022: some clippy::performance fixes r=matklad a=matthiaskrgr

use vec![] instead of Vec::new() + push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unnecessary resizing

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-15 10:05:49 +00:00
Aleksey Kladov
5dcdf2ceee Move code to the appropriate layer
StructureNodeKind is a type which is specific to a particular feature,
file_structure. It shouldn't be in the "code shared by all ide features"
part.
2021-03-15 12:55:27 +03:00
bors[bot]
cec676d082
Merge #7975
7975: Provide regions in file structure r=ivan770 a=ivan770

Closes #7913 

https://user-images.githubusercontent.com/14003886/110819163-96b3c080-8296-11eb-993e-a7cdb574a12d.mp4



Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-03-15 09:26:58 +00:00
Matthias Krüger
cad617bba0 some clippy::performance fixes
use vec![] instead of Vec::new() +  push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unneccessary resizing
2021-03-15 10:19:59 +01:00
Lukas Wirth
9763d9e8c4 Enable searching for builtin types 2021-03-15 09:32:06 +01:00
bors[bot]
de36027541
Merge #7966
7966: Diagnose files that aren't in the module tree r=jonas-schievink a=jonas-schievink

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

I'm not sure if this is the best way to do this. It will cause false positives for all `include!`d files (though I'm not sure how much IDE functionality we have for these).

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-15 01:23:29 +00:00
Jonas Schievink
32e1ca54ea Add module comment 2021-03-15 02:23:00 +01:00
Jonas Schievink
40638b16c8 Use pub(crate) 2021-03-15 01:46:59 +01:00
Jonas Schievink
8b4cbbb87c Redo it properly and add a quickfix 2021-03-15 01:39:41 +01:00
Lukas Wirth
f2610cbd7e Don't drop type params in doc-test paths 2021-03-14 20:38:26 +01:00
ivan770
7d48e04f31
Introduce StructureNodeKind 2021-03-14 19:00:41 +02:00
ivan770
8602f9573b
Added region intersection test 2021-03-14 18:53:40 +02:00
ivan770
56ca843695
Shorten trim call 2021-03-14 18:53:40 +02:00
ivan770
71a97a2d8c
Provide regions in file structure 2021-03-14 18:53:37 +02:00
bors[bot]
7accf6bc37
Merge #7799
7799: Related tests r=matklad a=vsrs

![tests](https://user-images.githubusercontent.com/62505555/109397453-a9013680-7947-11eb-8b11-ac03079f7645.gif)
This adds an ability to look for tests for the item under the cursor: function, constant, data type, etc

The LSP part is bound to change. But the feature itself already works and I'm looking for a feedback :)



Co-authored-by: vsrs <vit@conrlab.com>
2021-03-13 13:50:35 +00:00
Josh Mcguigan
9ee3914c61 remove unused CompletionScore enum 2021-03-12 06:16:04 -08:00
Josh Mcguigan
3679821eea add completion relevance score 2021-03-12 06:16:01 -08:00
vsrs
00e52e1f42 Add Feature: Related Tests comment 2021-03-11 17:58:45 +03:00
vsrs
daa2637486 Apply review suggestions 2021-03-11 17:39:41 +03:00
Lukas Wirth
98d2dbb90e Return original text range in PrepareRename responses when inside macro 2021-03-10 22:26:41 +01:00
Jonas Schievink
7b1a0d5fb7 Diagnose files that aren't in the module tree 2021-03-10 20:30:20 +01:00
bors[bot]
83280ea574
Merge #7958
7958: Avoid double text edits when renaming mod declaration r=matklad a=Veykril

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

See https://github.com/microsoft/vscode-languageserver-node/issues/752 for context

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-10 15:07:46 +00:00
Lukas Wirth
3af69b5359 Avoid double text edits when renaming mod declaration 2021-03-10 15:49:01 +01:00
Josh Mcguigan
09307be75b add apply ssr assist 2021-03-10 06:02:15 -08:00
Aleksey Kladov
842d8ad9c8 Compilation speed 2021-03-09 22:30:58 +03:00
Lukas Wirth
814d617d34 Show whether a binding is mutable or not on hover 2021-03-09 17:18:50 +01:00
Lukas Wirth
983726a45c Don't show const items initializer expressions on hover 2021-03-09 16:33:23 +01:00
Kirill Bulatov
33c83e72b9 Work towards better import labels 2021-03-08 23:59:20 +02:00
Laurențiu Nicola
fc9eed4836 Use upstream cov-mark 2021-03-08 22:19:44 +02:00
Laurențiu Nicola
42057896bc Fix some warnings 2021-03-05 15:59:50 +02:00
Lukas Wirth
e194f2edc4 Prevent renaming SelfType and BuiltinType 2021-03-03 19:48:53 +01:00
Lukas Wirth
183ba483a9 Reorder functions in rename.rs 2021-03-03 19:48:35 +01:00
bors[bot]
f8152171bb
Merge #7850
7850: Don't add space when joining line to opening quote r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-02 14:19:45 +00:00
Aleksey Kladov
e2fc9411f1 Don't add space when joining line to opening quote 2021-03-02 17:18:45 +03:00
bors[bot]
6a585c6ee2
Merge #7795
7795: Show docs on hover for keywords and primitives r=matklad a=Veykril

![lAWFadkziX](https://user-images.githubusercontent.com/3757771/109369534-eeb4f500-789c-11eb-8f2b-2f9c4e129de3.gif)

It's a bit annoying that this requires the `SyntaxNode` and `Semantics` to be pulled through `hover_for_definition` just so we can get the `std` crate but I couldn't think of a better way.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-02 13:46:50 +00:00
Lukas Wirth
8d305680e6 Show docs on hover for keywords and primitives 2021-03-02 14:41:01 +01:00
bors[bot]
657ec3616f
Merge #7335 #7691
7335: added region folding r=matklad a=LucianoBestia

Regions of code that you'd like to be folded can be wrapped with  `// #region` and `// #endregion` line comments.
This is called "Region Folding". It is originally available for many languages in VSCode. But Rust-analyzer has its own folding function and this is missing.
With this Pull Request I am suggesting a simple solution. 
The regions are a special kind of comments, so I added a bit of code in the comment folding function.
The regex to match are: `^\s*//\s*#?region\b` and `^\s*//\s*#?endregion\b`.
The number of space characters is not important. There is an optional # character. The line can end with a name of the region.
Example:
```rust
// 1. some normal comment
// region: test
// 2. some normal comment
calling_function(x,y);
// endregion: test
```
I added a test for this new functionality in `folding_ranges.rs`.
Please, take a look and comment. 
I found that these exact regexes are already present in the file `language-configuration.json`, but I don't find a way to read this configuration. So my regex is hardcoded in the code.

7691: Suggest name in extract variable r=matklad a=cpud36

Generate better default name in extract variable assist as was mentioned in issue #1587

# Currently supported
(in order of declining precedence)
1. Expr is argument to a function; use corresponding parameter name
2. Expr is result of a function or method call; use this function/method's name
3. Use expr type name (if possible)
4. Fallback to `var_name` otherwise

# Showcase

![generate_derive_variable_name_from_method](https://user-images.githubusercontent.com/4218373/108013304-72105400-701c-11eb-9f13-eec52e74d0cc.gif)
![generate_derive_variable_name_from_param](https://user-images.githubusercontent.com/4218373/108013305-72a8ea80-701c-11eb-957e-2214f7f005de.gif)

# Questions

* Should we more aggressively strip known types? E.g. we already strip `&T -> T`; should we strip `Option<T> -> T`, `Result<T, E> -> T`, and others?
* Integers and floats use `var_name` by default. Should we introduce a name, like `i`, `f` etc?
* Can we return a list and suggest a name when renaming(like IntelliJ does)?
* Should we add counters to remove duplicate variables? E.g. `type`, `type1`, type2`, etc.


Co-authored-by: Luciano Bestia <LucianoBestia@gmail.com>
Co-authored-by: Luciano <31509965+LucianoBestia@users.noreply.github.com>
Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
2021-03-02 13:32:06 +00:00