Commit Graph

159 Commits

Author SHA1 Message Date
Victor Song
53b6700594 Add dedicated target_dir field to CargoConfig and FlycheckConfig
Add dedicated field for `target_dir` in the configurations for Cargo
and Flycheck. Also change the directory to be a `PathBuf` as opposed to
a `String` to be more appropriate to the operating system.
2023-10-09 02:15:05 -05:00
bors
c405509f2e Auto merge of #15560 - davidbarsky:davidbarsky/use-sysroot-rustc-to-determine-cfgs, r=Veykril
project-model: when using `rust-project.json`, prefer the sysroot-defined rustc over discovery in `$PATH`

At the moment, rust-analyzer discovers `rustc` via the `$PATH` even if the `sysroot` field is defined in a `rust-project.json`. However, this does not work for users who do not have rustup installed, resulting in any `cfg`-based inference in rust-analzyer not working correctly. In my (decently naive!) opinion, it makes more sense to rely on the `sysroot` field in the `rust-project.json`.

One might ask "why not add `rustc` to the `$PATH`?" That is a reasonable question, but that doesn't work for my use case:
- The path to the sysroot in my employer's monorepo changes depending on which platform a user is on. For example, if they're on Linux, they'd want to use the sysroot defined at path `a`, whereas if they're on macOS, they'd want to use the sysroot at path `b` (I wrote the sysroot resolution functionality [here](765da4ca1e/integrations/rust-project/src/sysroot.rs (L39)), if you're curious).
- The location of the sysroot can (and does!) change, especially as people figure out how to make Rust run successfully on non-Linux platforms (e.g., iOS, Android, etc.) in a monorepo. Updating people's `$PATH` company-wide is hard while updating a config inside a CLI is pretty easy.

## Testing

I've created a `rust-project.json` using [rust-project](https://github.com/facebook/buck2/tree/main/integrations/rust-project) and was able to successfully load a project with and without the `sysroot`/`sysroot_src` fields—without those fields, rust-analyzer fell back to the `$PATH` based approach, as evidenced by `[DEBUG project_model::rustc_cfg] using rustc from env rustc="rustc"` showing up in the logs.
2023-09-08 18:14:25 +00:00
David Barsky
0bf6ffaf82
Update crates/project-model/src/rustc_cfg.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2023-09-08 14:07:59 -04:00
Lukas Wirth
fddef42e92 Only set rust-analyzer cfg for workspace members 2023-09-08 11:02:56 +02:00
Lukas Wirth
e9e2c1ae75 Update project-model test outputs 2023-09-08 10:49:15 +02:00
Lukas Wirth
ca6ddd8ea3 Enable rust_analyzer for cfgs when code is being analyzed by rust-analyzer 2023-09-08 10:49:12 +02:00
Ali Bektas
506a477acf Use cargo name as the CARGO_CRATE_NAME instead of package name 2023-09-08 01:41:00 +02:00
David Barsky
912b22fa07 add doc comment to rustc_cfg::RustcCfgConfig 2023-09-07 15:30:11 -04:00
David Barsky
fad3823a20 rename rustc_cfg::Config to rustc_cfg::RustcCfgConfig and import 2023-09-07 15:19:04 -04:00
David Barsky
553152e2d5 refactor rustc_cfg to be more inline with docs/dev/style.md 2023-09-07 15:06:51 -04:00
David Barsky
5b5bce8aaf project-model: when using rust-project.json, prefer the sysroot-defined rustc over an env-based one 2023-09-07 11:46:14 -04:00
Lukas Wirth
18b24f60d0 More error context when failing to invoke the rust toolchain 2023-08-09 14:09:37 +02:00
Ryo Yoshida
dfb32cdf10
Optimize DepKindInfo -> DepKind conversion
We don't need to allocate a `Vec`, nor do we need sorting.
2023-07-21 17:10:42 +09:00
hkalbasi
41b8b0b77d Enable cfg miri in analysis 2023-07-14 22:59:46 +03:30
David Lattimore
bea3a33d84 Change in-tree libs to workspace dependencies 2023-06-20 13:53:39 +10:00
Alex Kladov
6303551cb8 internal: use consistent style for error handling 2023-06-19 13:01:47 +01:00
Alex Kladov
49318bbae7 fix: ensure that ws loading error includes path to ws 2023-06-19 12:32:04 +01:00
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
Lukas Wirth
ecb8616870 fix: Don't duplicate sysroot crates in rustc workspace 2023-05-31 15:37:35 +02:00
bors
e8dbb8e2e0 Auto merge of #14911 - Veykril:config-cfg, r=Veykril
Allow setting cfgs

Fixes https://github.com/rust-lang/rust-analyzer/issues/14365
2023-05-30 12:00:14 +00:00
Lukas Wirth
cea84427e0 Allow setting cfgs 2023-05-28 13:43:21 +02:00
Lukas Wirth
35b208aaa7 Filter out unused cargo features from config 2023-05-26 22:16:34 +02:00
Lukas Wirth
f47caa666e Add AbsPath::absolutize 2023-05-13 11:51:28 +02:00
Lukas Wirth
939ebb4454 Forbid canonicalization of paths and normalize all rust-project.json paths 2023-05-04 14:51:35 +02:00
Laurențiu Nicola
7197a27028 Use triomphe Arc 2023-05-02 20:02:43 +03:00
bors
a7168a8c6f Auto merge of #14712 - Veykril:metadata-extra-args, r=Veykril
fix: Only pass unstable flags to cargo metadata from extra args config
2023-05-02 16:34:39 +00:00
Lukas Wirth
16b3febcf5 Only pass unstable flags to cargo metadata from extra args config 2023-05-02 17:33:58 +02:00
Ddystopia
fc888b583d
Add target_directory path to CargoWorkspace 2023-05-02 17:06:31 +02:00
Bruno Ortiz
072f69e4c1 fixing ts linting and rust test 2023-05-02 11:01:53 -03:00
Bruno Ortiz
66fe84d936 accepting review suggestions 2023-05-02 11:01:41 -03:00
Bruno Ortiz
c372fb3495 fixing tests for windows 2023-05-02 10:59:31 -03:00
Bruno Ortiz
a3081a6774 Adding crate_root_path to crate_graph 2023-05-02 10:59:31 -03:00
wackbyte
01c59812ae
fix grammar 2023-04-28 23:04:08 -04:00
bors
797c2f1dde Auto merge of #14659 - Veykril:dedup-crates, r=Veykril
Deduplicate crates when extending crate graphs

This is quadratic in runtime per deduplication attempt, but I don't think that'll be a problem for the workload here. Don't be scared of the diff, the actual diff is +42 -22, the rest is tests and test data.
Fixes https://github.com/rust-lang/rust-analyzer/issues/14476
2023-04-26 09:44:27 +00:00
Lukas Wirth
968850d7bf Deduplicate crates when extending crate graphs 2023-04-26 11:44:11 +02:00
Lukas Wirth
c21860bd6a Remove proc-macro server command from the rust-analyzer binary 2023-04-26 08:19:28 +02:00
bors
943d2a8a1c Auto merge of #14642 - jakhh8:master, r=Veykril
minor: Use `CargoConfig.extra_args` for fetching metadata

Fixes #14510
2023-04-25 12:46:29 +00:00
Lukas Wirth
10d7d7304b
Revert "Handle dev-dependency cycles" 2023-04-25 14:29:26 +02:00
Lukas Wirth
e205af259d Prefer test duped crates for ide features 2023-04-25 11:39:58 +02:00
Lukas Wirth
a4c7a87755 Handle dev-dependency cycles 2023-04-25 10:57:25 +02:00
Lukas Wirth
980c75bc91 Add more complex project-model test 2023-04-25 10:49:48 +02:00
wtj
59c4cc36c4 fix: remove extra argument "rustc" 2023-04-25 02:46:09 +08:00
jakhh8
62c9d96c67 fix 2023-04-24 10:13:29 +02:00
jakhh8
f502169f1c minor: use extra_args for fetching workspace 2023-04-23 21:19:40 +02:00
bors
0289dfa261 Auto merge of #14599 - HKalbasi:dev2, r=HKalbasi
Detect sysroot dependencies using symlink copy

cc #7637

It is currently in a proof of concept stage, and it doesn't generates a copy. You need to provide your own sysroot copy in `/tmp/ra-sysroot-hack` in a way that `/tmp/ra-sysroot-hack/library/std/lib.rs` exists and `/tmp/ra-sysroot-hack/Cargo.toml` is [the one from this comment](https://github.com/rust-lang/rust-analyzer/issues/7637#issuecomment-1495008329). I will add the symlink code if we decide that this approach is not a dead end.

It seems to somehow work on my system. Go to definition into std dependencies works, type checking can look through fields if I make them public and `cfg_if` appears to work (I tested it by hovering both sides and seeing that the correct one is enabled). Though finding layout of `HashMap` didn't work.

Please try it and let me know if I should go forward in this direction or not.
2023-04-20 22:26:17 +00:00
hkalbasi
39715ce26f Add RA_UNSTABLE_SYSROOT_HACK 2023-04-20 22:55:39 +03:30
Ryo Yoshida
4db87f9346
Fix release channel detection
See bootstrap code in rust-lang/rust for versioning details: e49122fb1c/src/bootstrap/lib.rs (L1244)
2023-04-18 02:12:17 +09:00
Lukas Wirth
dd5c3c30b6 internal: Warn when loading sysroot fails to find the core library 2023-04-13 08:40:14 +02:00
Lukas Wirth
72d47144e8 fix: Fix receiver adjustments for extract_variable assist 2023-04-11 14:01:23 +02:00
Lukas Wirth
7f0fbf7f9d Switch crate graph to use an Arena instead of a hashmap 2023-04-05 10:32:02 +02:00