Commit graph

10555 commits

Author SHA1 Message Date
Lukas Wirth
34464ede3f Fix associated items not being appended to paths in import_assets 2021-03-18 21:36:52 +01:00
bors[bot]
b70bea0d79
Merge #8083
8083: Track source file IDs in source mapping of Attrs r=jonas-schievink a=Veykril

Fixes the panics/incorrect injection highlighting of outline module declarations until we figure out a nicer source mapping strategy for attributes.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-18 19:26:10 +00:00
bors[bot]
f57ce6f558
Merge #8094
8094: Fix infinite recursion when computing diagnostics for inner items r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-18 19:16:05 +00:00
Jonas Schievink
ebd4c8c5df Fix infinite recursion when computing diagnostics for inner items 2021-03-18 20:15:06 +01:00
Jonas Schievink
6489e5b785 Add test 2021-03-18 20:04:20 +01:00
Jonas Schievink
268f45a099 Record custom derive helpers in DefMap
Also clean up proc macro attribute parsing a bit
2021-03-18 19:56:37 +01:00
Jonas Schievink
4390125314 Add test for goto def on proc macro invocation 2021-03-18 17:24:17 +01:00
Jonas Schievink
c05a1a6e37 Store an AstId for procedural macros 2021-03-18 16:11:18 +01:00
Jonas Schievink
b84efbaacf Make MacroDefId's AstId mandatory when possible 2021-03-18 15:37:14 +01:00
Jonas Schievink
4cf36545e6 Create AstId for builtin_derive macro in tests 2021-03-18 15:14:52 +01:00
bors[bot]
d3da042a62
Merge #8082
8082: Proper handle inner recursive macro rules cases r=edwin0cheng a=edwin0cheng

Fixes #7645

cc @jonas-schievink 

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-18 12:25:44 +00:00
Edwin Cheng
13f30e9ef5 Handle inner recursive macro rules cases 2021-03-18 20:19:15 +08:00
Lukas Wirth
d41a1690d2 Track source file IDs in source mapping of Attrs 2021-03-18 13:16:27 +01:00
bors[bot]
80d497e541
Merge #8081
8081: Reorganize mbe tests r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-18 09:23:54 +00:00
Edwin Cheng
49b876de09 Reorganize mbe tests 2021-03-18 17:22:52 +08:00
ivan770
f62944f416
Remove prioritization, add more movable items 2021-03-18 11:22:28 +02:00
ivan770
b67a91b960
Fix code after rowan version bump 2021-03-18 11:22:28 +02:00
ivan770
a154ef7ca1
Remove movable array, improve client code 2021-03-18 11:22:27 +02:00
ivan770
7d60458495
Item up and down movers 2021-03-18 11:22:27 +02:00
Jonas Schievink
5fbb97a0f0 Rename item_tree query to file_item_tree 2021-03-18 01:53:37 +01:00
Jonas Schievink
759f8c83e5 Make ItemTreeId its own type 2021-03-18 01:53:22 +01:00
Jonas Schievink
b5cb2829a4 Avoid cloning CfgOptions 2021-03-18 01:41:38 +01:00
Jonas Schievink
94b3b32c98 Support #[cfg] on all associated items 2021-03-18 01:28:55 +01:00
bors[bot]
62c059ea74
Merge #8076
8076: Add test for self-calling inner function r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/4438 (and duplicates)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-17 21:33:41 +00:00
Jonas Schievink
a85b32abdc Add test for self-calling inner function 2021-03-17 22:30:09 +01:00
bors[bot]
afcc0da3a1
Merge #8075
8075: Fix `use crate as <name>;` imports r=jonas-schievink a=jonas-schievink

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

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-17 21:25:25 +00:00
Jonas Schievink
a54564378b Fix use crate as <name>; imports 2021-03-17 22:24:51 +01:00
Jonas Schievink
5f80364ede Improve diagnostic when including nonexistent file 2021-03-17 21:56:09 +01:00
Jonas Schievink
c64adfe706 Use first early expansion error during nameres 2021-03-17 21:41:32 +01:00
Lukas Wirth
9763f0a6bd Semantic highlight intradoclinks in documentation 2021-03-17 21:00:01 +01:00
bors[bot]
ec10835d60
Merge #8069
8069: Inject highlight into block doc comments r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 18:20:25 +00:00
Lukas Wirth
37964f9fef Inject highlight into block doc comments 2021-03-17 19:12:28 +01:00
Jonas Schievink
9436436d20 Improve test 2021-03-17 18:35:17 +01:00
Jonas Schievink
ba0e4c745d Apply #[cfg]s when computing function signatures 2021-03-17 18:28:27 +01:00
Jonas Schievink
6356ea24dd Add test for #[cfg] on function params 2021-03-17 18:28:27 +01:00
Jonas Schievink
622c780a8c ItemTree: lower attributes on fn parameters 2021-03-17 18:28:27 +01:00
Jonas Schievink
022a0f061e Correctly parse attributes on fn parameters 2021-03-17 18:28:27 +01:00
Lukas Wirth
5481c78f32 Check whether cursor is on and not between intra doc links in goto_definition 2021-03-17 17:24:16 +01:00
bors[bot]
edf11480ce
Merge #8065
8065: Better handling of block doc comments r=Veykril a=Veykril

Moves doc string processing to `Attrs::docs`, as we need the indent info from all comments before being able to know how much to strip

Closes #7774

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 16:00:43 +00:00
Lukas Wirth
5734b347dd Fix incorrect newline emission in Attrs::docs 2021-03-17 17:00:08 +01:00
Jonas Schievink
cb530e7c97 Handle #[cfg] on call arguments 2021-03-17 15:10:46 +01:00
Lukas Wirth
ec824a92d0 Better handling of block doc comments 2021-03-17 14:48:57 +01:00
bors[bot]
0fbfab3b45
Merge #8059
8059: Move doc-comment highlight injection from AST to HIR r=matklad,jonas-schievink a=Veykril

Fixes #5016

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 11:13:54 +00:00
Lukas Wirth
cdfb5c353f Remove quadratic attr source lookup 2021-03-17 11:22:40 +01:00
bors[bot]
f7fbea509f
Merge #8063
8063: couple clippy::complexity fixes r=matklad a=matthiaskrgr

avoid redundant `.into()` calls to convert T into identical T (`let x: String = String::from("hello").into();`)
use `if let Some(x)` instead of `.is_some()` + `.unwrap()`
don't clone Copy types
remove redundant wrapped ?s:  `Some(Some(3)?)` can just be `Some(3)`
use `.map(|x| y)` instead of `and_then(|x| Some(y)` on `Option`s

Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-17 08:12:34 +00:00
bors[bot]
6fcb5d772f
Merge #8048
8048: Fix missing unresolved macro diagnostic in function body r=edwin0cheng a=brandondong

This was an issue I found while working on https://github.com/rust-analyzer/rust-analyzer/pull/7970.

**Reproduction:**
1. Call a non-existent macro in a function body.
```
fn main() {
  foo!();
}
```
2. No diagnostics are raised. An unresolved-macro-call diagnostic is expected.
3. If the macro call is instead outside of the function body, this works as expected.

I believe this worked previously and regressed in https://github.com/rust-analyzer/rust-analyzer/pull/7805.

**Behavior prior to https://github.com/rust-analyzer/rust-analyzer/pull/7805:**
- The unresolved-macro-call diagnostic did not exist. Instead, a macro-error diagnostic would be raised with the text "could not resolve macro [path]".
- This was implemented by adding an error to the error sink (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8L657).
- The error was propagated through 1a82af3527/crates/hir_def/src/body.rs (L123) eventually reaching 1a82af3527/crates/hir_def/src/body/lower.rs (L569).

**Behavior after:**
- Instead of writing to the error sink, an UnresolvedMacro error is now returned (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R631).
- The parent caller throws away the error as its function signature is `Option<MacroCallId>` (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R604).
- We instead now reach the warn condition (1a82af3527/crates/hir_def/src/body.rs (L124)) and no diagnostics are created in 1a82af3527/crates/hir_def/src/body/lower.rs (L575).

**Fix:**
- Make sure to propagate the UnresolvedMacro error. Report the error using the new unresolved-macro-call diagnostic.


Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-03-17 07:20:28 +00:00
Brandon
a79b5673e8 Follow established ErrorEmitted pattern 2021-03-16 23:31:14 -07:00
Matthias Krüger
ff5f90d8ae use simpler .map(|x| y) instead of .and_then(|x| Some(y)) for Options. (clippy::bind_instead_of_map) 2021-03-17 02:36:29 +01:00
Matthias Krüger
64b91393b8 remove uselessly wrapped ?s. (clippy::meedless_question_mark
let x = Some(3);

let y = Some(x?);
can just be:
let y = x
2021-03-17 02:19:40 +01:00
Matthias Krüger
048dad8c2e don't clone types that are copy (clippy::clone_on_copy) 2021-03-17 01:56:31 +01:00
Matthias Krüger
c5d654d513 use if let Some(x) instead of if x.is_some() and x.unwrap() (clippy::unnecessary-unwrap) 2021-03-17 01:39:58 +01:00
Matthias Krüger
966c23f529 avoid converting types into themselves via .into() (clippy::useless-conversion)
example: let x: String = String::from("hello world").into();
2021-03-17 01:27:56 +01:00
Lukas Wirth
c766492d26 Properly handle doc attributes in doc-comment highlight injection 2021-03-16 21:15:26 +01:00
Aleksey Kladov
186a430853 pit-of-successify tree editor 2021-03-16 22:59:57 +03:00
Aleksey Kladov
34555593ca Auto-magical whitespace 2021-03-16 22:51:37 +03:00
Aleksey Kladov
d733c9bdad Move more bounds
changelog: skip
2021-03-16 22:28:04 +03:00
Lukas Wirth
3daa302cd3 Fix attribute index assignment in cfg_attr resolution 2021-03-16 19:55:40 +01:00
Lukas Wirth
acc6458390 Replace trait object boxing with extra AttrsOwnerNode 2021-03-16 19:06:58 +01:00
Lukas Wirth
11e9bc60a2 Move doc-comment highlight injection from AST to HIR 2021-03-16 18:57:47 +01:00
Florian Diebold
ce2cae45b5 Rename Substs -> Substitution 2021-03-16 17:58:17 +01:00
bors[bot]
00c80b208b
Merge #8055
8055: Implement HirDisplay for some more types r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-16 15:48:35 +00:00
bors[bot]
a69f7ce312
Merge #8053
8053: Remove ShortLabel r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-16 15:40:06 +00:00
Lukas Wirth
4d1e1daa31 Implement HirDisplay for some more types 2021-03-16 16:36:34 +01:00
bors[bot]
979e788957
Merge #8034
8034: Implement Crate::transitive_reverse_dependencies r=matklad a=Veykril

changelog internal Implement Crate::transitive_reverse_dependencies

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-16 14:54:12 +00:00
Lukas Wirth
bebee2106d Don't repeat work in transitive_reverse_dependencies 2021-03-16 15:53:34 +01:00
Lukas Wirth
4628d94e74 Remove ShortLabel 2021-03-16 15:44:31 +01:00
Lukas Wirth
75fafd6fcc Add new_source_root meta to test fixtures 2021-03-16 15:28:02 +01:00
bors[bot]
b4ed3e1551
Merge #8052
8052: minor style fixes per feedback on #8036 r=JoshMcguigan a=JoshMcguigan

cc @matklad  - this PR addresses your comments in #8036. 

changelog fixup #8036

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-16 13:56:53 +00:00
Josh Mcguigan
81f51fcd65 minor style fixes per feedback on #8036 2021-03-16 06:54:17 -07:00
bors[bot]
da5328a01b
Merge #8051
8051: Fix more unused wariable warnings r=lnicola a=lnicola

bors r+

changelog skip

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-16 13:35:26 +00:00
Laurențiu Nicola
a7cf976c63 Fix more unused wariable warnings 2021-03-16 15:34:19 +02:00
bors[bot]
c49b5b7468
Merge #7498
7498: Clone for update r=matklad a=matklad

rowan counterpart https://github.com/rust-analyzer/rowan/pull/93

#6857

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-16 13:14:48 +00:00
Aleksey Kladov
f5a81ec468 Upgrade rowan
Notably, new rowan comes with support for mutable syntax trees.
2021-03-16 16:10:49 +03:00
bors[bot]
1a82af3527
Merge #7900 #8000
7900: show function params in completion detail r=matklad a=JoshMcguigan

This resolves #7842 by updating the detail for function completions from `-> T` to `fn(T, U) -> V`. I added an expicit unit test for this, `ide_completion::render::fn_detail_includes_args_and_return_type`, which passes.

Lots of other unit tests fail (~60 of them) due to this change, although I believe the failures are purely cosmetic (they were testing the exact format of this output). I'm happy to go update those tests, but before I do that I'd like to make sure this is in fact the format we want for the detail?

edit - I realized `UPDATE_EXPECT=1 cargo test` automatically updates `expect!` tests. Big 👍 to whoever worked on that! So I'll go ahead and update all these tests soon. But I still would like to confirm `fn(T, U) -> V` is the desired content in the `detail` field. 

8000: Use hir formatter for hover text r=matklad a=oxalica

Fix #2765 , (should) fix #4665

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: oxalica <oxalicc@pm.me>
2021-03-16 08:05:24 +00:00
bors[bot]
62ec04bbd5
Merge #8036 #8046
8036: completions: provide relevance bonus for enum types, and suggest ref matches for fn and enum r=matklad a=JoshMcguigan

This PR makes several improvements to completions and completion sorting:

1. Provide exact match type relevance score bonus for enum variants
2. Suggest `&Foo` (ref_match) for enums if that is an exact type match
3. Suggest `&foo()` (ref_match) if `foo` returns a type which would be an exact match either with the reference or due to a `Deref` impl

### Before

![pre-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189377-3f05a580-8573-11eb-89be-58a45cb7f829.png)

### After

![post-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189395-45941d00-8573-11eb-871b-09186b35cbb9.png)

### Caveats

I think generic types will require some kind of fancier logic when testing for `exact_type_match`, so for now `Option`/`Result`/etc unfortunately still don't have great completions.

### Implementation

I implemented this in a way that I think makes it most likely for each completion type to be handled consistently. Just replace `CompletionItem::new` with `CompletionItem::new_with_type_info` and `exact_type_match`/`exact_name_match`/`ref_match` are all handled for you, in a way which is sure to be consistent across completion types. 

This approach does introduce some coupling/plumbing that didn't exist before. Notice for example `set_is_local` on the builder, because `set_relevance` was removed from the builder to enforce that the relevance was built "properly" with `CompletionItem::new_with_type_info`. But I think there are benefits to this approach, like `CompletionRelevance` should probably consider deprecation status, and we already tell the builder about that, so in the (likely near term) future we can just pass that information along to `CompletionRelevance` when the user calls `set_deprecated` rather than the user having to manually set it in two places. This basically just hides `CompletionRelevance` from the individual completions, so they only worry about the `CompletionItem` interface. At the moment this seems like a cleaner approach to me, but I'm open to feedback here. 

edit - I've reimplemented this in a simpler way, per feedback below.

8046: Prefer match to if let else r=matklad a=matklad

bors r+
🤖

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-16 07:57:33 +00:00
Brandon
0103f5df8f Fix missing unresolved macro diagnostic in function body 2021-03-16 00:52:58 -07:00
bors[bot]
8b4075ff1c
Merge #8040
8040: 7709: Added the check for return type of len function. r=Veykril a=chetankhilosiya



Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-16 07:41:58 +00:00
Edwin Cheng
8e07b23b84 Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
Josh Mcguigan
405bbb3aa4 completions: centralize calculation of relevance and ref matches 2021-03-15 19:40:42 -07:00
Chetan Khilosiya
847ec9e840 7709: Import changes. 2021-03-16 01:58:21 +05:30
Chetan Khilosiya
714836959b 7709: Added the check for return type of len function. 2021-03-16 01:16:59 +05:30
Florian Diebold
455e755bb0 Use SmallVec for Substs
Doesn't help as much as I hoped, but it helps a bit and I also did some
refactorings that were necessary anyway.
2021-03-15 19:48:03 +01:00
bors[bot]
47b74cadf9
Merge #7970
7970: Fix incorrect diagnostics for failing built in macros r=jonas-schievink a=brandondong

**Reproduction:**
1. Use a built in macro in such a way that rust-analyzer fails to expand it. For example:

**lib.rs**
```
include!("<valid file but without a .rs extension so it is not indexed by rust-analyzer>");
```
2. rust-analyzer highlights the macro call and says the macro itself cannot be resolved even though include! is in the standard library (unresolved-macro-call diagnostic).
3. No macro-error diagnostic is raised.

**Root cause for incorrect unresolved-macro-call diagnostic:**
1. collector:collect_macro_call is able to resolve include! in legacy scope but the expansion fails. Therefore, it's pushed into unexpanded_macros to be retried with module scope.
2. include! fails at the resolution step in collector:resolve_macros now that it's using module scope. Therefore, it's retained in unexpanded_macros.
3. Finally, collector:finish tries resolving the remaining unexpanded macros but only with module scope. include! again fails at the resolution step so a diagnostic is created.

**Root cause for missing macro-error diagnostic:**
1. In collector:resolve_macros, directive.legacy is None since eager expansion failed in collector:collect_macro_call. The macro_call_as_call_id fails to resolve since we're retrying in module scope. Therefore, collect_macro_expansion is not called for the macro and no macro-error diagnostic is generated.

**Fix:**
- In collector:collect_macro_call, do not add failing built-in macros to the unexpanded_macros list and immediately raise the macro-error diagnostic. This is in contrast to lazy macros which are resolved in collector::resolve_macros and later expanded in collect_macro_expansion where a macro-error diagnostic may be raised.

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: brandondong <brandondong604@hotmail.com>
2021-03-15 18:24:22 +00:00
brandondong
ebb10da563
Update crates/hir_def/src/nameres/collector.rs
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-15 11:16:58 -07:00
bors[bot]
e24453c5ee
Merge #8038
8038: Fix unification logic r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-15 18:14:49 +00:00
Florian Diebold
287e9a870c Fix unification logic 2021-03-15 19:14:10 +01:00
bors[bot]
d38fd77845
Merge #8028
8028: Return multiple modules in `parent_module` feature r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 17:50:20 +00:00
bors[bot]
1f28345b37
Merge #8037
8037: Assist is empty 7709 r=Veykril a=chetankhilosiya

Updated the implementation to get the function from implementation

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-15 17:40:14 +00:00
Lukas Wirth
e97cd709cd Implement Crate::transitive_reverse_dependencies 2021-03-15 18:28:31 +01:00
oxalica
455b418263
Update tests 2021-03-16 01:24:26 +08:00
oxalica
73fc05fdca
Pretty print root module of extern crates 2021-03-16 01:24:21 +08:00
Chetan Khilosiya
0c2d4a8a77 7709: Updated the implementation.
The get function from impl method is updated.
and now same method used to get len and is_empty function.
2021-03-15 22:48:50 +05:30
oxalica
7c855c940a
Clean usage of ShortLabel 2021-03-16 01:05:56 +08:00
oxalica
7101bada0f
Fix trait type parameter 2021-03-16 01:04:33 +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
2bb8956a10
Introduce FunctionQualifier for hir::FunctionData 2021-03-16 01:03:07 +08:00
oxalica
b9c172a977
Collect HirDisplay impls to a single file 2021-03-16 01:02:33 +08:00
oxalica
ef48d1ca3b
Add test for hover of macro expanded function 2021-03-16 01:01:24 +08:00
bors[bot]
ce3125165a
Merge #8035
8035: unqualfied_path completions aren't responsible for variant pattern completions r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 16:51:53 +00:00
Lukas Wirth
4a0ab832f3 unqualfied_path completions aren't responsible for pattern completions 2021-03-15 17:23:08 +01:00
Chetan Khilosiya
2bf3802f21 7709: Added the assist to generate is_empty function
the assist will be shown when the len function is implemented.
is_empty internally uses len function.
2021-03-15 21:31:52 +05:30
bors[bot]
eec64ec01b
Merge #7992
7992: improved completion sorting for functions and methods r=JoshMcguigan a=JoshMcguigan

This PR improves completion sorting for functions and methods. Related to #7935.

### Before

The methods are being sorted by `coc` by closeness in file. 

![pre-fn-relevance](https://user-images.githubusercontent.com/22216761/111018669-fe3d3f00-836e-11eb-9607-cc05af080a6a.png)

### After

Notice `bbb()` on top (type + name match), followed by `ddd()` (type match).

![image](https://user-images.githubusercontent.com/22216761/111018680-0e551e80-836f-11eb-94b1-c88336ecbc6e.png)


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-15 15:53:15 +00:00
bors[bot]
b8a85e9603
Merge #8033
8033: Add test for proc-macro meta info retrieval r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-15 15:39:34 +00:00
Edwin Cheng
a8c9c88292 Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
Josh Mcguigan
db8bcf132c implement function completion scoring 2021-03-15 08:35:28 -07:00
Aleksey Kladov
469b739c28 Enable proc-macros by default 2021-03-15 18:19:08 +03: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
Lukas Wirth
2e3c156b0e Return multiple modules in parent_module 2021-03-15 15:15:40 +01: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
e941cb0238 Drop non-working mark 2021-03-15 16:05:16 +02:00
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
bors[bot]
3962b0d53c
Merge #8027
8027: Completion context remove exact match method in favor of fields r=JoshMcguigan a=JoshMcguigan

This is a minor cleanup PR following #8008. It removes the `expected_name_and_type` method on completion context in favor of using the fields. 

I thought this method was used in more places, or else it may have just made sense to make this change directly in #8008 🤷 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-15 13:42:12 +00:00
Lukas Wirth
79561b9d2e goto_implementation: Look at the entire crate graph for trait impls 2021-03-15 14:31:55 +01:00
Josh Mcguigan
67d59aeb7c remove expected_name_and_type method on completion context in favor of using fields added in #8008 2021-03-15 06:25:39 -07: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
bors[bot]
0ac7a19d0c
Merge #8008
8008: Completion context expected type r=matklad a=JoshMcguigan

Currently there are two ways completions use to determine the expected type. There is the `expected_type` field on the `CompletionContext`, as well as the `expected_name_and_type` method on the `RenderContext`. These two things returned slightly different results, and their results were only valid if you had pre-checked some (undocumented) invariants. A simple combination of the two approaches doesn't work because they are both too willing to go far up the syntax tree to find something that fits what they are looking for.

This PR makes the following changes:

1. Updates the algorithm that sets `expected_type` on `CompletionContext`
2. Adds `expected_name` field to `CompletionContext`
3. Re-writes the `expected_name_and_type` method to simply return the underlying fields from `CompletionContext` (I'd like to save actually removing this method for a follow up PR just to keep the scope of the changes down)
4. Adds unit tests for the `expected_type`/`expected_name` fields

All the existing unit tests still pass (unmodified), but this new algorithm certainly has some gaps (although I believe all the `FIXME` introduced in this PR are also flaws in the current code). I wanted to stop here and get some feedback though - is this approach fundamentally sound? 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-15 12:59:47 +00:00
bors[bot]
6139bd7649
Merge #8018
8018: Make Ty wrap TyKind in an Arc r=flodiebold a=flodiebold

... to further move towards Chalk.

This is a bit of a slowdown (218ginstr vs 213ginstr for inference on RA), even though it allows us to unwrap the Substs in `TyKind::Ref` etc..

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-15 12:51:27 +00:00
Lukas Wirth
6241567948 Speedup trait impl search for goto_implementation 2021-03-15 13:49:21 +01:00
Aleksey Kladov
f7156cb0ae Simplify source maps for fields 2021-03-15 15:38:50 +03:00
Josh Mcguigan
d91151c3b1 update algorithm for determining expected type of completion 2021-03-15 05:38:19 -07: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
bors[bot]
5ba7852cf1
Merge #8017
8017: Don't drop type params in doc-test paths r=Veykril a=Veykril

Closes #7995

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-14 19:46:49 +00:00
Lukas Wirth
f2610cbd7e Don't drop type params in doc-test paths 2021-03-14 20:38:26 +01:00
Florian Diebold
42217738e0 Don't use Substs for Ref/Raw/Array/Slice 2021-03-14 20:21:05 +01:00
ivan770
d6977550dd
Make CI happy 2021-03-14 19:05:09 +02: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
Florian Diebold
af466f8542 Make Ty wrap TyKind in an Arc
... like it will be in Chalk. We still keep `interned_mut` and
`into_inner` methods that will probably not exist with Chalk.

This worsens performance slightly (5ginstr inference on RA), but doesn't
include other simplifications we can do yet.
2021-03-14 17:31:08 +01:00
bors[bot]
af8440b848
Merge #8014
8014: increase completion relevance for items in local scope r=matklad a=JoshMcguigan

This PR provides a small completion relevance score bonus for items in local scope. The changes here are relatively minimal, since `coc` by default pre-sorts by position in file. But as we move toward fully server side sorting #7935 I think we'll want some relevance score bump for items in local scope. 

### Before

Note `let~` and `syntax` are both ahead of locals. Ultimately we may decide that `let~` is a high relevance completion given my cursor position here, but that should be done with some explicit scoring on the server side, rather than being caused by (I think) `coc` preferring shorter completions. 

![pre-local-score](https://user-images.githubusercontent.com/22216761/111073414-c97ad600-849b-11eb-84e7-fcee130536f0.png)

### After

![post-local-score](https://user-images.githubusercontent.com/22216761/111073422-d0094d80-849b-11eb-92ec-7ae5ec3b190d.png)


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-14 15:56:29 +00:00
Florian Diebold
1954147834 More renaming 2021-03-14 16:33:27 +01:00
Florian Diebold
eea777c714 Use chalk_ir::FnSig 2021-03-14 16:30:43 +01:00
Florian Diebold
3411fe3e84 Rename some fields to their Chalk names 2021-03-14 16:30:43 +01:00
Josh Mcguigan
ba924d04b3 increase completion relevance for items in local scope 2021-03-14 08:00:47 -07:00
bors[bot]
f57e2f5598
Merge #7993
7993: Use auto-deref in completion scoring r=JoshMcguigan a=ivan770

Closes #7982 

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-03-14 14:27:53 +00:00
bors[bot]
a8a7fa8347
Merge #8011
8011: Add no-sysroot flag for analysis-stats r=edwin0cheng a=edwin0cheng

Add `no-sysroot` flag for `rust-analyzer analysis-stats`. It is very useful for debugging propose. 

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-14 10:50:59 +00:00