Skip to content

Commit

Permalink
Rework manifest to return errors and values with text ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Feb 28, 2024
1 parent 2c1d8fe commit c46144b
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 148 deletions.
75 changes: 8 additions & 67 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ clap = {version = "4.4", features = ["derive"]}
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8"
toml-span = "0.2"
semver = { version = "1.0", features = ["serde"] }
dyn-clone = "1.0"
6 changes: 3 additions & 3 deletions crates/project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition.workspace = true
authors.workspace = true

[dependencies]
serde.workspace = true
semver.workspace = true
toml.workspace = true
toml-span.workspace = true
thiserror.workspace = true
lsp-types.workspace = true
ropey.workspace = true
dyn-clone.workspace = true
dyn-clone.workspace = true
shrinkwraprs.workspace = true
14 changes: 8 additions & 6 deletions crates/project/src/content_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum ContentGraphError {
Io(#[from] FileError<std::io::Error>),
#[error(transparent)]
ManifestParse(#[from] FileError<ManifestParseError>),
//TODO introduce error ranges
#[error("content could not be found in this path")]
ContentPathNotFound {
path: PathBuf,
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct ContentGraph {
pub errors: Vec<ContentGraphError>
}

//TODO perhaps it would be better to have errors stored in nodes and make nodes public
#[derive(Debug)]
struct GraphNode {
content: Box<dyn Content>,
Expand Down Expand Up @@ -185,10 +187,10 @@ impl ContentGraph {
visited.insert(node_idx);

if let Some(dependencies) = self.nodes[node_idx].content.dependencies().cloned() {
for (dep_name, dep_val) in dependencies {
match dep_val {
for entry in dependencies.into_iter() {
match entry.value.inner() {
DependencyValue::FromRepo(active) => {
self.link_dependencies_value_from_repo(node_idx, content0_idx, visited, dep_name, active);
self.link_dependencies_value_from_repo(node_idx, content0_idx, visited, &entry.name, *active);
},
DependencyValue::FromPath { path } => {
self.link_dependencies_value_from_path(node_idx, content0_idx, visited, path);
Expand All @@ -206,7 +208,7 @@ impl ContentGraph {
node_idx: usize,
content0_idx: usize,
visited: &mut HashSet<usize>,
dependency_name: String,
dependency_name: &str,
active: bool
) {
if active {
Expand All @@ -226,7 +228,7 @@ impl ContentGraph {
node_idx: usize,
content0_idx: usize,
visited: &mut HashSet<usize>,
dependency_path: PathBuf
dependency_path: &Path
) {
let dependant_path = self.nodes[node_idx].content.path().to_path_buf();
let final_dependency_path = if dependency_path.is_absolute() {
Expand Down Expand Up @@ -273,7 +275,7 @@ impl ContentGraph {
},
Err(_) => {
self.errors.push(ContentGraphError::ContentPathNotFound {
path: dependency_path,
path: dependency_path.to_path_buf(),
origin: Some(dependant_path)
})
}
Expand Down
Loading

0 comments on commit c46144b

Please sign in to comment.