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.
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.
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.
fix: don't replace default members' body
cc #12779, #12821
addresses https://github.com/rust-lang/rust-analyzer/pull/12821#issuecomment-1190157506
`gen_trait_fn_body()` only attempts to implement required trait member functions, so we shouldn't call it for `Implement default members` assist.
This patch also documents the precondition of `gen_trait_fn_body()` and inserts `debug_assert!`, but I'm not entirely sure if the assertions are appropriate.
- use `path` instead of `paths`
- don't mark rust-analyzer as an optional tool
- print the cargo command that's run in the proc-macro-test build script
this originally was part of a change to fix `test --stage 0 rust-analyzer`,
but I'm going to leave that for a separate PR so it's easier to review.
fix: Don't add braces to 'if' completion in match guard position
fixes#12823
Is this what you were thinking of here, `@Veykril` ? I haven't done any work on completions before, so I could definitely be misunderstanding the issue.
fix: Fix restart server duplicating language clients
Reverts 03a62c180e
vscode-languageclient@8.0.0-next.15 and beyond changed the behaviour of language clients to be automatically started if a request comes in while they are not running. Currently when we restart the server via the restart command we recreate the language client, which causes VSCode to restart the stopped server, effectively duplicating our language clients...
Reverting the commit is simpler right now, the proper fix would be to only create a language client once and then use the `restart` functionality on it instead.
Fixes https://github.com/rust-lang/rust-analyzer/issues/12836
internal: Use ItemTree for variant, field and module attribute collection in attrs_query
Less parsing = very good, should speed up lang item collection as that basically probes attributes of all enum variants which currently triggers parsing
Not fond of how this is searching for the correct index, ideally we'd map between HIR and item tree Id here but I am not sure how, storing the item tree ids in the HIR version doesn't work due to the usage of `Trace`...