Skip to content

Commit

Permalink
show project focus, rendering misc
Browse files Browse the repository at this point in the history
  • Loading branch information
tbillington committed May 30, 2024
1 parent 6b1d36a commit d473012
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 44 deletions.
163 changes: 159 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion kondo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version = "0.9.0"
edition = "2021"

[dependencies]
cmake-parser = { git = "https://github.com/rust-utility/cmake-parser.git", rev = "bf7e490" }
cargo-util-schemas = "0.3.0"
cmake-parser = "0.1.0-alpha.1"
crossbeam-channel = "0.5"
crossbeam-deque = "0.8"
crossbeam-utils = "0.8"
Expand Down
6 changes: 5 additions & 1 deletion kondo-lib/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ use unity::UnityProject;
#[enum_dispatch(ProjectEnum)]
pub trait Project {
fn kind_name(&self) -> &'static str;
fn name(&self, root_dir: &Path) -> Option<String>;
fn is_project(&self, root_dir: &Path) -> bool;
fn name(&self, root_dir: &Path) -> Option<String>;
#[allow(unused_variables)]
fn project_focus(&self, root_dir: &Path) -> Option<String> {
None
}
/// Assumes `root_path` is a valid `Project` of the same kind resulting from `Project::is_proejct`
fn is_root_artifact(&self, root_path: &Path) -> bool;
/// Assumes `root_dir` is a valid `Project` of the same kind resulting from `Project::is_proejct`
Expand Down
47 changes: 40 additions & 7 deletions kondo-lib/src/project/rust.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::path::{Path, PathBuf};
use std::{
collections::HashMap,
path::{Path, PathBuf},
};

use serde::Deserialize;

Expand All @@ -16,15 +19,31 @@ impl Project for RustProject {
"Rust"
}

fn is_project(&self, root_dir: &Path) -> bool {
root_dir.join("Cargo.toml").exists()
}

fn name(&self, root_dir: &Path) -> Option<String> {
toml::from_str::<CargoToml>(&std::fs::read_to_string(root_dir.join("Cargo.toml")).ok()?)
.ok()?
.package?
.name
let manifest = RustProject::manifest(root_dir)?;

manifest.package?.name
}

fn is_project(&self, root_dir: &Path) -> bool {
root_dir.join("Cargo.toml").exists()
fn project_focus(&self, root_dir: &Path) -> Option<String> {
let manifest = RustProject::manifest(root_dir)?;

let bevy = manifest
.dependencies
.is_some_and(|deps| deps.contains_key("bevy"))
|| manifest
.workspace
.is_some_and(|w| w.dependencies.is_some_and(|deps| deps.contains_key("bevy")));

if bevy {
Some("Bevy".to_string())
} else {
None
}
}

fn is_root_artifact(&self, root_path: &Path) -> bool {
Expand All @@ -39,9 +58,23 @@ impl Project for RustProject {
}
}

impl RustProject {
fn manifest(root_dir: &Path) -> Option<CargoToml> {
toml::from_str::<CargoToml>(&std::fs::read_to_string(root_dir.join("Cargo.toml")).ok()?)
.ok()
}
}

#[derive(Deserialize)]
struct CargoToml {
package: Option<CargoTomlPackage>,
dependencies: Option<
HashMap<
cargo_util_schemas::manifest::PackageName,
cargo_util_schemas::manifest::InheritableDependency,
>,
>,
workspace: Option<cargo_util_schemas::manifest::TomlWorkspace>,
}

#[derive(Deserialize)]
Expand Down
Loading

0 comments on commit d473012

Please sign in to comment.