Skip to content

Commit c43d72b

Browse files
author
Grant Wuerker
committed
cleanup
1 parent 33c6e31 commit c43d72b

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

crates/common/src/urlext.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use camino::Utf8PathBuf;
12
use url::Url;
23

34
#[derive(Debug)]
@@ -51,6 +52,13 @@ impl UrlExt for Url {
5152
}
5253
}
5354

55+
pub fn canonical_url(path: &Utf8PathBuf) -> Result<Url, ()> {
56+
Ok(
57+
Url::from_directory_path(path.canonicalize_utf8().map_err(|_| ())?.as_str())
58+
.map_err(|_| ())?,
59+
)
60+
}
61+
5462
#[cfg(test)]
5563
mod tests {
5664
use super::*;

crates/driver/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod files;
44

55
use camino::Utf8PathBuf;
66

7-
use common::InputDb;
7+
use common::{urlext::canonical_url, InputDb};
88
pub use db::DriverDataBase;
99

1010
use common::{
@@ -24,15 +24,14 @@ pub fn setup_workspace(
2424
path: &Utf8PathBuf,
2525
) -> (DriverDataBase, Workspace, Vec<WorkspaceSetupDiagnostics>) {
2626
let mut db = DriverDataBase::default();
27+
let ingot_url = canonical_url(path).unwrap();
2728
let workspace = db.workspace();
2829
let node_handler = InputNodeHandler {
2930
db: &mut db,
3031
workspace,
3132
};
3233
let mut ingot_graph_resolver = ingot_graph_resolver(node_handler);
33-
let _graph = ingot_graph_resolver
34-
.transient_resolve(&Url::from_directory_path(&path.canonicalize_utf8().unwrap()).unwrap())
35-
.unwrap();
34+
let _graph = ingot_graph_resolver.transient_resolve(&ingot_url).unwrap();
3635

3736
let diagnostics = ingot_graph_resolver
3837
.take_diagnostics()

crates/fe/src/check.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use camino::Utf8PathBuf;
2+
use common::urlext::canonical_url;
23
use url::Url;
34

45
pub fn check(path: &Utf8PathBuf) {
@@ -9,14 +10,8 @@ pub fn check(path: &Utf8PathBuf) {
910
}
1011

1112
let ingot = workspace
12-
.containing_ingot(
13-
&db,
14-
&Url::from_file_path(path.canonicalize_utf8().unwrap().join("fe.toml")).unwrap(),
15-
// &Url::from_directory_path(path.canonicalize_utf8().unwrap())
16-
// .unwrap()
17-
// .directory()
18-
// .unwrap(),
19-
)
13+
// should probably get url from setup
14+
.containing_ingot(&db, &canonical_url(path).unwrap())
2015
.unwrap();
2116
let diags = db.run_on_ingot(ingot);
2217
diags.emit(&db);

crates/fe/src/tree.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::collections::{HashMap, HashSet};
22

33
use camino::Utf8PathBuf;
4-
use common::config::{Config, IngotArguments};
4+
use common::{
5+
config::{Config, IngotArguments},
6+
urlext::canonical_url,
7+
};
58
use resolver::{
69
graph::{petgraph, DiGraph, NodeIndex},
710
ingot::basic_ingot_graph_resolver,
@@ -12,16 +15,13 @@ use url::Url;
1215

1316
pub fn print_tree(path: &Utf8PathBuf) {
1417
let mut graph_resolver = basic_ingot_graph_resolver();
15-
let c_path = &path.canonicalize_utf8().unwrap();
16-
println!("{c_path}");
17-
let ingot_graph = graph_resolver
18-
.transient_resolve(&Url::from_directory_path(c_path.as_str()).unwrap())
19-
.unwrap();
18+
let ingot_url = canonical_url(path).unwrap();
19+
let ingot_graph = graph_resolver.transient_resolve(&ingot_url).unwrap();
2020
print!(
2121
"{}",
2222
print_tree_impl(
2323
&ingot_graph,
24-
&Url::from_directory_path(c_path.as_str()).unwrap(),
24+
&ingot_url,
2525
&graph_resolver.node_handler.configs
2626
)
2727
);

0 commit comments

Comments
 (0)