Commit graph

22824 commits

Author SHA1 Message Date
Lukas Wirth
7c59d7c75c fix: Fix pattern completions adding unnecessary braces 2022-07-28 15:47:46 +02:00
bors
02f9ec4be5 Auto merge of #12895 - Veykril:compl-anchor, r=Veykril
fix: Calculate completions after type anchors

Fixes https://github.com/rust-lang/rust-analyzer/issues/12892
2022-07-28 08:06:58 +00:00
Lukas Wirth
e782e59d3d fix: Calculate completions after type anchors 2022-07-28 10:06:36 +02:00
bors
40875353a5 Auto merge of #12891 - brennanvincent:expander_stack, r=lnicola
Use large stack on expander thread

I have verified that this fixes #12884 for me.

Hat tip to `@bjorn3` for identifying the cause of the issue.
2022-07-27 19:40:59 +00:00
Brennan Vincent
f83738e1d9 Use large stack on expander thread 2022-07-27 15:02:34 -04:00
Paul Lange
c16e4f260f Add syntax fixup for loop 2022-07-27 18:18:51 +02:00
Paul Lange
a969481952 Add syntax fixup for while loops 2022-07-27 18:16:58 +02:00
bors
9a1ec451d3 Auto merge of #12890 - Veykril:syntax-blocks, r=Veykril
internal: Assume condition/iterable is missing if there is only a BlockExpr

cc https://github.com/rust-lang/rust-analyzer/pull/12880#issuecomment-1195567103

It sounds good on paper, so let's try it
2022-07-27 15:30:03 +00:00
Lukas Wirth
bf893d59b5 internal: Assume condition/iterable is missing if there is only a BlockExpr 2022-07-27 17:29:51 +02:00
bors
b4d652aa40 Auto merge of #12830 - hi-rustin:rustin-patch-issue-12717-fix, r=Veykril
Find original ast node before compute ref match

ref https://github.com/rust-lang/rust-analyzer/issues/12717
2022-07-27 12:31:26 +00:00
hi-rustin
349dfc7e95 Find original ast node before compute ref match in fn render
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-07-27 20:18:00 +08:00
bors
cb32e269df Auto merge of #12887 - Veykril:compl-pref-fix, r=Veykril
fix: Honor ref expressions for compute_ref_match completions

Fixes https://github.com/rust-lang/rust-analyzer/issues/8357
2022-07-27 11:48:55 +00:00
Lukas Wirth
1f8daa180f fix: Honor ref expressions for compute_ref_match completions 2022-07-27 13:48:26 +02:00
bors
8e4d9b84fe Auto merge of #12886 - Veykril:sema-cache, r=Veykril
fix: Fix Semantics::original_ast_node not caching the resulting file
2022-07-27 10:46:20 +00:00
Lukas Wirth
6c379b9f4b fix: Fix Semantics::original_ast_node not caching the resulting file 2022-07-27 12:46:04 +02:00
bors
c2eebd7a50 Auto merge of #12877 - zachs18:inline-def-in-macro, r=zachs18
fix: Insert spaces when inlining a function defined in a macro.

(partially) fixes #12860.

This PR (only) addresses the whitespace issue when inlining functions defined in macros.

Additionally, the indentation/spacing is not ideal, but works, e.g.
```rs
macro_rules! define_function {
    () => { fn test_function_macro() {
        if let Some(3) = 3i32.checked_add(0) {
            println!("3 + 0 == 3");
        }
    } };
}
define_function!();
fn main() {
    test_function_macro();
}
// previously became
// ...
fn main() {
    ifletSome(3)=3i32.checked_add(0){println!("3 + 0 == 3");};
}
// now becomes
// ...
fn main() {
    if let Some(3) = 3i32.checked_add(0){
        println!("3 + 0 == 3");

      };
}
```

The `self` -> `this` problem[^this] is (probably?) a separate problem that I am also looking into.

[^this]: As mentioned in [my comment on the above issue](https://github.com/rust-lang/rust-analyzer/issues/12860#issuecomment-1193231766), inlining a method defined in a macro does not properly replace `self` with the new local `this`.
2022-07-26 16:14:51 +00:00
Zachary S
add33b65dd Remove FIXME comment for unreachable fallback. 2022-07-26 10:59:19 -05:00
bors
7a30f62ecf Auto merge of #12881 - Veykril:proc-srv, r=Veykril
fix: Fix server panicking on project loading when proc-macros are disabled

Fixes https://github.com/rust-lang/rust-analyzer/issues/12879
2022-07-26 14:31:26 +00:00
Lukas Wirth
c8ff70e924 fix: Fix server panicking on project loading when proc-macros are disabled 2022-07-26 16:30:45 +02:00
bors
1c752841e2 Auto merge of #12878 - fasterthanlime:standalone-pms-exe, r=lnicola
Find standalone proc-macro-srv on windows too

I forgot that executables end with `.exe` on Windows in:

  * https://github.com/rust-lang/rust-analyzer/pull/12858
2022-07-26 10:33:43 +00:00
Amos Wenger
b1e3daf14b Find standalone proc-macro-srv on windows too 2022-07-26 12:28:59 +02:00
bors
e36a20c24f Auto merge of #12864 - Veykril:derive-helpers, r=Veykril
feat: Resolve derive helper attributes in IDE layer

![image](https://user-images.githubusercontent.com/3757771/180647125-98cae13b-a7b4-446b-8a64-fae014f982e2.png)

Also downmaps tokens inside deriver helpers to the derive expansion
![image](https://user-images.githubusercontent.com/3757771/180642110-699bdc73-e1f3-4692-94f2-21544f824ab9.png)

This does not handle the case where multiple derives make use of the same helper name though, unsure how to tackle that yet.

Partially addresses https://github.com/rust-lang/rust-analyzer/issues/10935
2022-07-26 07:34:11 +00:00
Lukas Wirth
ddad2847ab Allow name querying for derive helpers 2022-07-26 09:27:22 +02:00
Lukas Wirth
aa1491ecde Record derive helper attributes, resolve them in IDE layer 2022-07-26 09:26:51 +02:00
Lukas Wirth
4e60db2d07 feat: Downmap tokens inside derive helpers 2022-07-26 09:26:47 +02:00
bors
7ba94a89e9 Auto merge of #12858 - fasterthanlime:proc-macro-srv-bin, r=Veykril
Add `rust-analyzer-proc-macro-srv` binary, use it if found in sysroot

This adds a `bin` crate which simply runs `proc_macro_srv::cli::run()` (it does no CLI argument parsing, nothing).

The intent is to build that crate in Rust CI as part of the `dist::Rustc` component, then ship it in the sysroot: it would probably land in something like `~/.rustup/toolchains/nightly-2022-07-23-x86_64-unknown-linux-gnu/libexec/proc-macro-srv-cli`.

This makes https://github.com/rust-lang/rustup/pull/3022 less pressing. (Instead of teaching RA about rustup components, we simply teach it to look in the sysroot via `rustc --print sysroot`. If it can't find `proc-macro-srv-cli`, it falls back to its own `proc-macro` subcommand).

This is closely related to https://github.com/rust-lang/rust-analyzer/issues/12803 (but doesn't close it yet).

Things to address now:

  * [ ] What should the binary be named? What should the crate be named? We can pick different names with `[bin]` in the `Cargo.toml`

Things to address later:

  * Disable the "multi ABI compatibility scheme" when building that binary in Rust CI (that'll probably happen in `rust-lang/rust`)
  * Teaching RA to look in the sysroot

Things to address much, much later:

  * Is JSON a good fit here
  * Do we want to add versioning to future-proof it?
  * Other bikesheds

When built with `--features sysroot` on `nightly-2022-07-23-x86_64-unknown-linux-gnu`, the binary is 7.4MB. After stripping debuginfo, it's 2.6MB. When compressed to `.tar.xz`, it's 619KB.

In a Zulip discussion, `@jyn514` and `@Mark-Simulacrum` seemed to think that those sizes weren't a stopper for including the binary in the rustc component, even before we shrink it down further.
2022-07-26 06:35:16 +00:00
Zachary S
e45a250f8c fix: Insert spaces when inlining a function defined in a macro. 2022-07-25 15:45:17 -05:00
Amos Wenger
2c2520fbb4 Allow specifying sysroot OR sysroot_src 2022-07-25 17:52:38 +02:00
Amos Wenger
696775153d Fix mix up in comments 2022-07-25 16:59:10 +02:00
Amos Wenger
74a2fad5e6 Gate and rename binary, use it if it's in the sysroot 2022-07-25 16:22:39 +02:00
Amos Wenger
dadb83282d Remember the difference between 'sysroot root' and 'sysroot src root', start looking in there for a rust-analyzer-proc-macro-srv binary 2022-07-25 16:07:41 +02:00
Amos Wenger
4364531c2f Name the binary 'proc-macro-srv' 2022-07-25 15:19:57 +02:00
Amos Wenger
fd1b64ec71 Return result directly
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-07-25 15:19:57 +02:00
Amos Wenger
fba6adfae4 Add doc comment to pass tidy check 2022-07-25 15:19:57 +02:00
Amos Wenger
5f54ec0e85 Add a proc-macro-srv-cli crate 2022-07-25 15:19:57 +02:00
bors
0b1ed70c12 Auto merge of #12871 - fasterthanlime:sync-from-rust-2, r=Veykril
Sync from `rust-lang/rust`

This is the first subtree sync PR from `rust-lang/rust` to `rust-lang/rust-analyzer`, made by following the instructions at: https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html#performing-the-sync-from-rust-langrust-to-clippy

It includes all the commits that were made in:

  * https://github.com/rust-lang/rust/pull/99603

(And that were reviewed ahead of time by `@Veykril` + `@lnicola)`
2022-07-25 12:58:58 +00:00
Amos Wenger
dc94050815 revert nightly rustfmt formatting that accidentally slipped in
cf. https://github.com/rust-lang/rust/pull/99603
cf. https://github.com/rust-lang/rust-analyzer/pull/12871#discussion_r928816339
2022-07-25 14:18:30 +02:00
Amos Wenger
0d04e63627 Merge remote-tracking branch 'origin/master' into sync-from-rust-2 2022-07-25 14:07:07 +02:00
bors
ac86b8edff Auto merge of #12856 - Veykril:multi-proc-srv, r=Veykril
feat: Spawn a proc-macro-srv instance per workspace

cc https://github.com/rust-lang/rust-analyzer/issues/12855

The idea is to have each server be spawned with the appropriate toolchain, that way workspaces with differing toolchains shouldn't suffer from proc-macro abi mismatches.
2022-07-25 10:41:05 +00:00
bors
c7788ad3be Auto merge of #12868 - lowr:follow-up-on-12832, r=lnicola
Replace `debug_assert!` with `stdx::always!`

Addresses https://github.com/rust-lang/rust-analyzer/pull/12832#issuecomment-1193713473
2022-07-25 10:15:08 +00:00
Ryo Yoshida
71225c35bf
Replace debug_assert! with stdx::always! 2022-07-25 18:41:10 +09:00
Amos Wenger
dfe84494c1 Make macros test order-resistant 2022-07-24 16:48:06 +02:00
bors
7e2b983fd4 Auto merge of #12861 - DorianListens:dscheidt/complete-field, r=DorianListens
fix: Autocomplete for struct fields includes receiver

fixes #12857
2022-07-24 14:11:35 +00:00
Amos Wenger
56c369db48 Sort when iterating through CrateGraph 2022-07-24 16:11:05 +02:00
Dorian Scheidt
77acb5c162 fix: Autocomplete for struct fields includes receiver
fixes #12857
2022-07-24 09:07:43 -05:00
Amos Wenger
d8c0d88e4f Sort in DefMap::dump, since HashMap iteration order isn't defined 2022-07-24 16:04:20 +02:00
bors
537cc1eec5 Auto merge of #12863 - lowr:fix/missing-fields-on-destructuring-assignment, r=Veykril
Fix missing fields check on destructuring assignment

Fixes #12838

When checking if the record literal in question is an assignee expression or not, the new fn `is_assignee_record_literal` iterates over its ancestors until it is sure. This isn't super efficient, as we don't cache anything and does the iteration for every record literal during missing fields check. Alternatively, we may want to have a field like `assignee` on `hir_def::Expr::{RecordLit, Array, Tuple, Call}` to tell if it's an assignee expression, which would be O(1) when checking later but have some memory overhead for the field.
2022-07-24 13:57:14 +00:00
Amos Wenger
ff317858c1 hir-def tests: sort results before comparing, since FxHashSet iteration order isn't guaranteed
(And, in fact, it failed on i686)
2022-07-24 15:55:26 +02:00
Ryo Yoshida
805ac666ca
fix: consider assignee expressions in record fields exhaustiveness check 2022-07-24 22:40:04 +09:00
Ryo Yoshida
64758bd481
Add info whether it's assignee expr to relevant HIR Expr variants 2022-07-24 22:40:00 +09:00