From aa897bed72005321b349802e204ad5d9925572c7 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 13 Nov 2023 19:59:22 +0300 Subject: [PATCH] Add RUST_SRC_PATH when Rust Analyzer is included --- src/cli/cmd/init/handlers/rust.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cli/cmd/init/handlers/rust.rs b/src/cli/cmd/init/handlers/rust.rs index 82f5b01b..a0514b98 100644 --- a/src/cli/cmd/init/handlers/rust.rs +++ b/src/cli/cmd/init/handlers/rust.rs @@ -19,18 +19,14 @@ impl Handler for Rust { .push(String::from("rust-overlay.overlays.default")); let rust_toolchain_func = String::from(if project.has_file("rust-toolchain") { - "final.rust-bin.fromRustupToolchainFile ./rust-toolchain" + "(final.rust-bin.fromRustupToolchainFile ./rust-toolchain)" } else if project.has_file("rust-toolchain.toml") { - "final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml" + "(final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)" } else { // TODO: make this more granular "final.rust-bin.stable.latest.default" }); - flake - .overlay_attrs - .insert(String::from("rustToolchain"), rust_toolchain_func); - flake.dev_shell_packages.push(String::from("rustToolchain")); // Add cargo-* tools @@ -43,6 +39,25 @@ impl Handler for Rust { if Prompt::bool("Would you like to add Rust Analyzer to the environment?") { flake.dev_shell_packages.push(String::from("rust-analyzer")); + + let rust_toolchain_func_with_override = format!( + "{}.override {{ extensions = [ \"rust-src\"]; }}", + rust_toolchain_func + ); + + flake.overlay_attrs.insert( + String::from("rustToolchain"), + rust_toolchain_func_with_override, + ); + + flake.env_vars.insert( + String::from("RUST_SRC_PATH"), + String::from("${pkgs.rustToolchain}/lib/rustlib/src/rust/library"), + ); + } else { + flake + .overlay_attrs + .insert(String::from("rustToolchain"), rust_toolchain_func); } if Prompt::bool(