mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
Remove check for rust analyzer, always generate rust-project.json
This commit is contained in:
parent
979f7788d8
commit
27c1be0e4e
410
rust-project.json
Normal file
410
rust-project.json
Normal file
@ -0,0 +1,410 @@
|
|||||||
|
{
|
||||||
|
"sysroot_src": "/home/jacko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library",
|
||||||
|
"crates": [
|
||||||
|
{
|
||||||
|
"root_module": "exercises/advanced_errors/advanced_errs1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/advanced_errors/advanced_errs2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/clippy/clippy1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/clippy/clippy2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/collections/hashmap1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/collections/hashmap2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/collections/vec1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/collections/vec2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/conversions/as_ref_mut.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/conversions/from_into.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/conversions/from_str.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/conversions/try_from_into.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/conversions/using_as.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/enums/enums1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/enums/enums2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/enums/enums3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/error_handling/errors6.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/functions/functions1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/functions/functions2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/functions/functions3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/functions/functions4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/functions/functions5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/generics/generics1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/generics/generics2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/generics/generics3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/if/if1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/if/if2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/macros/macros1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/macros/macros2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/macros/macros3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/macros/macros4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/modules/modules1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/modules/modules2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/modules/modules3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/move_semantics/move_semantics1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/move_semantics/move_semantics2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/move_semantics/move_semantics3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/move_semantics/move_semantics4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/move_semantics/move_semantics5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/option/option1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/option/option2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/option/option3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/primitive_types/primitive_types6.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/quiz1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/quiz2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/quiz3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/quiz4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/arc1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/box1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/iterators1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/iterators2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/iterators3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/iterators4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/standard_library_types/iterators5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/strings/strings1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/strings/strings2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/structs/structs1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/structs/structs2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/structs/structs3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/tests/tests1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/tests/tests2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/tests/tests3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/threads/threads1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/traits/traits1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/traits/traits2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables1.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables2.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables3.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables4.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables5.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"root_module": "exercises/variables/variables6.rs",
|
||||||
|
"edition": "2021",
|
||||||
|
"deps": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -7,29 +7,8 @@
|
|||||||
use glob::glob;
|
use glob::glob;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
/// Custom error to check if io error or rust-analyzer just doesn't exist
|
|
||||||
/// if rust-analyzer doesn't exist don't want to panic, want to print
|
|
||||||
/// message to console and continue
|
|
||||||
pub enum RustAnalyzerError {
|
|
||||||
IoError(std::io::Error),
|
|
||||||
NoRustAnalyzerError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for RustAnalyzerError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "invalid first item to double")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RustAnalyzerError {
|
|
||||||
fn from_io(err: std::io::Error) -> RustAnalyzerError {
|
|
||||||
RustAnalyzerError::IoError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contains the structure of resulting rust-project.json file
|
/// Contains the structure of resulting rust-project.json file
|
||||||
/// and functions to build the data required to create the file
|
/// and functions to build the data required to create the file
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@ -87,21 +66,6 @@ impl RustAnalyzerProject {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run `rust-analyzer --version` to check if rust analyzer exists, if it doesn't
|
|
||||||
/// then return custom error
|
|
||||||
pub fn check_rust_analyzer_exists(&self) -> Result<(), RustAnalyzerError> {
|
|
||||||
match Command::new("rust-analyzer").arg("--version").output() {
|
|
||||||
Ok(out) => {
|
|
||||||
if out.stderr.len() > 0 {
|
|
||||||
return Err(RustAnalyzerError::NoRustAnalyzerError);
|
|
||||||
} else {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(RustAnalyzerError::from_io(err)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use `rustup` command to determine the default toolchain, if it exists
|
/// Use `rustup` command to determine the default toolchain, if it exists
|
||||||
/// it will be put in RustAnalyzerProject.sysroot_src, otherwise an error will be returned
|
/// it will be put in RustAnalyzerProject.sysroot_src, otherwise an error will be returned
|
||||||
pub fn get_sysroot_src(&mut self) -> Result<(), Box<dyn Error>> {
|
pub fn get_sysroot_src(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
@ -134,12 +98,3 @@ fn parses_exercises() {
|
|||||||
.expect("Failed to parse exercises");
|
.expect("Failed to parse exercises");
|
||||||
assert_eq!(rust_project.crates.len() > 0, true);
|
assert_eq!(rust_project.crates.len() > 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_exists() {
|
|
||||||
let rust_project = RustAnalyzerProject::new();
|
|
||||||
match rust_project.check_rust_analyzer_exists() {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => println!("Correctly identifying rust-analyzer doesn't exist"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
23
src/main.rs
23
src/main.rs
@ -1,5 +1,5 @@
|
|||||||
use crate::exercise::{Exercise, ExerciseList};
|
use crate::exercise::{Exercise, ExerciseList};
|
||||||
use crate::fix_rust_analyzer::{RustAnalyzerError, RustAnalyzerProject};
|
use crate::fix_rust_analyzer::RustAnalyzerProject;
|
||||||
use crate::run::run;
|
use crate::run::run;
|
||||||
use crate::verify::verify;
|
use crate::verify::verify;
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
@ -416,18 +416,13 @@ fn rustc_exists() -> bool {
|
|||||||
|
|
||||||
fn fix_rust_analyzer() {
|
fn fix_rust_analyzer() {
|
||||||
let mut rust_project = RustAnalyzerProject::new();
|
let mut rust_project = RustAnalyzerProject::new();
|
||||||
if rust_project.check_rust_analyzer_exists().is_ok() {
|
if let Err(err) = rust_project.get_sysroot_src() {
|
||||||
println!("rust-analyzer exists, fixing to work with rustlings");
|
println!("Couldn't find toolchain path for rust-analyzer: {}", &err)
|
||||||
if let Err(err) = rust_project.get_sysroot_src() {
|
|
||||||
println!("Error getting toolchain path: {}\nContinuing... rust-analyzer won't work with rustlings", &err)
|
|
||||||
}
|
|
||||||
if let Err(err) = rust_project.exercies_to_json() {
|
|
||||||
println!("Error parsing exercises and converting to json: {}\nContinuing... rust-analyzer won't work with rustlings", &err)
|
|
||||||
}
|
|
||||||
if let Err(_) = rust_project.write_to_disk() {
|
|
||||||
println!("Failed to write rust-project.json to disk, rust-analyzer won't work with rustlings");
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
println!("Can't find rust-analyzer, skipping fix\n")
|
|
||||||
}
|
}
|
||||||
|
if let Err(err) = rust_project.exercies_to_json() {
|
||||||
|
println!("Couldn't parse exercises for rust-analyzer: {}", &err)
|
||||||
|
}
|
||||||
|
if let Err(_) = rust_project.write_to_disk() {
|
||||||
|
println!("Failed to write rust-project.json to disk for rust-analyzer");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user