Commit Graph

21240 Commits

Author SHA1 Message Date
Morgan Thomas
14e20047c4 broke a test trying to make the diff look better... 2022-03-12 10:35:26 -08:00
Morgan Thomas
3fafbca32e fix: "Extract to function" assist preserves break and continue labels
Adds a label / lifetime parameter to `ide_assists::handlers::extract_function::FlowKind::{Break, Continue}`, adds support for emitting labels to `syntax::ast::make::{expr_break, expr_continue}`, and implements the required machinery to let `extract_function` make use of them.

This does modify the external API of the `syntax` crate, but the changes there are simple, not used outside `ide_assists`, and, well, we should probably support emitting `break` and `continue` labels through `syntax` anyways, they're part of the language spec.

Closes #11413.
2022-03-12 08:54:06 -08:00
bors[bot]
5fcf979f8a
Merge #11692
11692: round of clippy fixes. r=Veykril a=matthiaskrgr

Split these up into smaller chunks so I can easily revert parts of it if needed.

Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2022-03-12 15:53:05 +00:00
Matthias Krüger
f39cac17ce fix clippy::needless_late_init 2022-03-12 16:50:49 +01:00
Matthias Krüger
5a0078c9d1 more clippy fixes:
clippy::search_is_some
clippy::redundant_static_lifetimes
clippy::match_single_binding
clippy::match_ref_pats
clippy::map_entry
clippy::manual_map
clippy::iter_overeager_cloned
clippy::into_iter_on_ref
clippy::extra_unused_lifetimes
2022-03-12 16:50:49 +01:00
Matthias Krüger
56e4ea59d9 more clippy fixes:
clippy::match_like_matches_macro
clippy::to_string_in_format_args
clippy::single_char_add_str
clippy::filter_map_identity
clippy::clone_on_copy
clippy::useless_format
clippy::unused_unit
2022-03-12 16:50:49 +01:00
Matthias Krüger
77790f2b8e fix clippy::needless_return 2022-03-12 16:50:49 +01:00
Matthias Krüger
21ffc5350d fix clippy::redundant_clone 2022-03-12 16:50:49 +01:00
Matthias Krüger
d64d711db2 fix clippy::map_flatten 2022-03-12 16:50:49 +01:00
Matthias Krüger
62ed658311 fix clippy::useless_conversion 2022-03-12 16:50:49 +01:00
Matthias Krüger
451fcd3c79 fix clippy::redundant_closure 2022-03-12 16:50:49 +01:00
Matthias Krüger
1f70886b15 fix clippy::single_char_pattern 2022-03-12 16:50:49 +01:00
Matthias Krüger
7912e33ed6 fix clippy::needless_borrow 2022-03-12 16:50:49 +01:00
bors[bot]
ff7e057dca
Merge #11691
11691: feat: Suggest union literals, suggest union fields within an empty union literal r=Veykril a=m0rg-dev

Adds a `Union {…}` completion in contexts where a union is expected, expanding to a choice of available fields (if snippets are supported):

![image](https://user-images.githubusercontent.com/38578268/158023335-84c03e39-daf0-4a52-b969-f40b01501cc8.png)
![image](https://user-images.githubusercontent.com/38578268/158023354-db49d0bb-034c-49d3-bc02-07414179cb61.png)

Also, adds support for listing possible fields in an empty union literal.

![image](https://user-images.githubusercontent.com/38578268/158023398-4695ae34-ce64-4f40-8494-68731a3030c6.png)
![image](https://user-images.githubusercontent.com/38578268/158023406-be96dd95-125a-47ac-9628-0bce634ca2eb.png)

Closes #11568.

Co-authored-by: Morgan Thomas <corp@m0rg.dev>
2022-03-12 15:44:51 +00:00
Morgan Thomas
f922b805fe - clean up match in ide_completion::completions::record::complete_record_literal
- use original instead of adjusted type in ide_completion::completions::record::complete_record
- don't even bother checking if we can complete union literals to Default or to struct update syntax
2022-03-12 07:35:13 -08:00
bors[bot]
421d9643ba
Merge #11693
11693: internal: Remove ide_completion::render::build_ext module r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-12 15:28:33 +00:00
Lukas Wirth
301711ee71 internal: Remove ide_completion::render::build_ext module 2022-03-12 16:13:49 +01:00
Morgan Thomas
6519b0a009 Suggest union literals, suggest union fields within an empty union literal 2022-03-12 06:58:43 -08:00
bors[bot]
d65f9a28fa
Merge #11687 #11689
11687: Highlight escape sequences in byte strings r=Veykril a=yipinliu

#11605 

11689: minor: Pad type inlay hints if no colons are requested r=Veykril a=Veykril

bors r+

Co-authored-by: yipinliu <ypliu18@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-12 13:14:31 +00:00
Lukas Wirth
21af9ba4f0 minor: Pad type inlay hints if no colons are requested 2022-03-12 14:08:39 +01:00
yipinliu
c15ebcd84c Optimize imports 2022-03-12 21:06:33 +08:00
bors[bot]
d75a46852a
Merge #11686
11686: feat: Enum variant field completion, enum variant / struct consistency r=Veykril a=m0rg-dev

This addresses several related inconsistencies:
 - tuple structs use tab stops instead of placeholders
 - tuple structs display in the completion menu as `Struct {…}` instead of `Struct(…)`
 - enum variants don't receive field completions at all
 - enum variants display differently from structs in the completion menu

Also, structs now display their type in the completion detail rather than the raw snippet text to be inserted.

As far as what's user-visible, that looks like this:

| | Menu | Completion | Detail |
|-|-|-|-|
| Record struct (old) | `Struct {…}` | `Struct { x: ${1:()}, y: ${2:()} }$0` | `Struct { x: ${1:()}, y: ${2:()} }$0` |
| Record struct (new) | `Struct {…}` | `Struct { x: ${1:()}, y: ${2:()} }$0` | `Struct { x: i32, y: i32 }` |
| Tuple struct (old) | `Struct {…}`  | `Struct($1, $2)$0` | `Struct($1, $2)` |
| Tuple struct (new) | `Struct(…)` | `Struct(${1:()}, ${2:()})$0` | `Struct(i32, i32)` |
| Unit variant (old) | `Variant` | `Variant` | `()` |
| Unit variant (new) | `Variant` | `Variant$0` | `Variant` |
| Record variant (old) | `Variant` | `Variant` | `{x: i32, y: i32}` |
| Record variant (new) | `Variant {…}` | `Variant { x: ${1:()}, y: ${2:()} }$0` | `Variant { x: i32, y: i32 }` |
| Tuple variant (old) | `Variant(…)` | `Variant($0)` | `(i32, i32)` |
| Tuple variant (new) | `Variant(…)` | `Variant(${1:()}, ${2:()})$0` | `Variant(i32, i32)` |

Additionally, tuple variants no longer set `triggers_call_info` because it conflicts with placeholder generation, and tuple variants that require a qualified path should now use the qualified path.

Internally, this also lets us break the general "format an item with fields on it" code out into a shared module, so that means it'll be a lot easier to implement features like #11568.


Co-authored-by: Morgan Thomas <corp@m0rg.dev>
2022-03-12 13:05:45 +00:00
Morgan Thomas
f27c0ef1cf Reduce intermediate string allocations in render::compound::render_record and ::render_tuple 2022-03-12 05:01:25 -08:00
Morgan Thomas
d430ddd809 Extract the code for formatting struct and enum-variant literal labels out into a common function 2022-03-12 04:40:05 -08:00
yipinliu
0c54921f93 Fixed code style issues 2022-03-12 20:36:56 +08:00
yipinliu
8247925313 Fixed tidy test 2022-03-12 20:04:14 +08:00
yipinliu
581e1bf0d7 Highlight escape sequences in byte strings 2022-03-12 19:03:14 +08:00
Morgan Thomas
b3640ce424 make the doc comment on render::compound::visible_fields a little better 2022-03-11 19:23:04 -08:00
Morgan Thomas
6a1c151159 visibility tweak for CI 2022-03-11 19:10:43 -08:00
Morgan Thomas
2a22cf8efc Complete enum variants identically to structures.
In particular:
 - unit variants now display in the menu as "Variant", complete to "Variant", and display a detail of "Variant" (was "()")
 - tuple variants now display in the menu as "Variant(…)", complete to "Variant(${1:()})$0" (was "Variant($0)"), and display a detail of "Variant(type)" (was "(type)")
 - record variants now display in the menu as "Variant {…}", complete to "Variant { x: ${1:()} }$0" (was "Variant"), and display a detail of "Variant { x: type }" (was "{x: type}")

This behavior is identical to that of struct completions. In addition, tuple variants no longer set triggers_call_info, as to my understanding it's unnecessary now that we're emitting placeholders.

Tests have been updated to match, and the render::enum_variant::tests::inserts_parens_for_tuple_enums test has been removed entirely as it's covered by other tests (render::enum_detail_includes_{record, tuple}_fields, render::enum_detail_just_name_for_unit, render::pattern::enum_qualified).
2022-03-11 18:26:01 -08:00
Morgan Thomas
1c5b2c7d03 - Break out functionality related to rendering struct completions into crates/ide_completion/src/render/compound.rs
- Add support for placeholder completions in tuple structs
- Denote tuple struct completions with `(…)` instead of ` {…}`
- Show struct completions as their type (`Struct { field: Type }`) in the completion menu instead of raw snippet text (`Struct { field: ${1:()} }$0`)
2022-03-11 17:55:25 -08:00
bors[bot]
36e87fdb98
Merge #11685
11685: internal: Simplify CompletionContext r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-12 01:15:21 +00:00
Lukas Wirth
0b54d31359 Remove no_completions_required from CompletionContext 2022-03-12 02:12:00 +01:00
bors[bot]
71f7e67dcf
Merge #11684
11684: fix: Allow configuration of colons in inlay-hints r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-12 00:44:39 +00:00
Lukas Wirth
119ba82e4b minor: add missing definitions of lsp_ext::InlayHintLabel 2022-03-12 01:08:33 +01:00
bors[bot]
bbe61565bb
Merge #11683
11683: fix: Stop wrapping ConstParam's default values in ConstArg r=Veykril a=steven-joruk

I came across this problem while implementing the assist for inlining type aliases. This was causing `ConstParam::default_val` to always return `None` for block expressions. The `const_arg_path` test was actually testing const params so I've updated that.

The only code that uses `default_val` right now is  the `extract_function` assist. I couldn't figure out how to hit the affected code path, if someone can give me hint I'll add a test.

This test in my WIP branch fails without this:
```rust
    #[test]
    fn param_expression() {
        check_assist(
            inline_type_alias,
            r#"
type A<const N: usize = { 1 }> = [u32; N];
fn main() {
    let a: $0A;
}
"#,
            r#"
type A<const N: usize = { 1 }> = [u32; N];
fn main() {
    let a: [u32; { 1 }];
}
"#,
        );
    }
```

Co-authored-by: Steven Joruk <steven@joruk.com>
2022-03-11 23:31:24 +00:00
Steven Joruk
8a28430676 refactor: Rename and move const_arg_path
It wasn't testing the `const_arg` code path, it was actually hitting
const_param's default value code path, so move it to the right place
and rename it.
2022-03-11 22:28:38 +00:00
Steven Joruk
e84453c47f refactor: Rename const_arg_content to const_arg_expr 2022-03-11 22:28:35 +00:00
Lukas Wirth
62265ee9cb fix: Allow configuration of colons in inlay-hints 2022-03-11 21:15:36 +01:00
Steven Joruk
972f50da2d fix: Stop wrapping ConstParam's default values in ConstArg
This was causing ConstParam::default_val to always return None for block
expressions.

CONST_ARG@24..29
  BLOCK_EXPR@24..29
    ...
2022-03-11 19:51:35 +00:00
bors[bot]
224a255c5a
Merge #11680
11680: fix: Show what file paths were expected for unresolved modules r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-11 16:17:59 +00:00
Lukas Wirth
a9dd606387 fix: Show what file paths were expected for unresolved modules 2022-03-11 17:08:30 +01:00
bors[bot]
69e5bd5a25
Merge #11676
11676: internal: Expand into pseudo-derive attribute expansions in completions r=Veykril a=Veykril

With this we now properly handle qualified path completions in derives
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-10 21:24:11 +00:00
Lukas Wirth
6c8c02f625 Don't parse source files to generate macro completion details 2022-03-10 22:21:58 +01:00
Lukas Wirth
b1ab5770c9 Enable qualifier completions for derives 2022-03-10 21:56:19 +01:00
Lukas Wirth
2abe19e46a Don't offer qualified path completions for buitlin derives 2022-03-10 21:22:13 +01:00
Lukas Wirth
a8b76b632c Expand into pseudo-derive attribute expansions in completions 2022-03-10 20:53:50 +01:00
bors[bot]
e963443a0d
Merge #11672
11672: Add support for new `where` clause location in associated types. r=Veykril a=Dirbaio

A recent Rust nightly changed it: https://github.com/rust-lang/rust/issues/89122

This allows both the old and new location.

Fixes #11651

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-03-10 17:24:36 +00:00
Dario Nieuwenhuis
49d1207775 Add support for new where clause location in associated types.
A recent Rust nightly changed it: https://github.com/rust-lang/rust/issues/89122

This allows both the old and new location.
2022-03-10 18:21:29 +01:00
bors[bot]
356c507357
Merge #11671
11671: minor: Access parser internals through ide_db for ide crates r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-10 16:15:12 +00:00