Commit Graph

13083 Commits

Author SHA1 Message Date
bors[bot]
aa1cdc0cce
Merge #10095
10095: internal: Augment panic context when resolving path r=jonas-schievink a=jonas-schievink

Should help with debugging https://github.com/rust-analyzer/rust-analyzer/issues/10084 and similar issues.

Might have a perf impact since the string is created on every function call.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-08-31 12:47:33 +00:00
Aleksey Kladov
722a2a4690 minor: improve readability
naming, layout & comments help!
2021-08-31 15:46:00 +03:00
bors[bot]
4786a22787
Merge #10098
10098: minor: dead code r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-31 12:27:27 +00:00
Aleksey Kladov
f1222e8085 minor: dead code 2021-08-31 15:26:59 +03:00
bors[bot]
bda50a1b46
Merge #10097
10097: fix: Allow inherent impls for arrays r=jonas-schievink a=jonas-schievink

Part of https://github.com/rust-analyzer/rust-analyzer/issues/9992 (method resolution of these methods still does not work)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-08-31 12:17:50 +00:00
Jonas Schievink
418b163a4b Allow inherent impl for arrays 2021-08-31 14:15:39 +02:00
Aleksey Kladov
51b955ec8a internal: simplify 2021-08-31 15:09:46 +03:00
Jonas Schievink
b1a4784c95 Augment panic context when resolving path 2021-08-31 13:42:46 +02:00
bors[bot]
f70086203b
Merge #10094
10094: internal: split database loading time in anaysis-stats into components r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-31 11:39:34 +00:00
Aleksey Kladov
8dbf3832b2 internal: split database loading time in anaysis-stats into components 2021-08-31 14:38:52 +03:00
bors[bot]
545cdf955e
Merge #10091
10091: fix: fix "disjunction in conjunction" panic r=matklad a=jonas-schievink

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

The DNF construction code created expressions that were combined in a way that made us "forget" to make their contents valid DNF again. This PR fixes that by flattening nested `any(any())` and `all(all())` predicates. There was also a typo that led to a redundant call to `make_nnf` instead of the correct recursive call to `make_dnf` (but this didn't seem to break/fix anything).

This also adds some light property testing, though I'm not really sure this is the best way to do it.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-08-31 11:24:30 +00:00
Jonas Schievink
8c9de51fa3 Simplify int_in_range 2021-08-31 13:11:17 +02:00
Jonas Schievink
8969cbb22f Depend on both crates individually 2021-08-31 13:10:16 +02:00
bors[bot]
70dbf35712
Merge #10092
10092: feat: Improve `extract_struct_from_enum_variant` output r=matklad a=DropDemBits

Improves the struct generated by `extract_struct_from_enum_variant`.

Summary of changes:

- Indent the generated struct and enum to the same indent level
- Preserve comments & attributes from the enum variant (something I missed when doing the same thing for the variant fields)
- Use enum's visibility for fields without any visibility, instead of filling it in with `pub`

Co-authored-by: DropDemBits <r3usrlnd@gmail.com>
2021-08-31 09:11:53 +00:00
DropDemBits
3bafb5f025
feat: Use enum's visibility for extracted struct fields 2021-08-30 21:33:19 -04:00
DropDemBits
95bf89d3c8
fix: Keep comments & attrs from enum variant 2021-08-30 21:33:12 -04:00
DropDemBits
681efe6dcb
feat: Properly indent extracted struct and enum 2021-08-30 21:26:21 -04:00
Jonas Schievink
e6255356d2 Fix DNF construction, add proptest 2021-08-30 22:26:35 +02:00
bors[bot]
20f3792d10
Merge #10089
10089: Fix minor mispelling r=bjorn3 a=NerdyPepper

`find_map` misspelt as `wind_map` in test identifier. 

Co-authored-by: Akshay <nerdy@peppe.rs>
2021-08-30 19:35:00 +00:00
bors[bot]
02a3d898e4
Merge #10076
10076: Use struct init shorthand when applicable in fill struct fields assist r=matklad a=nathanwhit

This PR tweaks the fill struct fields assist to use the struct init shorthand when a local variable with a matching name and type is in scope.

For example:
```rust
struct Foo {
    a: usize,
    b: i32,
    c: char,
}

fn main() {
    let a = 1;
    let b = 2;
    let c = 3;
    let foo = Foo { <|> };
}
```
Before we would insert
```rust
Foo {
    a: (),
    b: (),
    c: (),
}
```
now we would insert
```rust
Foo {
    a,
    b,
    c: ()
}
```

Co-authored-by: nathan.whitaker <nathan.whitaker01@gmail.com>
2021-08-30 18:55:18 +00:00
nathan.whitaker
e1d86a42fe Add coverage mark for struct init shorthand test 2021-08-30 14:37:03 -04:00
Akshay
e304a623ad fix minor mispelling
find_map misspelt as wind_map
2021-08-30 22:51:14 +05:30
Aleksey Kladov
53d2050085 feat: improve CPU usage
closes #9922

Turned out to be trivial after preliminary refactor.

The intended behavior is that we schedule cache priming once ws become
quiescent (that is, we fully load cargo project), and we continue to
rschedule it until it completes (priming might get cancelled by user
typing into a file).
2021-08-30 19:48:16 +03:00
Aleksey Kladov
9e0203bd69 internal: make scheduling control flow more obvious
There should be only one place where we need to check if we want to
start background activities.
2021-08-30 19:39:08 +03:00
Aleksey Kladov
a59f344c4f internal: improve consistency
Let's have only one place where we start delayed ops
2021-08-30 19:24:31 +03:00
Aleksey Kladov
6317292cd5 internal: more obviously correct code for cache priming progerss
It doesn't make sense for the prime_caches itself send begin/end events
-- the caller knows perfectly fine when they happen!
2021-08-30 19:18:48 +03:00
bors[bot]
bb1987b45e
Merge #10085
10085: fix: avoid panic when parsing extern block r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-30 12:57:39 +00:00
Aleksey Kladov
4452f9ec48 internal: improve style
Group related stuff together, use only on path for parsing extern blocks
(they actually have modifiers).

Perhaps we should get rid of items_without_modifiers altogether? Better
to handle these kinds on diagnostics in validation layer...
2021-08-30 15:55:40 +03:00
Aleksey Kladov
8dc3b46017 fix: avoid panic when parsing extern block
closes #10083
2021-08-30 15:40:47 +03:00
Mario Carneiro
b22eb02f8b
fail -> failed 2021-08-30 02:47:10 -07:00
Mario Carneiro
2d349aed2e
Update crates/hir_expand/src/db.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-08-30 02:43:13 -07:00
Mario Carneiro
6e8dedadcd
Fix error message
I'm not entirely sure if the message is still correct, it seems to have survived a number of refactors, but it is mangled english anyway.
2021-08-30 02:36:21 -07:00
bors[bot]
1636f61a15
Merge #10005
10005: Extend `CargoConfig.unset_test_crates`  r=matklad a=regexident

This is to allow for efficiently disabling `#[cfg(test)]` on all crates (by passing `unset_test_crates: UnsetTestCrates::All`) without having to first load the crate graph, when using rust-analyzer as a library.

(FYI: The change doesn't seem to be covered by any existing tests.)

Co-authored-by: Vincent Esche <regexident@gmail.com>
2021-08-30 08:42:13 +00:00
bors[bot]
d250aa77ec
Merge #10015
10015: internal: more declarative re-indentation API r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-30 08:34:49 +00:00
bors[bot]
ceecf853ee
Merge #10080
10080: internal: don't shut up the compiler when it says the code's buggy r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-30 07:58:59 +00:00
Aleksey Kladov
a833fba98a internal: don't shut up the compiler when it says the code's buggy
Wrapping state-modifying functions into a `catch_unwind` is wrong -- to
do retry after failure, you need to have transactional semantics!
2021-08-30 10:58:39 +03:00
bors[bot]
b3452dd379
Merge #10079
10079: internal: make upstream bug less annoying r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-30 07:39:34 +00:00
Aleksey Kladov
3a055a6b1f internal: make upstream bug less annoying 2021-08-30 10:32:59 +03:00
Dezhi Wu
ba0947dded switch log crate to tracing 2021-08-30 15:11:42 +08:00
nathan.whitaker
e4757f9407 Update existing fill struct fields test 2021-08-29 13:14:15 -04:00
nathan.whitaker
251f9dfc8a Add tests for fill struct fields shorthand 2021-08-29 13:14:03 -04:00
nathan.whitaker
dcd4157420 Use struct init shorthand in fill struct fields assist 2021-08-29 13:12:59 -04:00
Aleksey Kladov
cfa3f679e9 internal: don't expose impl details out of hir 2021-08-29 18:55:25 +03:00
Aleksey Kladov
76b60efbfb internal: improve compile times a bit
before after for cargo llvm-lines -q --lib --release -p ide_ssr | head -n 24

  Lines          Copies        Function name
  -----          ------        -------------
  297146 (100%)  12748 (100%)  (TOTAL)
    5970 (2.0%)     47 (0.4%)  core::iter::traits::iterator::Iterator::try_fold
    4750 (1.6%)     27 (0.2%)  hashbrown::raw::RawTable<T,A>::resize
    4080 (1.4%)     30 (0.2%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    3933 (1.3%)     69 (0.5%)  alloc::raw_vec::RawVec<T,A>::current_memory
    3668 (1.2%)     89 (0.7%)  <core::result::Result<T,E> as core::ops::try_trait::Try>::branch
    3500 (1.2%)     50 (0.4%)  hashbrown::raw::RawTable<T,A>::drop_elements
    3436 (1.2%)     33 (0.3%)  hashbrown::raw::RawTable<T,A>::find
    3415 (1.1%)     17 (0.1%)  hashbrown::raw::RawTable<T,A>::rehash_in_place
    3400 (1.1%)     50 (0.4%)  <hashbrown::raw::RawIterRange<T> as core::iter::traits::iterator::Iterator>::next
    2840 (1.0%)     20 (0.2%)  alloc::raw_vec::RawVec<T,A>::allocate_in
    2700 (0.9%)     30 (0.2%)  core::alloc::layout::Layout::array
    2666 (0.9%)     86 (0.7%)  core::ptr::metadata::from_raw_parts_mut
    2495 (0.8%)     50 (0.4%)  core::option::Option<T>::map
    2354 (0.8%)     38 (0.3%)  alloc::alloc::box_free
    2302 (0.8%)      7 (0.1%)  ide_ssr::parsing::RuleBuilder::try_add
    2146 (0.7%)     45 (0.4%)  core::mem::replace
    2070 (0.7%)     69 (0.5%)  <alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop
    1979 (0.7%)     16 (0.1%)  hashbrown::map::HashMap<K,V,S,A>::insert
    1926 (0.6%)     18 (0.1%)  <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next
    1922 (0.6%)     62 (0.5%)  core::fmt::ArgumentV1::new
    1885 (0.6%)     13 (0.1%)  alloc::raw_vec::RawVec<T,A>::shrink

  Lines          Copies        Function name
  -----          ------        -------------
  261717 (100%)  11666 (100%)  (TOTAL)
    5239 (2.0%)     42 (0.4%)  core::iter::traits::iterator::Iterator::try_fold
    4750 (1.8%)     27 (0.2%)  hashbrown::raw::RawTable<T,A>::resize
    3933 (1.5%)     69 (0.6%)  alloc::raw_vec::RawVec<T,A>::current_memory
    3536 (1.4%)     26 (0.2%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    3500 (1.3%)     50 (0.4%)  hashbrown::raw::RawTable<T,A>::drop_elements
    3400 (1.3%)     50 (0.4%)  <hashbrown::raw::RawIterRange<T> as core::iter::traits::iterator::Iterator>::next
    3124 (1.2%)     30 (0.3%)  hashbrown::raw::RawTable<T,A>::find
    2812 (1.1%)     14 (0.1%)  hashbrown::raw::RawTable<T,A>::rehash_in_place
    2604 (1.0%)     84 (0.7%)  core::ptr::metadata::from_raw_parts_mut
    2340 (0.9%)     26 (0.2%)  core::alloc::layout::Layout::array
    2302 (0.9%)      7 (0.1%)  ide_ssr::parsing::RuleBuilder::try_add
    2272 (0.9%)     16 (0.1%)  alloc::raw_vec::RawVec<T,A>::allocate_in
    2201 (0.8%)     35 (0.3%)  alloc::alloc::box_free
    2104 (0.8%)     44 (0.4%)  core::mem::replace
    2079 (0.8%)     42 (0.4%)  <core::result::Result<T,E> as core::ops::try_trait::Try>::branch
    2070 (0.8%)     69 (0.6%)  <alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop
    1926 (0.7%)     18 (0.2%)  <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next
    1885 (0.7%)     13 (0.1%)  alloc::raw_vec::RawVec<T,A>::shrink
    1833 (0.7%)     13 (0.1%)  hashbrown::raw::RawTable<T,A>::shrink_to
    1771 (0.7%)     91 (0.8%)  core::ptr::read
    1701 (0.6%)     35 (0.3%)  core::option::Option<T>::map
2021-08-29 18:49:16 +03:00
Aleksey Kladov
78365c64c8 internal: slightly improve compile times
As per style guide, avoid monomorphisations
2021-08-29 12:53:56 +03:00
Aleksey Kladov
bef5e3096e minor: remove debug print 2021-08-29 12:33:07 +03:00
Lukas Wirth
6993a607cb Simplify 2021-08-29 01:38:10 +02:00
Lukas Wirth
99f1e66997 Only report unique text ranges in highlight_related 2021-08-29 01:11:29 +02:00
Lukas Wirth
72bfbb0691 Return all usages inside macros in usage searches 2021-08-29 00:49:57 +02:00
Lukas Wirth
512135920d Highlight all related tokens in macro inputs 2021-08-29 00:49:57 +02:00
Lukas Wirth
c5059e0623 Return all ranges corresponding to a token id in TokenMap 2021-08-29 00:49:57 +02:00
Jonas Schievink
002ef7d50a Use ManuallyDrop in RootDatabase 2021-08-28 23:05:40 +02:00
bors[bot]
10e9408d38
Merge #10066
10066: internal: improve compile times a bit r=matklad a=matklad

I wanted to *quickly* remove `smol_str = {features = "serde"}`, and figured out that the simplest way to do that is to replace our straightforward proc macro serialization with something significantly more obscure. 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-28 20:38:58 +00:00
Aleksey Kladov
0d5c671d76 minor: reformat 2021-08-28 23:38:39 +03:00
Aleksey Kladov
c639fe333f internal: improve compilation critical path a bit 2021-08-28 22:43:37 +03:00
Aleksey Kladov
0dabcf0044 remove unused serde feature from smol_str 2021-08-28 22:43:37 +03:00
Aleksey Kladov
55e9476e4b internal: more production-ready proc-macro RPC deserialization
* avoid arbitrary nested JSON tree (danger of stack overflow)
* use more compact representation.
2021-08-28 22:43:37 +03:00
bors[bot]
fae440c32a
Merge #10025
10025: Don't mutate syntax trees when preparing proc-macro input r=Veykril a=Veykril

Fixes #10013

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-28 14:14:54 +00:00
Jonas Schievink
3047ae8d0f Enable diagnostics in const and static items 2021-08-27 23:21:21 +02:00
bors[bot]
99e67f8998
Merge #10044
10044: minor: Ignore text and bench attributes again r=Veykril a=Veykril

Reverts part of #9943

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 20:19:56 +00:00
Lukas Wirth
798c53925a Ignore text and bench attributes again 2021-08-27 22:19:04 +02:00
bors[bot]
97409e5fc8
Merge #9970
9970: feat: Implement attribute input token mapping, fix attribute item token mapping r=Veykril a=Veykril

![image](https://user-images.githubusercontent.com/3757771/130328577-4c1ad72c-51b1-47c3-8d3d-3242ec44a355.png)

The token mapping for items with attributes got overwritten partially by the attributes non-item input, since attributes have two different inputs, the item and the direct input both.
This PR gives attributes a second TokenMap for its direct input. We now shift all normal input IDs by the item input maximum(we maybe wanna swap this see below) similar to what we do for macro-rules/def. For mapping down we then have to figure out whether we are inside the direct attribute input or its item input to pick the appropriate mapping which can be done with some token range comparisons.

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 19:30:36 +00:00
bors[bot]
3acbf94d29
Merge #10057
10057: fix: Remove incorrect assertion in extract_function r=Veykril a=Veykril

This assertion is actually just wrong
Fixes #10056
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 18:00:37 +00:00
Lukas Wirth
5c3a93ca9e Remove incorrect assertion in extract_function 2021-08-27 19:58:57 +02:00
bors[bot]
12a36db71c
Merge #10055
10055: fix: Don't use fake text range in original node search as is in completions r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10042
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 13:11:34 +00:00
Lukas Wirth
ebb87fe157 Don't use fake text range in original node search as is in completions 2021-08-27 15:10:42 +02:00
bors[bot]
ef54dace6a
Merge #10054
10054: minor: Ignore text and bench attributes again r=Veykril a=Veykril

cc https://github.com/rust-analyzer/rust-analyzer/issues/8518#issuecomment-907039593
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 12:21:46 +00:00
Lukas Wirth
5012fa2dd4 Add completion tests for cursor after items 2021-08-27 14:21:17 +02:00
Aleksey Kladov
cb3d04c818 minor: nicer way to defeat disjoint closure captures
Thanks https://internals.rust-lang.org/t/feature-idea-edition-dependent-names-replacing-standard-library-items/15198/27?u=matklad!
2021-08-26 22:13:50 +03:00
unexge
c0d2b44250 fix: correctly complete macro call if cursor at ! 2021-08-26 19:44:46 +03:00
Vincent Esche
74880a10ae Extend CargoConfig.unset_test_crates to allow for efficiently disabling #[cfg(test)] on all crates without having to first load the crate graph 2021-08-26 13:10:14 +02:00
oxalica
15eccf29e8
Fix missing unsafe block for the nightly change
Fix #10022
2021-08-26 17:21:23 +08:00
bors[bot]
793389b61a
Merge #10030
10030: fix: Fix multiple derives in one attribute not expanding all in expand_macro r=Veykril a=Veykril

It's probably better to only expand the exact derive the cursor is on(if possible) instead of all derives in the attribute the cursor is one.
follow up to #10029
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-26 01:34:30 +00:00
Lukas Wirth
0f3617f76f fix: Fix multiple derives in one attribute not expanding all in expand_macro 2021-08-26 03:32:45 +02:00
bors[bot]
49763c3cdb
Merge #10029
10029: internal: Improve expand_macro r=Veykril a=Veykril

- Adds a few more newlines to the output making it more readable
- Fixes a bug with multiple derives not being expandable

There seems to be an issue with multiple derives in one attribute only showing the expansion of the last derive which I'll have to investigate.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-26 00:39:00 +00:00
Lukas Wirth
3f9f63c1bd Improve expand_macro 2021-08-26 02:36:33 +02:00
Lukas Wirth
1195cb50c2 Add simple test for syntax_node_to_token_tree_censored 2021-08-25 19:57:18 +02:00
Lukas Wirth
d6134b6802 Don't mutate syntax trees when preparing proc-macro input 2021-08-25 18:57:24 +02:00
Jonas Schievink
276f6c6ba4 Reduce visibility of WorkspaceBuildScripts::run 2021-08-25 18:02:27 +02:00
Jonas Schievink
0ff2c81bb9 Fix reporting of build script errors 2021-08-25 17:56:39 +02:00
Jonas Schievink
095df7bc39 Don't fetch build script output twice 2021-08-25 17:56:24 +02:00
Aleksey Kladov
d1cd81f387 internal: more declarative re-indentation API 2021-08-24 18:18:43 +03:00
Lukas Wirth
d99b81f839 Expand derive macros under cursor in Expand Macro Recursively 2021-08-24 16:33:52 +02:00
bors[bot]
6287d388c0
Merge #9944
9944: internal: introduce in-place indenting API r=matklad a=iDawer

Introduce `edit_in_place::Indent` that uses mutable tree API and intended to replace `edit::AstNodeEdit`.

Closes #9903 

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-08-24 13:11:50 +00:00
bors[bot]
49c02b93b3
Merge #9993
9993: feat: join lines merges assignments r=matklad a=unexge

Closes https://github.com/rust-analyzer/rust-analyzer/issues/9967.
![Peek 2021-08-22 21-46](https://user-images.githubusercontent.com/16212576/130366571-3ebb1753-f8d5-4884-be8f-222cda71a2a7.gif)


Co-authored-by: unexge <unexge@gmail.com>
2021-08-24 12:14:25 +00:00
Aleksey Kladov
4f8c6193d5 minor: remove dead code 2021-08-24 14:39:31 +03:00
bors[bot]
ea5314d59c
Merge #10010
10010: internal: use idiomatic form of assertions r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-24 11:10:09 +00:00
Aleksey Kladov
1660820e51 internal: use idiomatic form of assertions
Ideally, we should just return an InvalidParameter dialog here, but that
shows error message to the end user, and we generally avoid that
2021-08-24 14:09:34 +03:00
bors[bot]
43021525e5
Merge #9994
9994: add static method generation assist r=matklad a=mahdi-frms

Adds feature: #9948

Will soon send a GIF for the changelog.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-24 09:26:52 +00:00
Lukas Wirth
631bca786f Highlight declarations and references for both defs in field shorthands 2021-08-24 03:15:41 +02:00
bors[bot]
ced65f77c4
Merge #10001
10001: Sort enum variant r=Veykril a=vsrs

A small fix to the problem noted by `@lnicola` :

> ![sort-fields](https://user-images.githubusercontent.com/308347/129513196-4ffc7937-be58-44d4-9ec7-ba8745dcb460.gif)
> 
> (note the slight inconsistency here: to sort the variants of `Animal` I have to select the enum name, but to sort the fields of `Cat` I have to select the fields themselves)



Co-authored-by: vsrs <vit@conrlab.com>
2021-08-23 22:19:50 +00:00
vsrs
7a8f881a09 Sort enum variant 2021-08-23 20:31:54 +03:00
Aleksey Kladov
0a7e57177e internal: use single env var to controll all benchmarks 2021-08-23 16:40:42 +03:00
Aleksey Kladov
c044493434 ⬆️ rowan
Just so we don't live on a per-release
2021-08-23 12:10:49 +03:00
mahdi-frms
cf5f1c102c add static method generation assist 2021-08-23 12:14:23 +04:30
unexge
3a9ba0e506 feat: join lines merges assignments 2021-08-22 21:28:39 +03:00
Lukas Wirth
4933beca87 Respect attributes in Hygiene token up-mapping 2021-08-22 19:12:45 +02:00
bors[bot]
996300f4a0
Merge #9989
9989: Fix two more “a”/“an” typos (this time the other way) r=lnicola a=steffahn

Follow-up to #9987

you guys are still merging these fast 😅

_this time I thought – for sure – that I’d get this commit into #9987 before it’s merged…_

Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
2021-08-22 16:10:48 +00:00
Frank Steffahn
75073451c6 Fix three more (reverse) “a”/“an” typos 2021-08-22 17:48:15 +02:00
Frank Steffahn
5f5d45468d Fix two more “a”/“an” typos (this time the other way) 2021-08-22 17:36:58 +02:00
Florian Diebold
424dda8113 Refactor & improve handling of overloaded binary operators
Fixes #9971. Also records them as method resolutions, which we could use
later.
2021-08-22 17:35:50 +02:00
Frank Steffahn
35a7fdd2c1 Fix two more “a”/“an” typos 2021-08-22 17:24:48 +02:00
bors[bot]
0960d4ebe2
Merge #9937 #9985
9937: internal: incentivize rust-analyzed developers to fix panics r=matklad a=matklad



9985: minor: Fix another “a”/“an” typo r=Veykril a=steffahn

Follow-up to #9984.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
2021-08-22 15:01:15 +00:00
Aleksey Kladov
85fbbc5372 internal: incentivize rust-analyzed developers to fix panics
It's good that rust-analyzer doesn't belly-up on a panic in some random
assist.

It is less good that rust-analyzer devs only know that the assists are
buggy when they are actively looking at the logs.
2021-08-22 17:54:50 +03:00
bors[bot]
107b2f1890
Merge #9972
9972: refactor : function generation assists r=Veykril a=mahdi-frms

Separated code generation from finding position for generated code. This will be ground work for introducing static associated function generation.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-22 14:53:41 +00:00
Frank Steffahn
ab23af439d Fix another “a”/“an” typo 2021-08-22 16:45:58 +02:00
bors[bot]
c6baf3dcf8
Merge #9984
9984: Fix typos “a”→“an” r=Veykril a=steffahn

See rust-lang/rust#88230

Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
2021-08-22 13:06:34 +00:00
Frank Steffahn
3a5a93595f Fix typos “a”→“an” 2021-08-22 14:31:37 +02:00
bors[bot]
b9d879876e
Merge #9979
9979: fix: Incorrect up-mapping for tokens in derive attributes r=Veykril a=Veykril

Merely detaching the attributes causes incorrect spans to appear when mapping tokens up as the token ids resolve to the ranges of the stripped item so all the text ranges of its tokens are actually lower than the non-stripped ones.

Same fix as with attributes can be applied here, just replace the derive attribute with an equal amount of whitespace.

Fixes #9387

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-22 12:25:18 +00:00
Lukas Wirth
5507512eaf Replace stripped derives with whitespace in process_macro_input 2021-08-22 14:23:59 +02:00
Aleksey Kladov
e86388689f internal: remove unreasonable crate dependency
Proc macro expansion shouldn't know about salsa at all.
2021-08-22 14:05:12 +03:00
Aleksey Kladov
881d71a489 internal: reduce crate interdependence
I don't think there's anything wrong with project_model depending on
proc_macro_api directly -- fundamentally, both are about gluing our pure
data model to the messy outside world.

However, it's easy enough to avoid the dependency, so why not.

As an additional consideration, `proc_macro_api` now pulls in `base_db`.
project_model should definitely not depend on that!
2021-08-22 13:32:00 +03:00
Aleksey Kladov
5cef007bff internal: improve consistency
load and load_proc_macro do similar things
2021-08-22 13:15:18 +03:00
mahdi-frms
c1edbfbacc better assist label 2021-08-22 12:31:16 +04:30
bors[bot]
8cd171cd94
Merge #9978
9978: fix: Expand attributes recursively in expand_macro r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-21 21:26:00 +00:00
Lukas Wirth
2f179adc41 Expand attributes recursively in expand_macro 2021-08-21 23:24:12 +02:00
Lukas Wirth
a0d5290b7f Show try operator propogated types on ranged hover 2021-08-21 22:21:27 +02:00
Lukas Wirth
833de22d0b fix: Do not show functional update completion when already qualified 2021-08-21 20:45:15 +02:00
bors[bot]
9e3517f8f3
Merge #9975
9975: minor: Fix panic caused by #9966 r=flodiebold a=flodiebold

Chalk can introduce new type variables when doing lazy normalization, so we have to do the proper 'fudging' after all.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-08-21 18:07:36 +00:00
Florian Diebold
df77e2448c Fix panic caused by #9966
Chalk can introduce new type variables when doing lazy normalization, so
we have to do the proper 'fudging' after all.
2021-08-21 20:07:07 +02:00
Lukas Wirth
5fb8c0ddfd Remove MappedSubtree 2021-08-21 18:19:18 +02:00
Lukas Wirth
177c70128c Map attribute input tokens correctly 2021-08-21 18:13:41 +02:00
Laurențiu Nicola
104d6124d7 Handle coercion on binary operator RHS 2021-08-21 17:54:45 +03:00
mahdi-frms
50923ad741 func gen: seperate generation form position(3) 2021-08-21 19:13:14 +04:30
mahdi-frms
1ac9400100 func gen: seperate generation form position(2) 2021-08-21 17:31:37 +04:30
Florian Diebold
1791a35f9f Determine expected parameters from expected return in calls
Fixes #9560
2021-08-21 14:33:31 +02:00
Florian Diebold
cd64353288 Adapt tests for correct behavior 2021-08-21 13:35:36 +02:00
Florian Diebold
5cff355059 Add another test 2021-08-21 13:35:34 +02:00
bors[bot]
6f41053ede
Merge #9965
9965: minor: Don't ask for the builtin attribute input twice r=Veykril a=Veykril

`tt` and `item` here were the same, I misunderstood what the main input for attributes was in #9943
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-21 10:56:09 +00:00
Lukas Wirth
cee02673d1 Don't ask for the builtin attribute input twice 2021-08-21 12:55:05 +02:00
bors[bot]
4aa2a44a55
Merge #9962
9962: Add empty-body check to replace_match_with_if_let and re-prioritize choices r=elkowar a=elkowar

This PR changes some behaviour of the `replace_match_with_if_let` ide-assist.
Concretely, it makes two changes:

it introduces a check for empty expression bodies. This means that checks of the shape
```rs
match x {
  A => {}
  B => {
    println!("hi");
  }
}
```
will prefer to use the B branch as the first (and only) variant.

It also reprioritizes the importance of "happy" and "sad" patterns.
Concretely, if there are reasons to prefer having the sad pattern be the first (/only) pattern,
it will follow these.
This means that in the case of 
```rs
match x {
  Ok(_) => {
    println!("Success");
  }
  Err(e) => {
    println!("Failure: {}", e);
  }
}
```
the `Err` variant will correctly be used as the first expression in the generated if.
Up until now, the generated code was actually invalid, as it would generate
```rs
if let Ok(_) = x {
  println!("Success");
} else {
  println!("Failure: {}", e);
}
```
where `e` in the else branch is not defined.


Co-authored-by: elkowar <5300871+elkowar@users.noreply.github.com>
2021-08-21 10:12:17 +00:00
elkowar
e47c9743cf
Fix smaller nitpicks 2021-08-21 12:02:21 +02:00
elkowar
7cff930393
Use NameClass::classify to check for ConstReference 2021-08-21 11:11:27 +02:00
elkowar
75f0701211
Add heuristic to determine type of IdentPat, make check for empty expressions correct 2021-08-21 11:00:43 +02:00
mahdi-frms
87439b1d6a func gen: seperate generation form position(1) 2021-08-21 13:29:15 +04:30
mahdi-frms
e2c233a42b simplify 2021-08-21 11:52:07 +04:30
Aleksey Kladov
4924c24d91 fix: resolve core::arch module
See https://users.rust-lang.org/t/rust-analyzer-unable-to-resolve-target-specific-module/63797/4?u=matklad

The fix is to put all sysroot crates into the same source root
2021-08-20 17:01:27 +03:00
elkowar
d6695286ee
Add empty-body check to replace_match_with_if_let and re-prioritize choices 2021-08-20 15:20:54 +02:00
Aleksey Kladov
1850849325 internal: prep to 2021 edition 2021-08-20 16:20:18 +03:00
Lukas Wirth
82728eb757 Switch AstDatabase::exapnd_proc_macro to ExpandResult 2021-08-20 14:34:46 +02:00
Lukas Wirth
269de9abe3 Switch BuiltinDeriveExpander::expand to ExpandResult 2021-08-20 14:28:36 +02:00
Lukas Wirth
557df6ff3f Use correct HirFileId in find_related_test 2021-08-20 13:50:40 +02:00
Lukas Wirth
7342dcf0b0 Fix runnables not seeing test and bench attributes 2021-08-20 13:50:06 +02:00
Lukas Wirth
351cec0cb4 Do not replace items annotated with builtin attrs with the attr input 2021-08-20 13:50:06 +02:00
bors[bot]
8dd3a71730
Merge #9955
9955: fix: Rename fails on renaming definitions created by macros instead of renaming the macro invocation r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-19 22:13:09 +00:00
Lukas Wirth
c67ecbebc4 Rename fails on renaming definitions created by macros 2021-08-20 00:12:47 +02:00
Lukas Wirth
95923c7b29 Fix imports 2021-08-19 17:33:58 +02:00
bors[bot]
59aa091866
Merge #9855
9855: feature: Destructure Tuple Assist r=Veykril a=Booksbaum

Part of #8673. This PR only handles tuples, not TupleStruct and RecordStruct.

Code Assist to destructure a tuple into its items:
![Destructure_Tuple_Assist](https://user-images.githubusercontent.com/15612932/129020107-775d7c94-dca7-4d1f-a0a2-cd63cabf4132.gif)



* Should work in nearly all pattern positions, like let assignment, function parameters, match arms, for loops, and nested variables (`if let Some($0t) = Some((1,2))`)  
  -> everywhere `IdentPat` is allowed
  * Exception: If there's a sub-pattern (``@`):`
    ```rust
    if let t @ (1..=3, 1..=3) = ... {}
    //     ^
    ```
    -> `t` must be a `Name`; `TuplePat` (`(_0, _1)`) isn't allowed
    * inside subpattern is ok:
      ```rust
      let t @ (a, _) = ((1,2), 3);
      //       ^
      ```
      ->
      ```rust
      let t @ ((_0, _1), _) = ((1,2), 3);
      ```
* Assist triggers only at tuple declaration, not tuple usage.  
  (might be useful especially when it creates a sub-pattern (after ``@`)` and only changes the usage under cursor -- but not part of this PR).

### References
References can be destructured:
```rust
let t = &(1,2);
//  ^
let v = t.0;
```
->
```rust
let (_0, _1) = &(1,2);
let v = _0;
```
BUT: `t.0` and `_0` have different types (`i32` vs. `&i32`) -> `v` has now a different type.

I think that's acceptable: I think the destructure assist is mostly used in simple, immediate scopes and not huge existing code.

Additional Notes:
* `ref` has same behaviour (-> `ref` is kept for items)
  ```rust
  let ref t = (1,2);
  //      ^
  ```
  ->
  ```rust
  let (ref _0, ref _1) = (1,2);
  ```
* Rust IntelliJ Plugin: doesn't trigger with `&` or `ref` at all 

### mutable
```rust
let mut t = (1,2);
//      ^
```
->
```rust
let (mut _0, mut _1) = (1,2);
```
and
```rust
let t = &mut (1,2);
//  ^
```
->
```rust
let (_0, _1) = &mut (1,2);
```
Again: with reference (`&mut`), `t.0` and `_0` have different types (`i32` vs `&mut i32`).  
And there's an additional issue with `&mut` and assignment:
```rust
let t = &mut (1,2);
//  ^
t.0 = 9;
```
->
```rust
let (_0, _1) = &mut (1,2);
_0 = 9;
//   ^
//   mismatched types
//   expected `&mut {integer}`, found integer
//   consider dereferencing here to assign to the mutable borrowed piece of memory
```
But I think that's quite a niche use case, so I don't catch that (`*_0 = 9;`)

Additional Notes:
* Rust IntelliJ Plugin: removes the `mut` (`let mut t = ...` -> `let (_0, _1) = ...`), doesn't trigger with `&mut`

### Binding after ``@``
Destructure tuple in sub-pattern is implemented:
```rust
let t = (1,2);
//  ^
let v = t.0;
let f = t.into();
```
->
```rust
let t @ (_0, _1) = (1,2);
let v = _0;
let f = t.into();
```
BUT: Bindings after ``@`` aren't currently in stable and require `#![feature(bindings_after_at)]` (though should be generally [available quite soon](https://github.com/rust-lang/rust/pull/85305#event-5072889913) (with `1.56.0`)).  
But I don't know how to check for an enabled feature -> Destructure tuple in sub-pattern [isn't enabled](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L32)) yet.

* When Destructure in sub-pattern is enabled there are two assists:
  * `Destructure tuple in place`:
    ```rust
    let t = (1,2);
    //  ^
    ```
    ->
    ```rust
    let (_0, _1) = (1,2);
    let v = _0;
    let f = /*t*/.into();
    ```
  * `Destructure tuple in sub-pattern`:
    ```rust
    let t = (1,2);
    //  ^
    let v = t.0;
    let f = t.into();
    ```
    ->
    ```rust
    let t @ (_0, _1) = (1,2);
    let v = _0;
    let f = t.into();
    ```
* When Destructure in sub-pattern is disabled, only the first one is available and just named `Destructure tuple`

<br/>
<br/>

### Caveats
* Unlike in #8673 or IntelliJ rust plugin, I'm not leaving the previous tuple name at function calls.  
  **Reasoning**: It's not too unlikely the tuple variable shadows another variable. Destructuring the tuple while leaving the function call untouched, results in still a valid function call -- but now with another variable:
  ```rust
  let t = (8,9);
  let t = (1,2);
  //  ^
  t.into()
  ```
  => Destructure Tuple
  ```rust
  let t = (8,9);
  let (_0, _1) = (1,2);
  t.into()
  ```
  `t.into()` is still valid -- using the first tuple.  
  Instead I comment out the tuple usage, which results in invalid code -> must be handled by user:
  ```rust
  /*t*/.into()
  ```
  * (though that might be a biased decision: For testing I just declared a lot of `t`s and quite ofen in lines next to each other...)
  * Issue: there are some cases that results in still valid code:
    * macro that accept the tuple as well as no arguments:
      ```rust
      macro_rules! m {
          () => { "foo" };
          ($e:expr) => { $e; "foo" };
      }
      let t = (1,2);
      m!(t);
      m!(/*t*/);
      ```
      -> both calls are valid ([test](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L1474)))  
    * Probably with tuple as return value. Changing the return value most likely results in an error -- but in another place; not where the tuple usage was. 

  -> not sure that's the best way....  
  Additional the tuple name surrounded by comment is more difficult to edit than just the name.
* Code Assists don't support snippet placeholder, and rust analyzer just the first `$0` -> unfortunately no editing of generated tuple item variables. Cursor (`$0`) is placed on first generated item.

<br/>
<br/>

### Issues
* Tuple index usage in macro calls aren't converted:
  ```rust
  let t = (1,2);
  //  ^
  let v = t.0;
  println!("{}", t.0);
  ```
  ->
  ```rust
  let (_0, _1) = (1,2);
  let v = _0;
  println!("{}", /*t*/.0);
  ```
  ([tests](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L1294)))
  * Issue is:  
    [name.syntax()](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L242-L244)) in each [usage](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L108-L113)) of a tuple is syntax & text_range in its file.  
    EXCEPT when tuple usage is in a macro call (`m!(t.0)`), the macro is expanded and syntax (and range) is based on that expanded macro, not in actual file.  
    That leads to several things:
    * I cannot differentiate between calling the macro with the tuple or with tuple item:
      ```rust
      macro_rules! m {
          ($t:expr, $i:expr) => { $t.0 + $i };
      }
      let t = (1,2);
      m!(t, t.0);
      ```
      -> both `t` usages are resolved as tuple index usage
    * Range of resolved tuple index usage is in expanded macro, not in actual file  
     -> don't know where to replace index usage

    -> tuple items passed into a macro are ignored, and only the tuple name itself is handled (uncommented)
* I'm not checking if the generated names conflict with already existing variables.
  ```rust
  let _0 = 42;            // >-|
  let t = (1,2);          //   |
  let v = _0;             // <-|
  //  ^ 42
  ```
  => deconstruct tuple
  ```rust
  let _0 = 42;
  let (_0, _1) = (1,2);     // >-|
  let v = _0;               // <-|
  //  ^ now 1
  ```
  * I tried to get the scope at tuple declaration and its usages. And then iterate all names with [`process_all_names`](145b51f9da/crates/hir/src/semantics.rs (L935)). But that doesn't find all local names for declarations (`let t = (1,2)`) (for usages it does)
  * This isn't unique to this Code Assist, but happen in others too (like `extract into variable` or `extract into function`). But here a name conflict is more likely (when destructuring multiple tuples, for examples nested ones (`let t = ((1,2),3)` -> `let (_0, _1) = ...` -> `let ((_0, _1), _1) = ...` -> error))
  * IntelliJ rust plugin does handle this (-> name is `_00`)

Co-authored-by: BooksBaum <15612932+Booksbaum@users.noreply.github.com>
2021-08-19 15:19:06 +00:00
BooksBaum
8a9feeddd3
Remove match_ast usage 2021-08-19 14:17:23 +02:00
BooksBaum
2c27adc0a3
Remove match_ast! macro call
Add node about uncommenting tuple in macro call
2021-08-19 14:09:52 +02:00
Yoshua Wuyts
586d6fca8c Fix codegen for is_method documentation
Previously the generated paths were invalid. This fixes that.
2021-08-19 13:31:16 +02:00
Dawer
08694dc1ef minor: address review comments 2021-08-18 19:04:10 +05:00
Dawer
98847e4d5b internal: use the new edit_in_place::Indent API 2021-08-18 18:08:14 +05:00
Lukas Wirth
04076bc5fb Don't trigger related highlighting on unrelated tokens 2021-08-18 15:03:39 +02:00
bors[bot]
320bb72b7f
Merge #9941
9941: feat: include full path in the cyclic deps error r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-18 12:36:18 +00:00
Aleksey Kladov
5192ddfa2e feat: include full path in the cyclic deps error 2021-08-18 15:35:04 +03:00
Dawer
d6c4165182 internal: introduce in-place indenting API 2021-08-18 16:05:23 +05:00
BooksBaum
b1ebb82f32
Add deref (*) handling for usages of ref tuples 2021-08-17 19:23:07 +02:00
BooksBaum
384fae7fcd
Switch order of assists
Destructure in sub-pattern before Destructure in place to favor the
first one
2021-08-17 19:23:06 +02:00
BooksBaum
d0cf28322a
Add generated doctest 2021-08-17 19:23:06 +02:00
BooksBaum
5b9f8e7e8e
Fix errors from rebase master
Note:
2nd Assist description is moved down: generated doc tests extracts now
all tests (previously only the first one). But it uses the first
`Assist` name -- which is the wrong one for the 2nd test. And 2nd assist
is currently disabled -> would fail anyway.
2021-08-17 19:23:06 +02:00
BooksBaum
b441aa2046
Cleanup according to style-requirements in tests 2021-08-17 19:23:06 +02:00
BooksBaum
45ef57bd23
Fix: different assist ids in doc and code 2021-08-17 19:23:05 +02:00
BooksBaum
0d2490f785
Handle tuple in macro call
Only tuple name is handled (uncommented), not tuple index
2021-08-17 19:23:05 +02:00
BooksBaum
450a9c5b12
Add destructure in sub-pattern (after @) 2021-08-17 19:23:05 +02:00
BooksBaum
3e4051938d
Handle mut & ref 2021-08-17 19:23:04 +02:00
BooksBaum
478b2988c0
Add Destructure Tuple 2021-08-17 19:22:57 +02:00
bors[bot]
d1ba993136
Merge #9936
9936: proc_macro_api: make commit & date suffix of binary version optional r=lnicola a=lnicola

Closes #9916

bors r+

Co-authored-by: Florian sp1rit​ <sp1ritCS@protonmail.com>
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-08-17 16:26:05 +00:00
Laurențiu Nicola
f69225c4fa Fix formatting 2021-08-17 19:25:37 +03:00
Alexander Sieg
778d372900
Bump notify version to 5.0.0-pre.12
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-08-17 17:25:11 +02:00
Alexander Sieg
ca6a1d8c63 Revert "Downgrade notify and use RecommendedWatcher"
This reverts commit 5b0c86af7d.

The pre-5.0.12 release of notify fixed this issue.
2021-08-17 17:17:13 +02:00
bors[bot]
8d7eea9e3a
Merge #9929
9929: fix: Handle all rename special cases for record pattern fields r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-17 13:25:08 +00:00
Lukas Wirth
daf3094958 Emit more concise text edits in ide_db::rename 2021-08-17 15:24:01 +02:00
Florian sp1rit​
2bfaffbf82 proc_macro_api: make commit & date suffix of binary version optional
Signed-off-by: Florian "sp1rit"​ <sp1ritCS@protonmail.com>
2021-08-17 14:08:10 +03:00
Lukas Wirth
995c8f50a2 some code docs for the ide_db/rename module 2021-08-16 23:06:51 +02:00
Lukas Wirth
5e533e5900 Handle all rename special cases for all record pattern fields 2021-08-16 22:48:38 +02:00
bors[bot]
dcbaa75bc1
Merge #9928
9928: internal: Highlight function exit points on `fn` keyword r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-16 19:26:18 +00:00
Lukas Wirth
40455db088 Highlight function exit points on fn keyword 2021-08-16 21:25:22 +02:00
Laurențiu Nicola
c9f448a834 Fix some clippy lints 2021-08-16 22:04:26 +03:00
bors[bot]
978b140781
Merge #9921
9921: Only add entries to SourceToDef dynmaps when they come from the same file r=matklad a=Veykril

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

Running the test as described in the issue I do not get any eprintln output at all anymore.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-16 16:38:44 +00:00
Lukas Wirth
6523a09562 style 2021-08-16 18:29:16 +02:00
bors[bot]
bae22f9507
Merge #9924
9924: Fix gen debug for enums r=yoshuawuyts a=yoshuawuyts

Closes https://github.com/rust-analyzer/rust-analyzer/issues/9914. Thanks!

r? `@Veykril` 

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-16 16:25:57 +00:00
Yoshua Wuyts
067dc660ae implement feedback from review 2021-08-16 18:23:51 +02:00
Lukas Wirth
0336e9b25f Flatten SourceToDefCache structure 2021-08-16 17:55:18 +02:00
Yoshua Wuyts
9374d526da fix debug tuple structs 2021-08-16 17:39:08 +02:00
Lukas Wirth
c90ecc5c26 Only add entries to SourceToDef dynmaps when they come from the same file 2021-08-16 17:07:25 +02:00
bors[bot]
6a07bf6a9f
Merge #9920
9920: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-16 14:13:04 +00:00
Lukas Wirth
0c0142f61a Simplify 2021-08-16 16:12:20 +02:00
Aleksey Kladov
438d1da6c6 minor: simplify 2021-08-16 14:45:54 +03:00
Aleksey Kladov
d29c52354c minor: remove dead code 2021-08-16 14:28:04 +03:00
Yoshua Wuyts
b67378f53e fix debug record structs 2021-08-16 12:58:06 +02:00
bors[bot]
b641a66078
Merge #9905
9905: internal: optimize compile time r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-15 10:26:59 +00:00
Aleksey Kladov
92da7e9ffa internal: optimize compile time
cargo llvm-lines shows that path_to_error bloats the code. I don't think
I've needed this functionality recently, seems that we've fixed most of
the serialization problems. So let's just remove it. Should be easy to
add back if we ever need it, and it does make sense to keep the
`from_json` function around.
2021-08-15 13:24:37 +03:00
bors[bot]
933a4dc3a6
Merge #9902
9902: minor: move functionality to a better place r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 17:43:52 +00:00
Aleksey Kladov
3c49a9f079 minor: move functionality to a better place 2021-08-14 20:43:28 +03:00
bors[bot]
182a2b8e72
Merge #9901
9901: internal: remove dead code r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 17:30:13 +00:00
Aleksey Kladov
78c7940f5c internal: remove dead code 2021-08-14 20:29:46 +03:00
bors[bot]
1e0d20366f
Merge #9900
9900: internal: remove one more usage of old editing API. r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 17:17:51 +00:00
Aleksey Kladov
e300f58d2c internal: remove one more usage of old editing API. 2021-08-14 20:17:16 +03:00
bors[bot]
01de9021cd
Merge #9899
9899: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-14 17:10:04 +00:00
Lukas Wirth
2e733b1a3e Simplify 2021-08-14 19:09:36 +02:00
bors[bot]
4be69436dd
Merge #9897
9897: internal: remove old editing API r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 16:46:19 +00:00
Aleksey Kladov
a26b1c3923 internal: remove old editing API 2021-08-14 19:45:47 +03:00
bors[bot]
d7374ab882
Merge #9896
9896: internal: Only complete type annotations for patterns in function params r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-14 16:19:14 +00:00
Lukas Wirth
bf918046fa Only complete type annotations for patterns in function params 2021-08-14 18:18:32 +02:00
bors[bot]
5a60e9106b
Merge #9895
9895: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-14 16:07:09 +00:00
Lukas Wirth
894a09b749 Simplify 2021-08-14 18:02:51 +02:00
bors[bot]
5d7ff6efe3
Merge #9894
9894: internal: use standard test style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 15:59:47 +00:00
Aleksey Kladov
c3bbeb947c internal: use standard test style 2021-08-14 18:53:21 +03:00
Lukas Wirth
37ad9cb2a5 Don't use non cache syntaxnodes in generate_function for lookups 2021-08-14 17:51:11 +02:00
Aleksey Kladov
a78decc466 internal: make assist naming consistent 2021-08-14 18:39:56 +03:00
Aleksey Kladov
dc17b35e62 internal: remove a remnant of old editing infra 2021-08-14 18:24:42 +03:00
Aleksey Kladov
90357a9090 internal: merge hir::BinaryOp and ast::BinOp 2021-08-14 18:10:01 +03:00
Aleksey Kladov
fe4f059450 internal: prepare to merge hir::BinaryOp and ast::BinOp 2021-08-14 17:07:51 +03:00
Aleksey Kladov
6df00f8495 internal: make naming consistent 2021-08-14 17:01:28 +03:00
Aleksey Kladov
faa420fc32 internal: prepare a dedicated module for all operators 2021-08-14 16:58:46 +03:00
Aleksey Kladov
beca92b245 internal: make invert binary op more robust
Previously, we only inverted comparison operators (< and the like) if
the type implemented Ord. This doesn't make sense: if `<` works, then
`>=` will work as well!

Extra semantic checks greatly reduce robustness and predictability of
the assist, it's better to keep things simple.
2021-08-14 16:40:00 +03:00
Jonas Schievink
4757679b9a feat: type inference for if-let guards 2021-08-14 00:09:30 +02:00
bors[bot]
43af7920af
Merge #9871
9871: Jump to generated func r=mahdi-frms a=rylev

Worked on this with `@yoshuawuyts.`

We thought we ran into an issue with the `generate_function` assist where the code was not being generated in a certain situations. However, it wasn't actually a bug just a very confusing implementation where the cursor is not moved to the newly generated function. This happened when the return type was successfully inferred (and not unit). The function would be generated, but selection would not be changed.

This can be very confusing: If the function is generated somewhat far from where the assist is being invoked, the user never sees that the code was generated (nor are they given the chance to actually implement the function body). 

This PR makes it so that the cursor is _always_ moved to somewhere in the newly generated function. In addition, if we can infer unit as the type, then we do not still generate `-> ()` as the return type. Instead, we simply omit the return type.

This means the selection will move to either one of two places:
* A generated `-> ()` return type when we cannot successfully infer the return type.
* The `todo!()` body when we can successfully infer the return type.

Co-authored-by: Ryan Levick <me@ryanlevick.com>
2021-08-13 11:19:16 +00:00
Ryan Levick
1cc43ab7f4 Add documentation on how whether a generated return type should be focused or not 2021-08-13 11:46:08 +02:00
Jonas Schievink
d568e7686a Support if let match guards 2021-08-13 00:25:14 +02:00
Jonas Schievink
6f579c4862 Always add implicit proc_macro dependency 2021-08-12 21:42:14 +02:00
bors[bot]
baf1494374
Merge #9807
9807: Implicit `Sized` bounds r=iDawer a=iDawer

This should close #8984 

`hir_ty`:
- Type parameters, associated types and `impl Trait` are `Sized` by deafault except `Self` in a trait.
- Implicit `Sized` bound is added to end of predicate list. It does not check if such bound is present already. Also it does not track the bound is implicit.
- Allowed ambiguous unsize coercion if Chalk returns definite guidance.
- Allowed ambiguous autoderef if Chalk returns definite guidance.

`hir_def`:
- `ItemTree` pretty printing shows `?Sized` bounds.

`HirDisplay`:
- `impl Trait` with weird bounds rendered correctly.
- `Sized`/`?Sized` bounds are not shown if they are default.

### Perf
`./target/rust-analyzer-baseline_8a843113 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.80s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 174
Inference:           50.28s, 116ginstr, 516mb
Total:               77.08s, 189ginstr, 855mb
```

`./target/rust-analyzer-sized-fixed_ambig_coercion-de074fe6 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.95s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 166
Inference:           96.39s, 234ginstr, 543mb
Total:               123.33s, 307ginstr, 881mb
```


Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-08-12 17:55:29 +00:00
Dawer
6c366ade00 Clean up 2021-08-12 21:20:28 +05:00
Ryan Levick
a5c46e5a88 Factor out return type handling for both function and method 2021-08-12 16:05:32 +02:00
Ryan Levick
0834e05045 Always fall back to focusing on generated function body 2021-08-12 14:56:39 +02:00
Ryan Levick
e8de34b6b3 Use term on label for generating method impl 2021-08-12 14:01:15 +02:00
bors[bot]
1376ece497
Merge #9863
9863: feat: Generate default trait fn impl when generating `PartialEq` r=yoshuawuyts a=yoshuawuyts

Implements a default trait function body when generating the `PartialEq` trait for a type. Thanks!

r? `@veykril`

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-12 10:18:02 +00:00
Yoshua Wuyts
97ec6a27ec add make::ext::path_from_idents 2021-08-12 12:17:09 +02:00
Yoshua Wuyts
df19895ba6 implement feedback from review 2021-08-12 11:50:01 +02:00
Yoshua Wuyts
8ed24029c1 rm remaining todo comment 2021-08-11 23:30:00 +02:00
Yoshua Wuyts
2fff019b6b improve codegen 2021-08-11 20:33:13 +02:00
Yoshua Wuyts
6c4a94b03a finishing touches 2021-08-11 20:04:05 +02:00
Yoshua Wuyts
c4e10c81b9 gen partialeq for tuple enums 2021-08-11 20:01:19 +02:00
Yoshua Wuyts
741e27b414 dedup PartialEq for Record enums 2021-08-11 19:40:47 +02:00
Dawer
de074fe636 Accept ambiguous unsize coercion only if it has definite guidance. 2021-08-11 22:09:32 +05:00
Lukas Wirth
73b7b34f89 Fill out expected type for functional update syntax completion 2021-08-11 18:12:44 +02:00
Lukas Wirth
6045059916 extract_variable handles selection ranges better 2021-08-11 17:52:09 +02:00
Yoshua Wuyts
fc17eb482d gen PartialEq for Record enums
Co-Authored-By: Ryan Levick <rylev@users.noreply.github.com>
2021-08-11 17:15:12 +02:00
bors[bot]
f438dbb100
Merge #9860
9860: fix: Fix extract_function tagging params as mut unnecessarily r=Veykril a=Veykril

Fixes #9822
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-11 15:10:26 +00:00
Lukas Wirth
6d960ab032 Fix extract_function tagging params as mut unnecessarily 2021-08-11 17:09:51 +02:00
bors[bot]
50617ee5c5
Merge #9856
9856: Show type actions on ranged type hover r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-11 11:53:25 +00:00
Lukas Wirth
ec443886ea Show type actions on ranged type hover 2021-08-11 13:52:57 +02:00
Aleksey Kladov
629c68e80d internal: document that ascription is preferred to a turbo fish 2021-08-11 14:16:15 +03:00
bors[bot]
145b51f9da
Merge #9836
9836: Refactor: quick clean-up of iteration idioms in the `vfs` crate r=matklad a=Some-Dood

This PR cleans up some of the iteration idioms used in the `vfs` crate. Most of the changes simply converted `for` loops into their `std::iter::Iterator`-method counterpart. Other changes required some inversion of logic to accommodate for better short-circuiting. Overall, there should be no behavioral changes. If there are any stylistic issues, I will gladly adhere to them and adjust the PR accordingly. Thanks!

Co-authored-by: Basti Ortiz <39114273+Some-Dood@users.noreply.github.com>
2021-08-11 09:54:09 +00:00
bors[bot]
6c80c42c57
Merge #9828
9828: Remove dependency on the system graphviz when rendering crate graph r=lnicola a=p32blo


This PR removes the need for having `graphviz` installed on the user system by using the `d3-graphviz` npm package.

The responsibility of rendering the svg output is moved to the extension while the rust side only handles the generation of the dot file.

This change also brings the following additional features:
- Allow zooming the view
- Ctrl+click to reset the zoom 
- Adjust the color scheme to dark themes
- Works on any platform without installing graphviz locally

---

I’m not sure if this fits what you had in mind for the crates graph feature but I decided to submit it anyway to see if this is useful to anyone else. 

A potential downside might be that it increases the extension size ( haven’t checked) but this feature already required the installation of graphviz on the user side, so the cost is just moved explicitly to the extension.

Feel free to make any suggestion or comments. 

Co-authored-by: André Oliveira <p32blo@gmail.com>
2021-08-11 08:30:53 +00:00
Yoshua Wuyts
1cf7af7032 wip enum record/tuple generation 2021-08-10 22:08:14 +02:00
Yoshua Wuyts
65ce87cad8 gen PartialEq for basic enums 2021-08-10 21:05:23 +02:00
Yoshua Wuyts
f8a64c044a gen PartialEq for structs 2021-08-10 19:49:06 +02:00
Yoshua Wuyts
3cad2c4feb add partial_eq gen tests 2021-08-10 19:48:50 +02:00
Yoshua Wuyts
20c3b20db3 add make::expr_op 2021-08-10 19:48:32 +02:00
Lukas Wirth
f6d6fda85b Refine functional update completion some more 2021-08-10 17:03:38 +02:00
Basti Ortiz
0986632c04
Fix: revert strange usage of ? operator 2021-08-10 22:44:15 +08:00
Basti Ortiz
27605b402e
Fix: prefer the usage of for loops over fold 2021-08-10 22:40:04 +08:00
Basti Ortiz
0e480a6e9c
Chore: add comments to explicitly express two-step check
See https://github.com/rust-analyzer/rust-analyzer/pull/9836#discussion_r685953381
2021-08-10 22:30:08 +08:00
Basti Ortiz
ae1288eeed
Fix: revert complex conditional in Directories::contains_file
This reverts commit 6d0336b2e4.
2021-08-10 22:25:43 +08:00
André Oliveira
11bbaecca0 Formatting issues 2021-08-10 13:43:57 +00:00
André Oliveira
b29508949d Remove debug logs 2021-08-10 13:43:57 +00:00
André Oliveira
8a563e4a46 Use local node_modules to allow the graph to load offline
- Fix some warnings
2021-08-10 13:43:08 +00:00
André Oliveira
f4f68e62c2 Use d3-graphviz for rendering crates graph on the extension side 2021-08-10 13:40:49 +00:00
bors[bot]
e1dcec0e02
Merge #9846
9846: feat: Generate default trait fn impl when generating `Clone` r=Veykril a=yoshuawuyts

Implements a default trait function body when generating the `Clone` trait for a type. Thanks!

r? `@\veykril`

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-10 13:18:09 +00:00
bors[bot]
f6ef043a88
Merge #9845
9845: fix: Do not drop `..Default::default()` completion when typing `..` r=Veykril a=Veykril

cc https://github.com/rust-analyzer/rust-analyzer/issues/9839
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-10 13:08:58 +00:00
Lukas Wirth
e729529410 Do not drop ..Default::default() completion when typing .. 2021-08-10 15:08:35 +02:00
Yoshua Wuyts
2f866974d9 gen clone for tuple enums 2021-08-10 15:07:13 +02:00
Yoshua Wuyts
e0adb39de3 gen clone for record enums 2021-08-10 14:43:20 +02:00
bors[bot]
cb3201188f
Merge #9842
9842: fix: Substitute generic types in inline_call r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-10 12:40:37 +00:00
Lukas Wirth
7e6eb67f0d Substitute generic types in inline_call 2021-08-10 14:39:56 +02:00
bors[bot]
a739a579cd
Merge #9841
9841: internal: print total size of source code in analysis-stats r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-10 12:31:35 +00:00
Aleksey Kladov
a379bd715f
Update crates/rust-analyzer/src/cli/analysis_stats.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-08-10 15:31:12 +03:00
Aleksey Kladov
5d5d5182c1 internal: print total size of source code in analysis-stats 2021-08-10 15:28:48 +03:00
Yoshua Wuyts
7ddc26aea1 add clone generation for structs and bare enums 2021-08-10 13:55:26 +02:00
Yoshua Wuyts
7d7a50daf7 Add clone generation tests 2021-08-10 13:20:24 +02:00
Lukas Wirth
b7d7dd6163 Implement bool_then_to_if assist 2021-08-10 13:17:45 +02:00
Yoshua Wuyts
4b5139e8a5 impl gen hash for structs 2021-08-10 12:37:10 +02:00
Yoshua Wuyts
ec2535e9ce impl gen hash for enums 2021-08-10 12:37:10 +02:00
bors[bot]
e652545472
Merge #9830
9830: Enable more assists to generate default trait body impls r=Veykril a=yoshuawuyts

Enable more assists to benefit from trait body generation. Follow-up to #9825 and #9814.

__edit:__ I'd like to move the existing tests to this new file too, but I'll do that in a follow-up PR.

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-10 10:27:55 +00:00
Yoshua Wuyts
326890753c implement feedback from review 2021-08-10 12:21:48 +02:00
Basti Ortiz
7ee6cca3d7
Refactor: use iterator methods over for loops 2021-08-10 17:51:11 +08:00
Aleksey Kladov
9cf5914c45 internal: unify subcommand handling between ra and xtask 2021-08-10 12:49:55 +03:00
Aleksey Kladov
e8a67b67bf internal: prepare to use standard .run pattern for subcommands 2021-08-10 12:25:47 +03:00
Basti Ortiz
6d0336b2e4
Refactor: simplify logic for Directories::contains_file
The logic was simply inverted to accomodate for the short-circuiting `&&` operator.
2021-08-10 16:32:00 +08:00
Yoshua Wuyts
d6b788a9ee Add trait codegen to add_missing_impl_members assist 2021-08-10 10:27:52 +02:00
Basti Ortiz
0765c9713b
Refactor: use filter_map when iterating over stored IDs and 2021-08-10 15:56:16 +08:00
Basti Ortiz
e912d6507f
Chore: use short-circuiting for file ID getter 2021-08-10 15:43:51 +08:00
Jake Heinz
4fba518b02 [semantic-highlighting] functions that consume are marked as HlMod::Consuming 2021-08-10 07:31:30 +00:00
Yoshua Wuyts
4d2e25a034 move trait body gen code to utils 2021-08-09 21:47:44 +02:00
bors[bot]
8e4fb4f518
Merge #9804
9804: Generate method from call r=matklad a=mahdi-frms

Needs a bit of refactoring. Tests also should be added.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-09 17:09:13 +00:00
bors[bot]
63427afb69
Merge #9825
9825: Generate default impl when converting #[derive(Default)] to manual impl r=Veykril a=yoshuawuyts

Similar to https://github.com/rust-analyzer/rust-analyzer/pull/9814, but for `#[derive(Default)]`. Thanks!

## Follow-up steps
I've added the tests inside `handlers/replace_derive_with_manual_impl.rs` again, but I'm planning a follow-up PR to extract these to `utils/` so we can share them between assists - and maybe even add another assist just for the purpose of testing these impls (e.g. `generate_default_trait_body`).

The step after _that_ is likely to fill out the remaining traits, so we can make it so whenever RA auto-completes a trait which also can be derived, we provide a default function body.


Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-09 16:59:10 +00:00
mahdi-frms
05a789c09d refactor method generation assist 2021-08-09 21:06:24 +04:30
mahdi-frms
9217f6dcf7 method gen assist usable in all of expression 2021-08-09 21:06:24 +04:30
mahdi-frms
311dc5b04f add test for method generation assist 2021-08-09 21:06:24 +04:30
mahdi-frms
3c31f3831d One assist for function and method generation 2021-08-09 21:06:24 +04:30
mahdi-frms
02f5b5e0e2 method generation assist: store owned ast nodes 2021-08-09 21:06:24 +04:30
mahdi-frms
6240b2dae2 generate method adds pub keyword 2021-08-09 21:06:24 +04:30
mahdi-frms
d38f36e5af generate method assist uses existing impl blocks 2021-08-09 21:06:24 +04:30
mahdi-frms
99570f32d8 refactor: use single next space 2021-08-09 21:06:24 +04:30
mahdi-frms
b777e498fe refactor: use single fn_args 2021-08-09 21:06:24 +04:30
mahdi-frms
9ca73528ee generate method assist 2021-08-09 21:06:24 +04:30
Yoshua Wuyts
13749e782e move code around 2021-08-09 18:27:01 +02:00
Aleksey Kladov
ce8400bbfd internal: drop latest requests tracking
From the dawn of time, when dinosaurs roamed the and we didn't have
hierarchical profiling, there was the `latest_requests` infra we used to
track the time of ten last requests.

Today, no one is actually using it and, what's more, it itself became
pretty useless -- LSP grew way more chatty, and 10 requests don't really
paint any kind of picture.

Personally, it's been years since I last looked at latest requests in
the status output.

So, let's remove a tiny bit of state from the big ball of complexity
that is `GlobalState` and `main_loop`!
2021-08-09 18:56:19 +03:00