mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
Fix rust analyzer
This commit is contained in:
parent
5002c54ffb
commit
726844bc96
27
Cargo.lock
generated
27
Cargo.lock
generated
@ -236,6 +236,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "home"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indicatif"
|
name = "indicatif"
|
||||||
version = "0.10.3"
|
version = "0.10.3"
|
||||||
@ -289,9 +298,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.8"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kernel32-sys"
|
name = "kernel32-sys"
|
||||||
@ -547,11 +556,13 @@ dependencies = [
|
|||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"console 0.7.7",
|
"console 0.7.7",
|
||||||
"glob",
|
"glob",
|
||||||
|
"home",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"notify",
|
"notify",
|
||||||
"predicates",
|
"predicates",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -578,18 +589,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.129"
|
version = "1.0.133"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d1f72836d2aa753853178eda473a3b9d8e4eefdaf20523b919677e6de489f8f1"
|
checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.129"
|
version = "1.0.133"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e57ae87ad533d9a56427558b516d0adac283614e347abf85b0dc0cbbf0a249f3"
|
checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -598,9 +609,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.66"
|
version = "1.0.74"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127"
|
checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
|||||||
15
Cargo.toml
15
Cargo.toml
@ -1,8 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
version = "4.6.0"
|
version = "4.6.0"
|
||||||
authors = ["anastasie <ana@ana.st>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com>"]
|
authors = [
|
||||||
|
"anastasie <ana@ana.st>",
|
||||||
|
"Carol (Nichols || Goulding) <carol.nichols@gmail.com>",
|
||||||
|
]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-run = "rustlings"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argh = "0.1.4"
|
argh = "0.1.4"
|
||||||
@ -11,12 +15,19 @@ console = "0.7.7"
|
|||||||
notify = "4.0.15"
|
notify = "4.0.15"
|
||||||
toml = "0.4.10"
|
toml = "0.4.10"
|
||||||
regex = "1.1.6"
|
regex = "1.1.6"
|
||||||
serde = {version = "1.0.10", features = ["derive"]}
|
serde = { version = "1.0.133", features = ["derive"] }
|
||||||
|
glob = "0.3.0"
|
||||||
|
serde_json = "1.0.74"
|
||||||
|
home = "0.5.3"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rustlings"
|
name = "rustlings"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "fix-rust-analyzer"
|
||||||
|
path = "src/fix-rust-analyzer.rs"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "0.11.0"
|
assert_cmd = "0.11.0"
|
||||||
predicates = "1.0.1"
|
predicates = "1.0.1"
|
||||||
|
|||||||
72
src/fix-rust-analyzer.rs
Normal file
72
src/fix-rust-analyzer.rs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
use glob::glob;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct RustProject {
|
||||||
|
sysroot_src: String,
|
||||||
|
crates: Vec<Crate>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct Crate {
|
||||||
|
root_module: String,
|
||||||
|
edition: String,
|
||||||
|
deps: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RustProject {
|
||||||
|
fn new() -> RustProject {
|
||||||
|
RustProject {
|
||||||
|
sysroot_src: RustProject::get_sysroot_src(),
|
||||||
|
crates: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_sysroot_src() -> String {
|
||||||
|
let mut sysroot_src = home::rustup_home()
|
||||||
|
.expect("Can't find Rustup... aborting")
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
use std::process::Command;
|
||||||
|
let output = Command::new("rustup")
|
||||||
|
.arg("default")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to get rustup default toolchain");
|
||||||
|
|
||||||
|
let toolchain = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
|
|
||||||
|
sysroot_src += "/toolchains/";
|
||||||
|
sysroot_src += toolchain
|
||||||
|
.split_once(' ')
|
||||||
|
.expect("Malformed default toolchain path")
|
||||||
|
.0;
|
||||||
|
sysroot_src += "/lib/rustlib/src/rust/library";
|
||||||
|
println!("{}", sysroot_src);
|
||||||
|
sysroot_src
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut project = RustProject::new();
|
||||||
|
for e in glob("./exercises/**/*").expect("Glob failed to read pattern") {
|
||||||
|
let path = e
|
||||||
|
.expect("Unable to extract path")
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string();
|
||||||
|
if let Some((_, ext)) = path.split_once(".") {
|
||||||
|
if ext == "rs" {
|
||||||
|
project.crates.push(Crate {
|
||||||
|
deps: Vec::new(),
|
||||||
|
edition: "2021".to_string(),
|
||||||
|
root_module: path,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::fs::write(
|
||||||
|
"./rust-project.json",
|
||||||
|
serde_json::to_vec(&project).expect("Failed to serialize to JSON"),
|
||||||
|
)
|
||||||
|
.expect("Failed to write file");
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user