Commit Graph

23225 Commits

Author SHA1 Message Date
Lukas Wirth
c069f1b7d2 Prefer similar tokens when expanding macros speculatively 2022-10-10 22:47:52 +02:00
bors
d23537394e Auto merge of #13386 - Veykril:completions-ref, r=Veykril
Refactor completions expansion

Depends on https://github.com/rust-lang/rust-analyzer/pull/13384
Diff is unfortunately massive as I changed the functions in the analysis module from associated ones to standalone (unfortunately without an extra commit)
2022-10-10 14:05:38 +00:00
bors
deddad347b Auto merge of #13380 - Veykril:cfg-pat-params, r=Veykril
Honor cfg attributes on params when lowering their patterns

Closes https://github.com/rust-lang/rust-analyzer/issues/13375
2022-10-10 13:57:09 +00:00
bors
ef014aac02 Auto merge of #13385 - Veykril:progress, r=Veykril
Don't report build-scripts and proc-macros as metadata progress

Seems somewhat confusing to me, given `metadata` is already the step we do for workspace loading
2022-10-10 13:48:26 +00:00
Lukas Wirth
f3ae5e56fb Refactor completions expansion 2022-10-10 15:45:24 +02:00
Lukas Wirth
fd9cd8476b Don't report build-scripts and proc-macros are metadata progress 2022-10-10 15:41:32 +02:00
bors
4ac3f2c24f Auto merge of #13384 - Veykril:macro-fallbacks, r=Veykril
Expand unmatched mbe fragments to reasonable default token trees

Currently we expand unmatched fragments by not replacing them at all, leaving us with `$ident`. This trips up the parser or subsequent macro calls. Instead it makes more sense to replace these with some reasonable default depending on the fragment kind which should make more recursive macro calls work better for completions.
2022-10-10 13:40:09 +00:00
Lukas Wirth
78f33c0e96 Expand unmatched mbe fragments to reasonable default token trees
Currently we expand unmatched fragments by not replacing them at all,
leaving us with `$ident`. This trips up the parser or subsequent macro
calls. Instead it makes more sense to replace these with some reasonable
default depending on the fragment kind which should make more recursive
macro calls work better for completions.
2022-10-10 14:27:05 +02:00
bors
3a69435af7 Auto merge of #13333 - feniljain:fix_assists, r=Veykril
fix(generate_method): correct method indentation inside generated impl and change gen loc

should fix #10619
2022-10-10 08:36:18 +00:00
bors
dcf1d71bb8 Auto merge of #13303 - jplatte:convert-named-struct-to-tuple-struct, r=Veykril
Add convert_named_struct_to_tuple_struct assist

Closes #11643, since the assist for converting in the other direction is already there (I based most of the implementation and all of the tests on it).
2022-10-10 08:24:37 +00:00
bors
79a3f84002 Auto merge of #13367 - matklad:fix-problem-matchers, r=Veykril
fix: in VSCode, correctly resolve relative paths to errors

VS Code problem matcher are restricted to be static "regexes". You can't create a problem matcher dynamically, and you can't use custom code in lieu of problem matcher.

This creates a problem for rust/cargo compiler errors. They use paths relative to the root of the Cargo workspace, but VS Code doesn't necessary know where that root is.

Luckily, there's a way out: our current problem matcher is defined like this:

    "fileLocation": [ "autoDetect", "${workspaceRoot}" ],

That means that relative pahts would be resoleved relative to workspace root. VS Code allows to specify a command inside `${}`. So we can plug custom logic there to fetch Cargo's workspace root!

And that's exactly what this PR is doing!
2022-10-10 07:54:55 +00:00
Lukas Wirth
63ed71bd30 Honor cfg attributes on params when lowering their patterns 2022-10-10 09:47:09 +02:00
bors
05a6bc48b5 Auto merge of #13377 - DropDemBits:doc-link-underline-range, r=Veykril
fix: Underline only the intra-doc link itself instead of the whole doc comment
2022-10-10 07:14:43 +00:00
bors
910c565b17 Auto merge of #13376 - DropDemBits:strip-generic-bounds-and-defaults, r=Veykril
internal: Add `GenericParamList::to_generic_args` and `{TypeParam,ConstParam}::remove_default` APIs

Also fixes `generate_impl` not removing the default const param value, though it seems that no one has encountered or reported that issue yet 😅

This initially started out as refactoring `utils::generate_impl_text_inner` to understand it better (which was the reason for adding `{TypeParam,ConstParam}::remove_default`), but ended up also finding another place that needed `GenericParamList::to_generic_args`, hence its addition in here.
2022-10-10 06:34:58 +00:00
DropDemBits
a69cccfc0e Underline only the intra-doc link instead of the whole doc comment 2022-10-09 21:29:31 -04:00
DropDemBits
1015a177d4 Have to_generic_args return ast::GenericArgList 2022-10-09 21:03:38 -04:00
DropDemBits
bfe6ec9b77 Add {TypeParam, ConstParam}::remove_default
Also includes a drive-by refactor of `utils::generate_impl_text_inner`,
since that's what drove this change
2022-10-09 18:46:31 -04:00
DropDemBits
75f641799e Add GenericParamList::to_generic_args 2022-10-09 18:44:23 -04:00
Aleksey Kladov
5bbfea03cc fix: in VSCode, correctly resolve relative paths to errors
VS Code problem matcher are restricted to be static "regexes". You can't
create a problem matcher dynamically, and you can't use custom code in
lieu of problem matcher.

This creates a problem for rust/cargo compiler errors. They use paths
relative to the root of the Cargo workspace, but VS Code doesn't
necessary know where that root is.

Luckily, there's a way out: our current problem matcher is defined like
this:

    "fileLocation": [ "autoDetect", "${workspaceRoot}" ],

That means that relative pahts would be resoleved relative to workspace
root. VS Code allows to specify a command inside `${}`. So we can plug
custom logic there to fetch Cargo's workspace root!

And that's exactly what this PR is doing!
2022-10-08 23:25:13 +01:00
bors
61504c8d95 Auto merge of #13366 - matklad:xflags, r=lnicola
internal: ⬆️ xflags

The main change here should be that flags are not inhereted, so

   $ rust-analyzer analysis-stats . -v -v

would do what it should do

We also no longer Don\'t
2022-10-08 16:46:15 +00:00
Aleksey Kladov
39fa8b5c39 internal: ⬆️ xflags
The main change here should be that flags are not inhereted, so

   $ rust-analyzer analysis-stats . -v -v

would do what it should do

We also no longer Don\'t
2022-10-08 15:35:07 +01:00
bors
8437e4ba58 Auto merge of #13362 - WaffleLapkin:go_to_def_fix_doc_include_str, r=Veykril
fix: Make go-to-def work for `#[doc = include_str!("path")]`

See the added test, go-to-def on `#[doc = include_str!("path$0")]` should navigate to `path`.
2022-10-07 09:56:12 +00:00
Maybe Waffle
1c0ec9f0c8 Fix go-to-def for #[doc = include_str!("path")] 2022-10-07 09:04:41 +00:00
bors
a415fb4c4e Auto merge of #13353 - wildbook:fix_type_inference_panic, r=Veykril
Fix assertion failure in type inference (#13352)

Fixes https://github.com/rust-lang/rust-analyzer/issues/13352
2022-10-06 12:33:50 +00:00
bors
f2f3528618 Auto merge of #13356 - WaffleLapkin:go_to_def_shadow_include, r=Veykril
minor: Fix go-to-def for shadowed `include*!`

Add a check in go-to-def feature, so that we don't assume any macro named `include`/`include_str`/`include_bytes` is the builtin one.
2022-10-06 06:28:31 +00:00
Maybe Waffle
a57ef6b0b1 Fix go-to-def for shadowed include*! 2022-10-06 06:16:39 +00:00
Wildbook
8862fe6ff2 Fix assertion failure in type inference (#13352) 2022-10-05 17:46:56 +02:00
bors
476d043874 Auto merge of #13344 - lowr:patch/change-generic-param-order, r=Veykril
fix: use `BoundVar`s from current generic scope

Fixup for #13335, addresses https://github.com/rust-lang/rust-analyzer/pull/13339#issuecomment-1266654607

Before the change in generic parameter order, `BoundVar`s for trait reference didn't change whether you are in an impl's scope or in an associated item's scope. Now that item's generic params come before its parent's, we need to shift their indices when we are in an associated item's scope.
2022-10-04 18:26:43 +00:00
Ryo Yoshida
ded3326a64
fix: use BoundVars from current generic scope 2022-10-05 00:49:00 +09:00
bors
b429df2653 Auto merge of #13342 - rust-lang:revert-13328-rustc-proc-macro, r=Veykril
Revert "Add proc-macro dependency to rustc crates"

1. This panics since it indexes into the wrong thing, so fixes https://github.com/rust-lang/rust-analyzer/issues/13340
2. This didn't fix what I thought it would either
Reverts rust-lang/rust-analyzer#13328
2022-10-04 06:18:57 +00:00
Lukas Wirth
e0c9e28d1f
Revert "Add proc-macro dependency to rustc crates" 2022-10-04 08:18:01 +02:00
bors
974caaff8f Auto merge of #13339 - lowr:patch/change-generic-param-order, r=Veykril
fix: treat enum variants as generic item on their own

Fixup for #13335

It turns out I tried to merge two procedures into one utility function without noticing the incompatibility.

This time I *did* run analysis-stats on the four crates and confirmed it doesn't crash and this patch doesn't cause regression.
2022-10-03 15:34:32 +00:00
Ryo Yoshida
e0a161b2e3
fix: treat enum variants as generic item on their own 2022-10-04 00:07:34 +09:00
bors
5bd98e36bc Auto merge of #13335 - lowr:patch/change-generic-param-order, r=Veykril
internal: change generic parameter order

tl;dr: This PR changes the `Substitution` for trait items and methods like so:

```rust
trait Trait<TP, const CP: usize> { // note the implicit Self as first parameter
  type Type<TC, const CC: usize>;
  fn f<TC, const CC: usize>() {}
}
impl<TP, const CP: usize> S {
  fn f<TC, const CC: usize>() {}
}
```

- before this PR: `[Self, TP, CP, TC, CC]` for each trait item, `[TP, CP, TC, CC]` for `S::f`
- after this PR: `[TC, CC, Self, TP, CP]` for each trait item, `[TC, CC, TP, CP]` for `S::f`

---

This PR "inverts" the generic parameters/arguments of an item and its parent. This is to fulfill [chalk's expectation](d875af0ff1/chalk-solve/src/rust_ir.rs (L498-L502)) on the order of generic arguments in `Substitution`s for generic associated types and it's one step forward for GATs support (hopefully). Although chalk doesn't put any constraint for other items, it feels more natural to get everything aligned than special casing GATs.

One complication is that `TyBuilder` now demands its users to pass in parent's `Substitution` upon construction unless it's obvious that the the item has no parent (e.g. an ADT never has parent). All users *should* already know the parent of the item in question, and without this, it cannot be easily reasoned about whether we're pushing the argument for the item or for its parent.

Some additional notes:
- f8f5a5ea57: This isn't related to the change, but I felt it's nicer.

- 78977cd86c: There's one major change here other than the generic param order: Default arguments are now bound by the same `Binder` as the item in question rather than a `Binder` limited to parameters they can refer to (i.e. arguments that syntactically appear before them). Now that the order of generic parameters is changed, it would be somewhat complicated to make such `Binder`s as before, and the "full" `Binder`s shouldn't be a problem because we already make sure that the default arguments don't refer to the generic arguments after them with `fallback_bound_vars()`.

- 7556f74b16: This is split from 4385d3dcd0 to make it easy to revert if it turns out that the GATs with const generics panic is actually not resolved with this PR. cc #11878 #11957
2022-10-03 12:13:25 +00:00
bors
f087ebe6e7 Auto merge of #13338 - Veykril:flycheck, r=Veykril
Prioritize restart messages in flycheck

cc https://github.com/rust-lang/rust-analyzer/issues/12936#issuecomment-1264670905
2022-10-03 12:05:11 +00:00
Lukas Wirth
5916803555 Prioritize restart messages in flycheck 2022-10-03 14:03:54 +02:00
Ryo Yoshida
7556f74b16
Remove hack 2022-10-03 02:40:12 +09:00
Ryo Yoshida
78977cd86c
Adapt to the new generic parameter/argument order 2022-10-03 02:40:07 +09:00
Ryo Yoshida
4385d3dcd0
Change generic parameter/argument order
This commit "inverts" the order of generic parameters/arguments of an
item and its parent. This is to fulfill chalk's expectation on the
order of `Substitution` for generic associated types and it's one step
forward for their support (hopefully).

Although chalk doesn't put any constraint on the order of `Substitution`
for other items, it feels natural to get everything aligned rather than
special casing GATs.

One complication is that `TyBuilder` now demands its users to pass in
parent's `Substitution` upon construction unless it's obvious that the
the item has no parent (e.g. an ADT never has parent). All users
*should* already know the parent of the item in question, and without
this, it cannot be easily reasoned about whether we're pushing the
argument for the item or for its parent.

Quick comparison of how this commit changes `Substitution`:

```rust
trait Trait<TP, const CP: usize> {
  type Type<TC, const CC: usize> = ();
  fn f<TC, const CC: usize>() {}
}
```

- before this commit: `[Self, TP, CP, TC, CC]` for each trait item
- after this commit: `[TC, CC, Self, TP, CP]` for each trait item
2022-10-03 02:39:25 +09:00
Ryo Yoshida
f8f5a5ea57
refactor: use cast() instead of interning GenericArgData 2022-10-02 22:40:55 +09:00
bors
5c28ad1932 Auto merge of #13328 - Veykril:rustc-proc-macro, r=Veykril
Add proc-macro dependency to rustc crates
2022-10-01 19:29:33 +00:00
Lukas Wirth
870825b376 Add proc-macro dependency to rustc crates 2022-10-01 21:29:14 +02:00
bors
cdc5493901 Auto merge of #13327 - Veykril:proc-macro-srv-config, r=Veykril
Add config for supplying sysroot path
2022-10-01 19:17:36 +00:00
Lukas Wirth
5424c51158 Add config for supplying sysroot path 2022-10-01 21:17:06 +02:00
bors
bf5cad8e77 Auto merge of #13326 - Veykril:proc-macro-srv-config, r=Veykril
Do not use the sysroot proc-macro server when a server path is given explicitly
2022-10-01 17:51:47 +00:00
Lukas Wirth
26cf250ccc Do not use the sysroot proc-macro server when a server path is given explicitly 2022-10-01 19:50:34 +02:00
bors
f88293f777 Auto merge of #13324 - Veykril:trait-impl-completion, r=Veykril
Fix trait impl item completions using macro file text ranges

Fixes https://github.com/rust-lang/rust-analyzer/issues/13323
2022-10-01 13:35:08 +00:00
Lukas Wirth
bfd5f00bfc Fix trait impl item completions using macro file text ranges 2022-10-01 15:34:45 +02:00
bors
5b7e40014e Auto merge of #13321 - Veykril:format-str-args, r=Veykril
Fix move_format_string_arg being tokentree unaware

Fixes https://github.com/rust-lang/rust-analyzer/issues/13261
2022-09-30 22:42:40 +00:00
Lukas Wirth
3ad0334718 Fix move_format_string_arg being tokentree unaware 2022-10-01 00:42:16 +02:00