Add fixups for incomplete in proc-macros
Partially implements https://github.com/rust-lang/rust-analyzer/issues/12777.
Added support for for loops and match statements.
I couldn't do paths like `crate::foo::` as I wasn't able to add `SyntheticTokens` to the end of `foo::`, they always ended up after `crate::`
This is my first contribution so please don't be shy about letting me know if I've done anything wrong!
fix: make `concat!` work with char
Fixes#12921
- I avoided making `unquote_str()` take char literals as well because it's depended on by another function `parse_string()` that's only supposed to take strings.
- Even with this patch, we don't output `\0` as `\u{0}` which #12921 pointed out ~~, but we're not actually responsible for serializing it but rowan is~~. They are functionally equivalent and I don't think it'd cause any confusion, but we *could* try escaping them before serialization (for reference, `rustc -Zunpretty=expanded`, which `cargo expand` uses under the hood, [makes use of `str::escape_default()`](3830ecaa8d/compiler/rustc_ast/src/util/literal.rs (L161)).
More methods and traits for `la_arena::ArenaMap`
Continue of #12931. Seems that I forgot some methods in the previous PR :(
I also changed `ArenaMap::insert` to return the old value, to match the map-like collection API of std. **So this is a breaking change.**
r? `@lnicola`
Run stable `fmt` & `cargo` through `rustup`
`cargo test -p ide-assists` fails on Windows/x64/nightly:
```shell
> rustup self update
info: checking for self-updates
rustup unchanged - 1.25.1
> rustup update
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'
info: checking for self-updates
stable-x86_64-pc-windows-msvc unchanged - rustc 1.62.1 (e092d0b6b 2022-07-16)
nightly-x86_64-pc-windows-msvc unchanged - rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
info: cleaning up downloads & tmp directories
> rustup show
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\stanc\.rustup
installed toolchains
--------------------
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc (default)
active toolchain
----------------
nightly-x86_64-pc-windows-msvc (default)
rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
> cargo test -p ide-assists
test tests::sourcegen::sourcegen_assists_docs ... FAILED
failures:
---- tests::sourcegen::sourcegen_assists_docs stdout ----
thread 'tests::sourcegen::sourcegen_assists_docs' panicked at 'Failed to run rustfmt from toolchain 'stable'. Please run `rustup component add rustfmt --toolchain stable` to install it.', crates\sourcegen\src\lib.rs:141:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::sourcegen::sourcegen_assists_docs
test result: FAILED. 1576 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.82s
error: test failed, to rerun pass '-p ide-assists --lib'
```
After some investigation it seemed that [`cmd!`](51705698bd/crates/sourcegen/src/lib.rs (L139)) didn't execute the expected (stable) rustfmt.
A simple `xshell` test failed too:
```rust
use xshell::{cmd, Shell};
fn main() {
let sh = &Shell::new().unwrap();
sh.set_var("RUSTUP_TOOLCHAIN", "stable");
let version = cmd!(sh, "rustfmt --version").read().unwrap_or_default();
println!("{version}");
}
```
Bypassing `xshell` and using `Command` directly failed too:
```rust
use std::process::{Command, Stdio};
fn main() {
let child = Command::new("rustfmt")
.arg("--version")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.env("RUSTUP_TOOLCHAIN", "stable")
.spawn()
.expect("failed to start");
let output = child.wait_with_output().unwrap();
let version = String::from_utf8_lossy(&output.stdout);
println!("{version}");
}
```
Spawning `cargo +stable fmt version` [failed too](https://github.com/rust-lang/rustup/issues/3036) with `error: no such subcommand: +stable`.
Only `rustup run stable` worked fine for both `cargo` and `fmt`.
Thanks to `@lnicola` for a live investigation session, hints and tips.
Add more constructors and entry-APIs for la-arena
`la-arena` on crates.io is quite helpful when just a thin wrapper for Vec with u32 indices is needed.
But the current API is not ergonomic enough.
This PR
- Adds `ArenaMap::new`. Not sure why only `Arena` has it now.
- Adds `Arena{,Map}::with_capacity` for known-size storage.
- Adds entry-API for `ArenaMap` for easier `.entry(idx).or_default().push(value)` or `.entry(idx).or_insert(...)` operations.
Don't switch workspace on vfs file changes from libraries
When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
feat: Only flycheck workspace that belongs to saved file
Supercedes https://github.com/rust-lang/rust-analyzer/pull/11038
There is still the problem that all the diagnostics are cleared, only clearing diagnostics of the relevant workspace isn't easily doable though I think, will have to dig into that