Commit graph

11029 commits

Author SHA1 Message Date
Ayomide Bamidele
8e11796dc5 formatting fix 2021-03-29 12:56:02 +01:00
Jonas Schievink
3c6c1c99b4 Don't use snippets 2021-03-29 13:23:07 +02:00
Ayomide Bamidele
a813062ed2 Folding range for statics 2021-03-29 12:20:26 +01:00
Jonas Schievink
8c1092455e Use find_node_at_range 2021-03-29 13:17:49 +02:00
Ayomide Bamidele
391be07298 Folding range for consts 2021-03-29 12:17:19 +01:00
Ayomide Bamidele
23601454fe New FoldKinds - Consts, Statics 2021-03-29 11:49:14 +01:00
Ayomide Bamidele
f6702dda9a Test cases for folding consts and statics 2021-03-29 11:43:03 +01:00
bors[bot]
ae7de296ae
Merge #8222
8222: Don't mark unlinked file diagnostic as unused r=lnicola a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8215, at least on VS Code

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-29 07:30:28 +00:00
bors[bot]
bb1d925dab
Merge #8212
8212: Basic support macro 2.0 r=jonas-schievink a=edwin0cheng

Turn out it is quite straight forward :)

r @jonas-schievink 

![m2](https://user-images.githubusercontent.com/11014119/112712565-6eb99380-8f0b-11eb-88de-5d7f974dfe6d.png)


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-28 15:43:11 +00:00
Edwin Cheng
7729879118 Remove unused test fixtures 2021-03-28 10:41:18 +08:00
Jonas Schievink
bd18e5fa87 Don't mark unlinked file diagnostic as unused 2021-03-28 03:56:03 +02:00
bors[bot]
ce6bb5ccca
Merge #8221
8221: Prefer adding `mod` declaration to lib.rs over file.rs in UnlinkedFile fix r=Veykril a=Veykril

When there is a `lib.rs` and `main.rs` in one crate, one usually wants the `lib.rs` file to declare the modules.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-27 22:43:34 +00:00
Lukas Wirth
c9e479870b Prefer add mod declaration to lib.rs over file.rs in UnlinkedFile fix 2021-03-27 23:43:07 +01:00
bors[bot]
84f1660a37
Merge #8220
8220: Reorder some ide_db imports r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-27 21:13:08 +00:00
Lukas Wirth
1ef55002c2 Cleanup ide_db imports 2021-03-27 21:51:00 +01:00
Jonas Schievink
b494e47920 Snippet support in extract_type_alias 2021-03-27 18:53:13 +01:00
ivan770
665266bf66
Replace empty dbg with unit in letexprs, better removal in blocks 2021-03-27 17:34:35 +02:00
bors[bot]
ae92014319
Merge #8213
8213: Added support for const generics in impl generation r=Veykril a=ivan770

Closes #8211

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-03-27 10:00:37 +00:00
ivan770
5a2ef8d0ca
Added support for const generics in impl generation 2021-03-27 11:37:39 +02:00
ivan770
0a5badbcba
Replace match on option with if 2021-03-27 11:17:17 +02:00
ivan770
c7cd0aff4a
Remove dbg expression and newline as whole 2021-03-27 11:10:20 +02:00
Edwin Cheng
eedadd7024 Add support for doc on hover for macro 2.0 2021-03-27 14:57:11 +08:00
Edwin Cheng
4520002b63 Unleash macro 2.0 in hightlight and more 2021-03-27 14:42:49 +08:00
Edwin Cheng
a193666361 Basic Support Macro 2.0 2021-03-27 13:44:54 +08:00
bors[bot]
c8066ebd17
Merge #8201
8201: Fix recursive macro statements expansion r=edwin0cheng a=edwin0cheng

This PR attempts to properly handle macro statement expansion by implementing the following:

1.  Merge macro expanded statements to parent scope statements.
2.  Add a new hir `Expr::MacroStmts` for handle tail expression infer.

PS : The scope of macro expanded statements are so strange that it took more time than I thought to understand and implement it :(

Fixes  #8171



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-27 02:57:02 +00:00
Jonas Schievink
e39979aa91 Implement "Extract type alias" assist 2021-03-26 19:39:20 +01:00
Aleksey Kladov
1bbac9053d Add TokenText 2021-03-26 21:33:45 +03:00
cynecx
5ff3299dd6 syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
Josh Mcguigan
0e31ae2cef completion relevance distinguish between exact type match and could unify 2021-03-26 09:18:18 -07:00
Josh Mcguigan
957939292e completion relevance consider if types can be unified 2021-03-26 09:11:50 -07:00
ivan770
2292ff64f1
Show dbg remove assist on empty contents 2021-03-26 16:15:26 +02:00
ivan770
50e28aec25
Ignore main functions not in root module 2021-03-26 16:04:53 +02:00
Edwin Cheng
8ce15b02de Fix recursive macro statement expansion 2021-03-26 04:21:15 +08:00
Laurențiu Nicola
bc5c86543b Use more std::array::IntoIter 2021-03-25 21:06:48 +02:00
Laurențiu Nicola
9787bddac5 Use arrayvec 0.6 2021-03-25 21:03:20 +02:00
bors[bot]
d7db38fff9
Merge #7907
7907: Autoderef with visibility r=cynecx a=cynecx

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

I am not sure about the general approach here. Right now this simply tries to check whether the autoderef candidate is reachable from the current module. ~~However this doesn't exactly work with traits (see the `tests::macros::infer_derive_clone_in_core` test, which fails right now).~~ see comment below

Refs:

- `rustc_typeck` checking fields: 66ec64ccf3/compiler/rustc_typeck/src/check/expr.rs (L1610) 


r? @flodiebold

Co-authored-by: cynecx <me@cynecx.net>
2021-03-24 22:37:48 +00:00
bors[bot]
9d81618f11
Merge #8190
8190: Fix chalk_ir assertion r=flodiebold a=flodiebold

Fixes #8150.

I implemented a validator that catches this in the tests, but it'd need to get merged in Chalk first.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-24 22:13:56 +00:00
Florian Diebold
b4c20e3589 Fix chalk_ir assertion
Fixes #8150.
2021-03-24 23:10:13 +01:00
cynecx
d1156bb52e hir: don't use the self module as visible_from in iterate_method_candidates 2021-03-24 23:09:22 +01:00
cynecx
7155f815b9 hir_ty: don't call write_field_resolution when field candidate isn't visible 2021-03-24 23:03:38 +01:00
cynecx
96c88680b2 hir_def: move visibility queries from hir_ty to hir_def 2021-03-24 23:00:03 +01:00
Jonas Schievink
37c6ce34a9 Document unlinked-file diagnostic 2021-03-24 22:18:17 +01:00
Jonas Schievink
4781479ab2 Sweep the new TraitEnvironmentQuery 2021-03-24 18:59:35 +01:00
hi-rustin
eef9bdb441 refine comment style of tests 2021-03-24 19:28:50 +08:00
bors[bot]
776b1ebcb4
Merge #8168
8168: correct `convert to guard return` let_stmt r=Veykril a=hi-rustin

close https://github.com/rust-analyzer/rust-analyzer/issues/8074

Co-authored-by: hi-rustin <rustin.liu@gmail.com>
2021-03-24 10:55:25 +00:00
bors[bot]
2aa64831e5
Merge #8183
8183: Fix missing command error with macros r=Veykril a=brandondong

**Reproduction:**
1. Define a struct through a macro (can be via `macro_rules`, proc macro, or `include!()`).
2. !!MISSING: command!! annotation appears. Clicking on it results in an error message. No matter where the macro is called/defined, the annotation is always at the start of the file.
![image](https://user-images.githubusercontent.com/13722457/112268785-bce14500-8c34-11eb-9a23-bafd63ffd6ef.png)

**Cause:**
- For struct `A`, a `HasImpls` annotation is added just like for struct `B`. Unlike `B`, the file id for `A` is not the file we are adding annotations to but a macro file.
- The resolving step of the code lens does not succeed.

**Fix:**
- Check that the files match before computing offsets and adding `HasImpls`/`HasReferences` annotations.

Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-03-24 10:17:12 +00:00
bors[bot]
5f9ba2d589
Merge #8177
8177: Limit the hints size by default r=Veykril a=SomeoneToIgnore

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8175
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/3138

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-03-24 08:53:48 +00:00
Brandon
903a2e98f9 Clean up implementation 2021-03-24 00:47:55 -07:00
Edwin Cheng
a2950fcb05 Trim down IPC json size 2021-03-24 15:01:37 +08:00
Brandon
0d063b8d21 Fix MISSING: command error with macros 2021-03-24 00:00:38 -07:00
hi-rustin
e992acf078 correct convert to guard return let_stmt
fix

fix

add check
2021-03-24 11:52:44 +08:00
bors[bot]
d702f10fb3
Merge #8159
8159: Ignore proc-macro stdout to prevent IPC crash r=edwin0cheng a=edwin0cheng

fixes  #7954

r? @flodiebold 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-23 20:06:44 +00:00
bors[bot]
c6d6a7d412
Merge #8178
8178: Show item info when hovering intra doc links r=Veykril a=Veykril

![r4uIITP0IZ](https://user-images.githubusercontent.com/3757771/112197618-91e2fb00-8c0c-11eb-9edc-a7923214d2b6.gif)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-23 19:58:03 +00:00
Lukas Wirth
caaeb92882 Cleanup intra_doc_link parsing 2021-03-23 20:56:38 +01:00
Edwin Cheng
79f583ed66 Improve message usage in proc-macro
Reuse storage for the buffer send to child process of proc-macro.
2021-03-24 03:51:06 +08:00
Edwin Cheng
f41ae64722 Ignore proc-macro stdout to prevent IPC crash 2021-03-24 03:44:28 +08:00
Lukas Wirth
8b0d0bd9c7 Show item info when hovering intra doc links 2021-03-23 19:57:04 +01:00
Kirill Bulatov
5e83a56dfb Bump the default hint length 2021-03-23 19:43:55 +02:00
bors[bot]
5f13319892
Merge #8176
8176: Cleanup r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-23 17:05:14 +00:00
Kirill Bulatov
f1e1a2c0a7 Limit the hints size by default 2021-03-23 19:04:48 +02:00
Aleksey Kladov
8b4240e026 Cleanup 2021-03-23 19:59:33 +03:00
bors[bot]
789f7aca2e
Merge #8173
8173: simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-23 16:54:35 +00:00
Lukas Wirth
6bdf505d7c simplify 2021-03-23 17:49:06 +01:00
bors[bot]
c220b34095
Merge #8174
8174: Simplify code r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-23 16:44:28 +00:00
Aleksey Kladov
e33959a888 Simplify code
changelog: skip
2021-03-23 19:41:15 +03:00
Jonas Schievink
1d5d44f7f7 Merge bang-macros and derives in name resolution 2021-03-23 17:23:10 +01:00
bors[bot]
065a8e87cd
Merge #8169
8169: Make more use of the HIR in rename::rename_to_self r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-23 15:55:04 +00:00
Lukas Wirth
638dcac092 Make more use of the HIR in rename::rename_to_self 2021-03-23 16:54:21 +01:00
Aleksey Kladov
860e069d4d Use styleguide conforming import for ast nodes 2021-03-23 17:44:17 +03:00
Aleksey Kladov
7352f50ec2 Unify test style
changelog skip
2021-03-23 17:38:51 +03:00
Aleksey Kladov
b83c7eedcc Tweak assits API to fit mutable syntax trees
changelog: skip
2021-03-23 17:31:19 +03:00
Lukas Wirth
395183e0b7 Cleanup Definition::search_scope 2021-03-23 13:03:55 +01:00
Lukas Wirth
7c4eb66c1a Merge hir::MacroDef::is_* into hir::MacroDef::kind 2021-03-23 11:32:14 +01:00
Lukas Wirth
bad4e48672 Set up a search scope when searching for mbe macro references 2021-03-23 11:32:10 +01:00
bors[bot]
1efd220f2f
Merge #8162
8162: Compute more mathematically well-rounded notion of transitive deps r=Veykril a=matklad

By including the crate itself, we make the resulting set closed with
respect to `transitve_reveres_dependencies` operation, as it becomes a
proper transitive closure. This just feels more proper and mathy.

And, indeed, this actually allows us to simplify call sites somewhat.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-23 10:20:47 +00:00
Aleksey Kladov
fa9c6eb456 Improve readability 2021-03-23 13:04:43 +03:00
Aleksey Kladov
ba48c0d8bd Align naming of deps and revdeps 2021-03-23 13:04:43 +03:00
Aleksey Kladov
521a26b0d2 Align semantics of deps and rev deps 2021-03-23 12:58:48 +03:00
Aleksey Kladov
45a8f37b6a Compute more mathematically well-rounded notion of transitive deps
By including the crate itself, we make the resulting set closed with
respect to `transitve_reveres_dependencies` operation, as it becomes a
proper transitive closure. This just feels more proper and mathy.

And, indeed, this actually allows us to simplify call sites somewhat.
2021-03-23 12:49:55 +03:00
bors[bot]
bf3a8eb40a
Merge #8142
8142: temp disable broken ref match completions for struct fields/methods r=matklad a=JoshMcguigan

This PR implements a temporary workaround for #8058 by disabling ref match completions for struct fields and methods. Disabling this doesn't break any existing functionality (that I am aware of) since these completions were broken.

I plan to keep working on a real fix for the underlying issue here, but I think a proper fix could take some time, so I'd prefer to quickly fix the bug to buy some more time to implement a better solution (which would ultimately allow re-enabling ref matches for struct fields and methods). 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-23 09:24:26 +00:00
Josh Mcguigan
18c3fb2df5 add unit test to demonstrate struct fields/methods do not get ref match completions 2021-03-22 20:34:02 -07:00
bors[bot]
4b997b8663
Merge #8156
8156: Correctly lower TraitRefs with default params r=flodiebold a=Veykril

Fixes #5685

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-22 20:39:58 +00:00
Lukas Wirth
0aa4ac362d Correctly lower TraitRefs with default params 2021-03-22 19:13:43 +01:00
bors[bot]
97fe64a5c7
Merge #8154 #8155
8154: rewrite merge use trees assist to use muatable syntax trees r=matklad a=matklad

bors r+
🤖

8155: Fix confusion between parameters and the function r=jonas-schievink a=jonas-schievink

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

bors r+

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2021-03-22 17:56:18 +00:00
Jonas Schievink
2633e23f2b resolver: manually traverse nested block scopes 2021-03-22 18:55:51 +01:00
Aleksey Kladov
9cbf09ec4f rewrite merge use trees assist to use muatable syntax trees
changelog internal
2021-03-22 20:47:46 +03:00
bors[bot]
d834306e7c
Merge #8153
8153: ⬆️ rowan r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-22 17:27:32 +00:00
Aleksey Kladov
48b534ceb8 ⬆️ rowan 2021-03-22 20:26:59 +03:00
bors[bot]
94aa3a7b1a
Merge #8141
8141: Don't suggest long looping paths for imports r=matklad a=SomeoneToIgnore

Fixes https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/name.3A.3Aname.3A.3Aname.3A.3Aname.3A.3Aname


Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-03-22 13:20:07 +00:00
Kirill Bulatov
129353255c Code review fixes 2021-03-22 15:15:53 +02:00
bors[bot]
d4fa6721af
Merge #8054
8054: Item movers r=matklad a=ivan770

Closes #6823

https://user-images.githubusercontent.com/14003886/111331579-b4f43480-8679-11eb-9af0-e4dabacc4923.mp4

Implementation issues:
- [ ] Most of items are non-movable, since _movability_ of any item has to be determined manually. Common ones are movable though
- [x] Cursor should move with the item

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-03-22 13:08:45 +00:00
bors[bot]
3af1885bd2
Merge #8144
8144: bail out early for source code closures r=Veykril a=hi-rustin

close https://github.com/rust-analyzer/rust-analyzer/issues/8084

Co-authored-by: hi-rustin <rustin.liu@gmail.com>
2021-03-22 12:35:44 +00:00
bors[bot]
e220d3d507
Merge #8139
8139: Align `Canonical` and `InEnvironment` with the Chalk versions r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-22 12:25:53 +00:00
bors[bot]
6f1f91cdcf
Merge #8136 #8146
8136: Introduce QuantifiedWhereClause and DynTy analogous to Chalk r=flodiebold a=flodiebold

This introduces a bunch of new binders in lots of places, which we have to be careful about, but we had to add them at some point. There's a lot of skipping of the binders; once we're done with the Chalk move, we should review the remaining ones.

8146: Document patch policy r=matklad a=matklad

bors r+
🤖

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-22 12:08:25 +00:00
hi-rustin
2e09714dfe bail out early for source code closures
add closure error
2021-03-22 19:40:07 +08:00
Edwin Cheng
7784cadc3d Reexport PrefixKind to remove deps to hir 2021-03-22 13:39:13 +08:00
Josh Mcguigan
8cd94900f7 implement a temporary workaround for #8058 2021-03-21 17:30:56 -07:00
Kirill Bulatov
3a4e99115d Do not revisit recursively imported modules 2021-03-22 00:46:52 +02:00
bors[bot]
858ad55437
Merge #8137
8137: Fix box pattern inference panic r=flodiebold a=Veykril

Fixes #6560

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-21 19:25:14 +00:00
Florian Diebold
c4fd3f47f5 Align InEnvironment with Chalk
This in particular means storing a chalk_ir::Environment, not our
TraitEnvironment. This makes InEnvironment not usable for Type, where we
need to keep the full TraitEnvironment.
2021-03-21 20:19:07 +01:00
Florian Diebold
f7be314579 Align Canonical more with Chalk's version
In particular, use chalk_ir::CanonicalVarKinds.
2021-03-21 20:05:38 +01:00
bors[bot]
31ed164161
Merge #8134
8134: Correct the paths of submodules from the include! macro r=edwin0cheng a=sticnarf

This PR should fix #7846. It mostly follows the instructions from @edwin0cheng in that issue.

Co-authored-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 17:57:45 +00:00
Yilin Chen
7b693470c4
check is_include_macro only when attr_path is not specified
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-22 01:54:05 +08:00
Lukas Wirth
af50e8d955 Fix box pattern inference panic 2021-03-21 18:25:00 +01:00
Florian Diebold
1d5c4a77fb Use QuantifiedWhereClause in generic_predicates as well
Still far too much binder skipping going on; I find it hard to imagine
this is all correct, but the tests pass.
2021-03-21 18:01:14 +01:00
Florian Diebold
590c416359 Introduce QuantifiedWhereClause and DynTy analogous to Chalk
This introduces a bunch of new binders in lots of places, which we have
to be careful about, but we had to add them at some point.
2021-03-21 18:01:14 +01:00
bors[bot]
35868c4f7d
Merge #8133
8133: Ignore type bindings in generic_predicates_for_param (fix panic on ena and crates depending on it) r=flodiebold a=flodiebold

This allows us to handle more cases without a query cycle, which includes certain cases that rustc accepted. That in turn means we avoid triggering salsa-rs/salsa#257 on valid code (it will still happen if the user writes an actual cycle).

We actually accept more definitions than rustc now; that's because rustc only ignores bindings when looking up super traits, whereas we now also ignore them when looking for predicates to disambiguate associated type shorthand. We could introduce a separate query for super traits if necessary, but for now I think this should be fine.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-21 16:42:08 +00:00
bors[bot]
1ae20d2b89
Merge #8132
8132: Add `'` to trigger_characters, allowing more direct lifetime completions r=Veykril a=Veykril

Fixes having to type a character after `'` to complete lifetimes and labels

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-21 15:57:14 +00:00
bors[bot]
d51cf133f6
Merge #8135
8135: more clippy::{perf, complexity, style} fixes r=Veykril a=matthiaskrgr



Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-21 15:49:31 +00:00
bors[bot]
5bb65bb496
Merge #8128
8128: Expand legacy-scoped macro during collection r=jonas-schievink a=jonas-schievink

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



Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-21 15:21:11 +00:00
Matthias Krüger
202b51bc7b a lot of clippy::style fixes 2021-03-21 16:15:41 +01:00
Yilin Chen
3bb9efb6b7
use the included file as the source of expanded include macro
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 23:02:01 +08:00
Florian Diebold
d8f8b495ad Ignore type bindings in generic_predicates_for_param
This allows us to handle more cases without a query cycle, which
includes certain cases that rustc accepted. That in turn means we avoid
triggering salsa-rs/salsa#257 on valid code (it will still happen if the
user writes an actual cycle).

We actually accept more definitions than rustc now; that's because rustc
only ignores bindings when looking up super traits, whereas we now also
ignore them when looking for predicates to disambiguate associated type
shorthand. We could introduce a separate query for super traits if
necessary, but for now I think this should be fine.
2021-03-21 15:29:03 +01:00
Florian Diebold
0623bb4d71 Test for a Salsa bug 2021-03-21 13:33:06 +01:00
Matthias Krüger
ae7e55c1dd clippy::complexity simplifications related to Iterators 2021-03-21 13:13:34 +01:00
Matthias Krüger
8a67116857 use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) 2021-03-21 12:38:21 +01:00
Matthias Krüger
3d9b3a8575 remove more redundant clones (clippy::redundant_clone()) 2021-03-21 12:10:39 +01:00
Lukas Wirth
f3c7499be5 Add ' to trigger_characters, allowing more direct lifetime completions 2021-03-21 11:05:04 +01:00
Kirill Bulatov
b17d99c070 Fix the profile string 2021-03-21 11:45:37 +02:00
Kirill Bulatov
eaa4fcbbde Less reallocations 2021-03-21 11:45:37 +02:00
Kirill Bulatov
ec731e19df Use smart case in flyimport items lookup 2021-03-21 11:45:37 +02:00
bors[bot]
09412d85fc
Merge #8123
8123: Do not display unqualified assoc item completions r=SomeoneToIgnore a=SomeoneToIgnore

Part of https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/autoimport.20weirdness

Removes all flyimport completions for any unqualified associated type, effectively reverting https://github.com/rust-analyzer/rust-analyzer/pull/8095 
I've explained the reasoning in the corresponding FIXME and open to discussions.
As an alternative way, we could add yet another parameter in the method that's used by the `qualify_path` and enable it for the qualify assists only.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-03-21 09:37:08 +00:00
Jonas Schievink
5322cd830e Expand legacy-scoped macro during collection 2021-03-21 01:45:24 +01:00
bors[bot]
a0ed87ff56
Merge #8127
8127: Add label completion r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-21 00:29:15 +00:00
Lukas Wirth
64957acb5f Fix incorrect scoping in while expressions 2021-03-21 01:28:42 +01:00
bors[bot]
787bd3c551
Merge #8122
8122: Make bare underscore token an Ident rather than Punct in proc-macro r=edwin0cheng a=kevinmehall

In rustc and proc-macro2, a bare `_` token is parsed for procedural macro purposes as `Ident` rather than `Punct` (see https://github.com/rust-lang/rust/pull/48842). This changes rust-analyzer to match rustc's behavior and implementation by handling `_` as an Ident in token trees, but explicitly preventing `$x:ident` from matching it in MBE.

proc macro crate:
```rust
#[proc_macro]
pub fn input(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    dbg!(input)
}
```

test crate:
```rust
test_proc_macro::input!(_);
```

output (rustc):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Ident {
        ident: "_",
        span: #0 bytes(173..174),
    },
]
```

output (rust-analyzer before this change):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Punct {
        ch: '_',
        spacing: Joint,
        span: 4294967295,
    },
]
```

output (rust-analyzer after this change):
```rust
[test-proc-macro/src/lib.rs:10] input = TokenStream [
    Ident {
        ident: "_",
        span: 4294967295,
    },
]
```


Co-authored-by: Kevin Mehall <km@kevinmehall.net>
2021-03-21 00:10:14 +00:00
Lukas Wirth
62a4677dbc Add label completion 2021-03-21 01:02:22 +01:00
Lukas Wirth
cbd325707b Track labels in scopes 2021-03-21 01:02:01 +01:00
Kevin Mehall
0a7f28620a Fix and test edge cases of _ as ident 2021-03-20 17:54:57 -06:00
bors[bot]
090e013161
Merge #8124
8124: Add basic lifetime completion r=Veykril a=Veykril

This adds basic lifetime completion, basic in the sense that the completions for lifetimes are only shown when the user enters `'` followed by a char. Showing them when nothing is entered is kind of a pain, as we would want them to only show up where they are useful which in turn requires a lot of tree traversal and cursor position checking to verify whether the position is valid for a lifetime. This in itself doesn't seem too bad as usually when you know you want to write a lifetime putting `'` to ask for lifetime completions seems fine.

~~I'll take a look at whether its possible to lift the restriction of having to put a char after `'`.~~ This actually already works so I guess this is the clients responsibility, in which case VSCode doesn't like it.

![TYH9gIlyVo](https://user-images.githubusercontent.com/3757771/111886437-c9b02f80-89cd-11eb-9bee-340f1536b0de.gif)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-20 22:32:25 +00:00
Lukas Wirth
3c000c6364 Add basic lifetime completion 2021-03-20 23:25:07 +01:00
Lukas Wirth
38048c35d8 Don't use an untyped String for ActiveParam tracking 2021-03-20 23:22:09 +01:00
Kirill Bulatov
56a7d246d5 Disable unqualified assoc items completion for now 2021-03-20 23:08:44 +02:00
Kirill Bulatov
879432452d Docs 2021-03-20 22:55:34 +02:00
Kirill Bulatov
a631108d2d Do not query item search by name eagerly 2021-03-20 22:33:54 +02:00
Kirill Bulatov
81961dc035 Do not propose assoc items without qualifiers 2021-03-20 22:18:43 +02:00
cynecx
42abfa0f88 hir_ty: add coverage testing for autoderef_visibility_method test 2021-03-20 20:35:57 +01:00
cynecx
2dc85f739a hir_ty: fix test by removing trailing whitespace 2021-03-20 19:58:00 +01:00
cynecx
ac2a831b2e hir_ty: iterate_method_candidates_for_self_ty pass visible_from_module down to iterate_inherent_methods 2021-03-20 19:50:55 +01:00
cynecx
66d295d72d hir_ty: fix visibility in infer_inherent_method test 2021-03-20 19:47:14 +01:00
Kevin Mehall
0a0e22235b Make bare underscore token an Ident rather than Punct in proc-macro 2021-03-20 12:28:44 -06:00
cynecx
34bb13e293 hir_ty: introduce visible_from_module param into method resolution 2021-03-20 19:28:26 +01:00
cynecx
b1b456c642 hir_ty: check field visibility while iterating through autoderef candidates 2021-03-20 19:07:23 +01:00
cynecx
30980396af hir_ty: add field_visibilities and fn_visibility queries 2021-03-20 18:29:30 +01:00
cynecx
edfd741c5b hir_ty: add tests around autoderef with visibility checking 2021-03-20 17:26:18 +01:00
cynecx
15e4aae823 hir_ty: fix tests by making required methods public 2021-03-20 17:12:49 +01:00
bors[bot]
5cc8ad0c4a
Merge #8119
8119:  Don't return a SourceChange on WillRenameFiles when nothing gets refactored r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-20 12:58:28 +00:00
Lukas Wirth
a9a7c5cb1f Don't return a SourceChange on WillRenameFiles when nothing gets refactored 2021-03-20 13:57:58 +01:00
Lukas Wirth
d84912483d Fix add_life_to_type label typo 2021-03-20 13:44:12 +01:00
Florian Diebold
7ec3b66f7a Turn Obligation into something similar to chalk_ir::DomainGoal
This includes starting to make use of Chalk's `Cast` trait.
2021-03-20 12:47:12 +01:00
Florian Diebold
8e7e405f6a Remove WhereClause::Error
Chalk doesn't have it, and judging from the removed code, it wasn't
useful anyway.
2021-03-20 10:51:00 +01:00
Florian Diebold
7a5fb37cf1 Rename GenericPredicate -> WhereClause 2021-03-20 10:46:36 +01:00
Jonas Schievink
636de3c709 Add AttrsWithOwner and clean up source_map 2021-03-19 21:23:57 +01:00
Jonas Schievink
fc5f73de45 Move AttrsOwnerNode to syntax and make it public 2021-03-19 20:05:17 +01:00
Jonas Schievink
93aeb16eb2 Return Either from MacroDefId::ast_id 2021-03-19 19:56:13 +01:00
bors[bot]
0392e63c95
Merge #8110
8110: simplify r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-19 18:01:34 +00:00
Aleksey Kladov
ba72308588 simplify
changelog skip
2021-03-19 21:00:20 +03:00
bors[bot]
b54e4b87e8
Merge #8109
8109: Make ast editing more ergonomic r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-19 17:54:30 +00:00
Aleksey Kladov
a61691026a Make ast editing more ergonomic
changelog internal
2021-03-19 20:53:23 +03:00
Jonas Schievink
cf494a515f Fix handling of #![cfg] in outline module file 2021-03-19 18:24:04 +01:00
ivan770
d331155f8d
Remove needless lifetime 2021-03-19 17:01:39 +02:00
ivan770
2794cc7b00
Added more movable lists 2021-03-19 16:43:47 +02:00
Jonas Schievink
506467b4c8 Add builtin macro-like attributes 2021-03-19 14:33:31 +01:00
Jonas Schievink
54c78c96db Rename derive-specific APIs 2021-03-19 14:23:13 +01:00
Lukas Wirth
c34a9f10b1 Cleanup qualify_path 2021-03-19 13:12:00 +01:00
bors[bot]
7200b994c9
Merge #8097
8097: Parse extended_key_value_attributes r=jonas-schievink a=Veykril

Companion PR https://github.com/rust-analyzer/ungrammar/pull/31

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-19 11:38:40 +00:00
bors[bot]
98d29d4f53
Merge #8101
8101: Replace Projection variant in GenericPredicate with AliasEq r=flodiebold a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-19 11:12:54 +00:00
Lukas Wirth
8996b1a235 Replace Projection variant in GenericPredicate with AliasEq 2021-03-19 12:12:18 +01:00
ivan770
0a2d221d47
Added arglist mover 2021-03-19 10:28:09 +02:00
Lukas Wirth
4771a56791 Parse extended_key_value_attributes 2021-03-19 02:13:46 +01:00
Jonas Schievink
fcbaf585cb Document fields of ModuleId 2021-03-19 00:06:35 +01:00
bors[bot]
86878443b1
Merge #8095
8095: Fix associated items not being appended to paths in import_assets r=SomeoneToIgnore a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-18 21:40:12 +00:00
Lukas Wirth
8c0f454d11 Use a highlight modifier for intra doc links 2021-03-18 22:32:07 +01:00
Florian Diebold
7a7e47eab7 Chalkify TraitRef 2021-03-18 21:53:19 +01:00
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
Edwin Cheng
8cc0c7f420 Add no-sysroot flag for analysis-stats 2021-03-14 18:31:14 +08:00
ivan770
8a9ebe62a1
Skip ref_match on same types, remove sorting in tests 2021-03-14 12:25:37 +02:00
bors[bot]
48adf6b697
Merge #8010
8010: Attach trivia to ast::Union nodes r=Veykril a=Veykril

Closes #8007
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-14 10:13:38 +00:00
Lukas Wirth
6e6d75bbdc Attach trivia to ast::Union nodes 2021-03-14 11:11:01 +01:00
Brandon
2df637f419 Fix incorrect diagnositics for failing built in eager macros 2021-03-13 21:28:10 -08:00
Brandon
4245973e24 Fix spelling error 2021-03-13 20:07:20 -08:00
Edwin Cheng
7279749bbb Simpify mbe bindings builder 2021-03-14 11:54:19 +08:00
Edwin Cheng
b3b91046dd Make sure ill-form macro handle propely 2021-03-14 11:24:55 +08:00
Florian Diebold
3743ede404 Move type lowering methods to TyLoweringContext 2021-03-13 22:44:36 +01:00
Florian Diebold
c82d1823a1 Create TraitEnvironment through a query 2021-03-13 20:38:45 +01:00
Florian Diebold
b035c314b4 Use chalk_ir::OpaqueTyId 2021-03-13 20:05:47 +01:00
Florian Diebold
1bf6b7360c Use chalk_ir::PlaceholderIndex 2021-03-13 19:47:34 +01:00
Florian Diebold
2d69eb131f Use chalk_ir::ClosureId 2021-03-13 19:27:09 +01:00
Jonas Schievink
1848bd0fa0 Handle cfg_attr gating multiple attributes 2021-03-13 18:18:42 +01:00
Jonas Schievink
72785fb94d Extend cfg_attr test 2021-03-13 18:18:05 +01:00
Florian Diebold
9719ce9fc7 Use chalk_ir::FnDefId 2021-03-13 17:56:48 +01:00
Florian Diebold
19664e276a Use chalk_ir::AssocTypeId 2021-03-13 17:56:48 +01:00
Florian Diebold
dfafcd926a Use chalk_ir::ForeignDefId 2021-03-13 17:56:48 +01:00
ivan770
661cc7f0c8
Added both references and original matches to tests 2021-03-13 18:31:52 +02:00
Aleksey Kladov
a9c3e70443 fix folding range kind 2021-03-13 19:24:28 +03:00
ivan770
32ad929b82
Fix incorrect DerefMut test reference type 2021-03-13 17:28:05 +02:00
ivan770
3bc5d81a33
Make relevance tests display references, suggest derefs only when needed 2021-03-13 17:25:41 +02:00
Florian Diebold
6c32bbf3ca Separate Ty and TyKind like in Chalk
Currently `Ty` just wraps `TyKind`, but this allows us to change most
places to already use `intern` / `interned`.
2021-03-13 16:17:15 +01: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
ivan770
75cb441fba
Simplify call site and deref completion test 2021-03-13 15:32:37 +02:00
bors[bot]
9674490b45
Merge #7981
7981: Allow applying De Morgan's law to multiple terms at once r=matklad a=shepmaster



Co-authored-by: Jake Goulding <jake.goulding@gmail.com>
2021-03-13 13:31:55 +00:00
bors[bot]
ceffcf8a11
Merge #7984
7984: Improve version display r=matklad a=lnicola

Maybe closes #7854

The version string for unreleased builds looks like this now:

```
$ rust-analyzer --version
rust-analyzer 2021-03-08-159-gc0459c535
```

Release builds should only have the tag name (`2021-03-15`).

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-13 13:22:25 +00:00
bors[bot]
fe4a94fff3
Merge #7994
7994: Speed up mbe matching in heavy recursive cases r=edwin0cheng a=edwin0cheng

In some cases (e.g.  #4186), mbe matching is very slow due to a lot of copy and allocation for bindings, this PR try to solve this problem by introduce a semi "link-list" approach for bindings building.

I used this [test case](https://github.com/weiznich/minimal_example_for_rust_81262) (for `features(32-column-tables)`) to run following command to benchmark:
```
time rust-analyzer analysis-stats  --load-output-dirs ./ 
```

Before this PR : 2 mins
After this PR: 3 seconds.

However, for 64-column-tables cases, we still need 4 mins to complete. 

I will try to investigate in the following weeks.

bors r+




Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-13 13:04:45 +00:00
Edwin Cheng
9117148f42 Add bindings builder for speed up matching 2021-03-13 20:52:36 +08:00
ivan770
d064ed5f63
Count derefs as matched types if possible 2021-03-13 14:34:11 +02:00
Edwin Cheng
f1350dd93c add expand log 2021-03-13 20:14:21 +08:00
Jonas Schievink
2b5ea5c730 Simplify hir_def TestDB 2021-03-13 02:24:53 +01:00
Jonas Schievink
8447f101ac Remove ItemTree::source
`HasSource` should be used instead
2021-03-12 23:54:29 +01:00
Josh Mcguigan
d5f0f58e63 add params_display and ty_display 2021-03-12 13:46:40 -08:00
Josh Mcguigan
53bb46fa85 show function params in completion detail 2021-03-12 13:36:13 -08:00
Florian Diebold
784636f1c1 Simplify a bit 2021-03-12 20:51:29 +01:00
Florian Diebold
ec70387a4c Use Chalk Environment more directly 2021-03-12 19:12:17 +01:00
Laurențiu Nicola
88ef0541a5 Improve version display 2021-03-12 19:49:00 +02:00
Jake Goulding
63155d66f5 Allow applying De Morgan's law to multiple terms at once 2021-03-12 10:19:54 -05:00
bors[bot]
c0459c5357
Merge #7956
7956: Add assist to convert for_each into for loops r=Veykril a=SaiintBrisson

This PR resolves #7821.
Adds an assist to that converts an `Iterator::for_each` into a for loop: 

```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    x.iter().for_each(|(x, y)| {
        println!("x: {}, y: {}", x, y);
    })
}
```
becomes
```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    for (x, y) in x.iter() {
        println!("x: {}, y: {}", x, y);
    });
}
```

Co-authored-by: Luiz Carlos Mourão Paes de Carvalho <luizcarlosmpc@gmail.com>
Co-authored-by: Luiz Carlos <luizcarlosmpc@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 14:45:04 +00:00
Lukas Wirth
6d35c67b6e Fix convert_iter_for_each_to_for doctest 2021-03-12 15:42:53 +01:00
bors[bot]
19dd1fd4d4
Merge #7904
7904: Improved completion sorting r=JoshMcguigan a=JoshMcguigan

I was working on extending #3954 to apply completion scores in more places (I'll have another PR open for that soon) when I discovered that actually completion sorting was not working for me at all in `coc.nvim`. This led me down a bit of a rabbit hole of how coc and vs code each sort completion items.

Before this PR, rust-analyzer was setting the `sortText` field on completion items to `None` if we hadn't applied any completion score for that item, or to the label of the item with a leading whitespace character if we had applied any completion score. Completion score is defined in rust-analyzer as an enum with two variants, `TypeMatch` and `TypeAndNameMatch`. 

In vs code the above strategy works, because if `sortText` isn't set [they default it to the label](b4ead4ed66). However, coc [does not do this](e211e36147/src/completion/complete.ts (L245)).

I was going to file a bug report against coc, but I read the [LSP spec for the `sortText` field](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion) and I feel like it is ambiguous and coc could claim what they do is a valid interpretation of the spec.

Further, the existing rust-analyzer behavior of prepending a leading whitespace character for completion items with any completion score does not handle sorting `TypeAndNameMatch` completions above `TypeMatch` completions. They were both being treated the same.

The first change this PR makes is to set the `sortText` field to either "1" for `TypeAndNameMatch` completions, "2" for `TypeMatch` completions, or "3" for completions which are neither of those. This change works around the potential ambiguity in the LSP spec and fixes completion sorting for users of coc. It also allows `TypeAndNameMatch` items to be sorted above just `TypeMatch` items (of course both of these will be sorted above completion items without a score). 

The second change this PR makes is to use the actual completion scores for ref matches. The existing code ignored the actual score and always assumed these would be a high priority completion item.

#### Before

Here coc just sorts based on how close the items are in the file.

![image](https://user-images.githubusercontent.com/22216761/110249880-46063580-7f2d-11eb-9233-91a2bbd48238.png)

#### After

Here we correctly get `zzz` first, since that is both a type and name match. Then we get `ccc` which is just a type match.

![image](https://user-images.githubusercontent.com/22216761/110249883-4e5e7080-7f2d-11eb-9269-a3bc133fdee7.png)


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-12 14:23:32 +00:00
Josh Mcguigan
acbe297fbd update relevance score u8 -> u32 2021-03-12 06:16:04 -08:00
Josh Mcguigan
10fb065b14 add relevance score test 2021-03-12 06:16:04 -08: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
Lukas Wirth
ebf4448f78 Fix remaining references to cargo xtask codegen 2021-03-12 15:10:33 +01:00
Luiz Carlos Mourão Paes de Carvalho
e505752442 fix: generated test fixture 2021-03-12 08:53:57 -03:00
Luiz Carlos
7a9230acdf
fix: replace doc-comments with normal comments
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 08:44:03 -03:00
Luiz Carlos Mourão Paes de Carvalho
f67861310c refactor: refactored and reduced assist code 2021-03-12 08:06:50 -03:00
Aleksey Kladov
7e217a42e1 Unify naming 2021-03-12 12:22:45 +03:00
yonip23
99c4a41cd1 use references in CompletionItem's builder 2021-03-11 17:46:41 +02: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
Conrad Ludgate
233820d780
fix: add semicolon after type ascription 2021-03-11 10:36:45 +00:00
Lukas Wirth
98d2dbb90e Return original text range in PrepareRename responses when inside macro 2021-03-10 22:26:41 +01:00
Jonas Schievink
bc4ecb199b Use expect-test for builtin macro/derive tests 2021-03-10 21:05:02 +01:00
Jonas Schievink
7b1a0d5fb7 Diagnose files that aren't in the module tree 2021-03-10 20:30:20 +01:00
bors[bot]
6c32e2d8a0
Merge #7965
7965: cargo update and lexer r=kjeremy a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-03-10 18:59:19 +00:00
kjeremy
08e0e9976d cargo update and lexer 2021-03-10 13:47:12 -05:00
Luiz Carlos Mourão Paes de Carvalho
6236b1eaf8 fix: remove semicolon 2021-03-10 15:43:57 -03:00
Jonas Schievink
2b8674b37e Implement builtin cfg! macro 2021-03-10 19:43:03 +01:00
bors[bot]
f0e78f2ed6
Merge #7961
7961: add user docs for ssr assist r=JoshMcguigan a=JoshMcguigan

@matklad 

This is a small follow up on #7874, adding user docs for the SSR assist functionality. Since most other assists aren't handled this way I wasn't sure exactly how we wanted to document this, so feel free to suggest alternatives.

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-10 17:06:11 +00:00
Josh Mcguigan
40587b08a0 add user docs for ssr assist 2021-03-10 09:04:47 -08:00
Jonas Schievink
c2622c9228 Prefer names from outer DefMap over extern prelude 2021-03-10 16:33:18 +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
Kirill Bulatov
94bb9cb9ee Fix labels for single import assists 2021-03-10 11:30:25 +02:00
Luiz Carlos Mourão Paes de Carvalho
a224e0087d fix: code formatting 2021-03-10 00:32:25 -03:00
Luiz Carlos Mourão Paes de Carvalho
b7f97715a3 fix: tests should work for convert_iter_for_each_to_for 2021-03-10 00:23:20 -03:00
Luiz Carlos Mourão Paes de Carvalho
87dc9d1fcc refactor: create block expressions and for loops using make 2021-03-09 23:55:26 -03:00
Luiz Carlos Mourão Paes de Carvalho
61fb16577b feat: add expr_for_loop to make in syntax 2021-03-09 23:54:35 -03:00
Luiz Carlos Mourão Paes de Carvalho
eea21490e0 feat: add assist to conver for_each into for loops 2021-03-09 22:58:17 -03:00
Jonas Schievink
7beec8fda1 Stop fetching ItemTrees for no reason 2021-03-10 02:32:16 +01:00
bors[bot]
654313dbc7
Merge #6822
6822: Read version of rustc that compiled proc macro r=edwin0cheng a=jsomedon

Signed-off-by: Jay Somedon <jay.somedon@outlook.com>

This PR is to fix #6174.

I basically
* added two methods, `read_version` and `read_section`(used by `read_version`)
* two new crates `snap` and `object` to be used by those two methods

I just noticed that some part of code were auto-reformatted by rust-analyzer on file save. Does it matter?

Co-authored-by: Jay Somedon <jay.somedon@outlook.com>
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-09 20:57:04 +00:00
Edwin Cheng
ad34e79bb9 use doc-comments 2021-03-10 04:54:31 +08:00
Aleksey Kladov
842d8ad9c8 Compilation speed 2021-03-09 22:30:58 +03:00
Jonas Schievink
b885e6bdee Delete ContainerId 2021-03-09 19:09:02 +01:00
bors[bot]
9a5c72d9f0
Merge #7878
7878: Remove `item_scope` field from `Body` r=jonas-schievink a=jonas-schievink

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

Instead of storing an `ItemScope` filled with inner items, we store the list of `BlockId`s for all block expressions that are part of a `Body`. Code can then query the `block_def_map` for those.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2021-03-09 17:34:18 +00:00
Jonas Schievink
a430549aa6 Stop using ContainerId in AssocContainerId 2021-03-09 18:27:23 +01:00
Jonas Schievink
12f6bdcfd9 Check ancestor maps when computing traits in scope 2021-03-09 18:27:23 +01:00
Jonas Schievink
6be4f30cae Remove item_scope field from Body 2021-03-09 18:27:23 +01:00
Jonas Schievink
1da0a27626 Use body.block_scopes in hir_ty tests 2021-03-09 18:27:23 +01:00
Jonas Schievink
0cb46a9e8d Use body.block_scopes to validate inner items 2021-03-09 18:27:23 +01:00
Jonas Schievink
c12f7be8d3 Use body.block_scopes in ChildBySource 2021-03-09 18:27:23 +01:00
Jonas Schievink
13f4356d2f Store inner BlockIds in Body 2021-03-09 18:27:23 +01:00
Jonas Schievink
8da50c9077 Change ChildBySource to allow reusing DynMap 2021-03-09 18:27:23 +01:00
bors[bot]
84eed2136b
Merge #7945
7945: Future proof completion scores r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-09 17:25:23 +00:00
Aleksey Kladov
b2764a6641 Future proof completion scores 2021-03-09 20:24:09 +03:00
bors[bot]
c45ac6effe
Merge #7942
7942: Show whether a binding is mutable or not on hover r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-09 16:23:51 +00:00
Lukas Wirth
814d617d34 Show whether a binding is mutable or not on hover 2021-03-09 17:18:50 +01:00
bors[bot]
c2359608c9
Merge #7944
7944: Selecting `&mut foo` completion now actually inserts `&mut` r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-09 16:05:23 +00:00
Aleksey Kladov
73b9937e4e Selecting &mut foo completion now actually inserts &mut 2021-03-09 19:04:27 +03:00
Lukas Wirth
983726a45c Don't show const items initializer expressions on hover 2021-03-09 16:33:23 +01:00
Aleksey Kladov
12fe301a0c Cleanup auto-ref in completion 2021-03-09 18:06:08 +03:00
bors[bot]
472641fc5b
Merge #7941
7941: Fix unused definitions not being document highlit r=Veykril a=Veykril

Fixes #7939

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-09 14:54:24 +00:00
Lukas Wirth
a1f080138a Fix unused definitions not being document highlit 2021-03-09 15:45:31 +01:00
Aleksey Kladov
abc0ed36bd Cleanup 2021-03-09 17:44:27 +03:00
Aleksey Kladov
444d67ae18 Cleanup 2021-03-09 17:42:05 +03:00
Aleksey Kladov
2cc278c6ff Fix bad names
`res` should only be used for the result variable
2021-03-09 17:39:22 +03:00
bors[bot]
21913d0fdb
Merge #7873 #7933
7873: Consider unresolved qualifiers during flyimport r=matklad a=SomeoneToIgnore

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

Takes unresolved qualifiers into account, providing better completions (or none, if the path is resolved or do not match).

Does not handle cases when both path qualifier and some trait has to be imported: there are many extra issues with those (such as overlapping imports, for instance) that will require large diffs to address.

Also does not do a fuzzy search on qualifier, that requires some adjustments in `import_map` for better queries and changes to the default replace range which also seems relatively big to include here.

![qualifier_completion](https://user-images.githubusercontent.com/2690773/110040808-0af8dc00-7d4c-11eb-83db-65af94e843bb.gif)


7933: Improve compilation speed r=matklad a=matklad

bors r+
🤖

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-09 11:58:48 +00:00
Aleksey Kladov
867fdf8f03 Improve compilation speed 2021-03-09 14:54:50 +03:00
Aleksey Kladov
37b7b56821 Make code less surprising
Theres no reason to have literal `\n\n` in the source code
2021-03-09 14:47:42 +03:00
bors[bot]
ffba4c0dce
Merge #7931
7931: Use `Type::new_with_resolver_inner` more r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-09 11:36:40 +00:00
Jonas Schievink
30791c5295 Use Type::new_with_resolver_inner more 2021-03-09 12:31:16 +01:00
bors[bot]
844b7f7411
Merge #7927
7927: Add more documentation for rustc_private r=matklad a=jyn514



Co-authored-by: Joshua Nelson <jyn514@gmail.com>
2021-03-09 11:22:37 +00:00
Duong Do Minh Chau
73590f0f0b
Fix format 2021-03-09 16:38:07 +07:00
Duong Do Minh Chau
a068cedee0
Add trailing commas 2021-03-09 16:00:06 +07:00
Duong Do Minh Chau
ea835fc800
Update the test to match the change 2021-03-09 15:48:53 +07:00
Duong Do Minh Chau
5fc91058ff
Add completion to turn x.err into Err(x) 2021-03-09 15:36:41 +07:00
bors[bot]
3fdf26a6fc
Merge #7898
7898: generate_function assist: infer return type r=JoshMcguigan a=JoshMcguigan

This PR makes two changes to the generate function assist:

1. Attempt to infer an appropriate return type for the generated function
2. If a return type is inferred, and that return type is not unit, don't render the snippet

```rust
fn main() {
    let x: u32 = foo$0();
    //              ^^^ trigger the assist to generate this function
}

// BEFORE
fn foo() ${0:-> ()} {
    todo!()
}

// AFTER (only change 1)
fn foo() ${0:-> u32} {
    todo!()
}

// AFTER (change  1 and 2, note the lack of snippet around the return type)
fn foo() -> u32 {
    todo!()
}
```

These changes are made as two commits, in case we want to omit change 2. I personally feel like it is a nice change, but I could understand there being some opposition.

#### Pros of change 2
If we are able to infer a return type, and especially if that return type is not the unit type, the return type is almost as likely to be correct as the argument names/types. I think this becomes even more true as people learn how this feature works.

#### Cons of change 2

We could never be as confident about the return type as we are about the function argument types, so it is more likely a user will want to change that. Plus it is a confusing UX to sometimes have the cursor highlight the return type after triggering this assist and sometimes not have that happen.

#### Why omit unit type?

The assumption is that if we infer the return type as unit, it is likely just because of the current structure of the code rather than that actually being the desired return type. However, this is obviously just a heuristic and will sometimes be wrong. But being wrong here just means falling back to the exact behavior that existed before this PR.



Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-08 22:51:04 +00:00
Josh Mcguigan
b275e60905 generate_function assist don't render snippet if ret type inferred 2021-03-08 14:38:36 -08:00
Kirill Bulatov
778deb38fe Better strip turbofishes 2021-03-08 23:59:39 +02:00
Kirill Bulatov
5168ab16e1 Add rustdocs and use better names 2021-03-08 23:59:37 +02:00
Kirill Bulatov
dccbb38d2e Less lifetines: derive SemanticsScope in place 2021-03-08 23:59:20 +02:00
Kirill Bulatov
db61d4ea13 Rebase leftovers 2021-03-08 23:59:20 +02:00
Kirill Bulatov
c56b59d377 Cleanup 2021-03-08 23:59:20 +02:00
Kirill Bulatov
84c575a212 Restrict fuzzy qualifiers for now 2021-03-08 23:59:20 +02:00
Kirill Bulatov
6ca6f101c1 Test for fuzzy unresolved path maatch 2021-03-08 23:59:20 +02:00
Kirill Bulatov
5b7d928075 Enforce the located imports' order 2021-03-08 23:59:20 +02:00
Kirill Bulatov
24a5d3b19d Fix the completion labels and tests 2021-03-08 23:59:20 +02:00
Kirill Bulatov
33c83e72b9 Work towards better import labels 2021-03-08 23:59:20 +02:00
Kirill Bulatov
4d4ac1d4fa Profile import_assets better 2021-03-08 23:59:20 +02:00
Kirill Bulatov
821e8369d9 Update the docs 2021-03-08 23:59:20 +02:00
Kirill Bulatov
e214c3a6bd Simplify 2021-03-08 23:59:20 +02:00