Skip to content

Commit 109a9dd

Browse files
author
Grant Wuerker
committed
cleanup
1 parent c43d72b commit 109a9dd

File tree

6 files changed

+59
-26
lines changed

6 files changed

+59
-26
lines changed

crates/common/src/config.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use smol_str::SmolStr;
55
use toml::Value;
66
use url::Url;
77

8-
use crate::ingot::Version;
8+
use crate::{ingot::Version, urlext::UrlExt};
99

1010
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1111
pub struct Config {
@@ -152,25 +152,17 @@ impl Dependency {
152152
DependencyDescription::Path(path) => BasedDependency {
153153
alias: self.alias.clone(),
154154
arguments: IngotArguments::default(),
155-
url: join_dependency_path(base_url, path),
155+
url: base_url.join_directory(path).unwrap(),
156156
},
157157
DependencyDescription::PathWithArguments { path, arguments } => BasedDependency {
158158
alias: self.alias.clone(),
159159
arguments: IngotArguments::default(),
160-
url: join_dependency_path(base_url, path),
160+
url: base_url.join_directory(path).unwrap(),
161161
},
162162
}
163163
}
164164
}
165165

166-
fn join_dependency_path(base_url: &Url, path: &Utf8PathBuf) -> Url {
167-
if base_url.as_str().ends_with("/") {
168-
base_url.join(path.as_str()).unwrap()
169-
} else {
170-
Url::from_str(&format!("{}/{}", base_url.as_str(), path.as_str())).unwrap()
171-
}
172-
}
173-
174166
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
175167
pub struct BasedDependency {
176168
pub alias: SmolStr,

crates/common/src/urlext.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum UrlExtError {
1010
pub trait UrlExt {
1111
fn parent(&self) -> Option<Url>;
1212
fn directory(&self) -> Option<Url>;
13+
fn join_directory(&self, path: &Utf8PathBuf) -> Result<Url, ()>;
1314
}
1415

1516
impl UrlExt for Url {
@@ -50,6 +51,16 @@ impl UrlExt for Url {
5051
return Some(parent);
5152
}
5253
}
54+
55+
fn join_directory(&self, path: &Utf8PathBuf) -> Result<Url, ()> {
56+
Ok(if path.as_str().ends_with("/") {
57+
self.join(path.as_str()).map_err(|_| ())?
58+
} else {
59+
let mut path = path.clone();
60+
path.push("");
61+
self.join(path.as_str()).map_err(|_| ())?
62+
})
63+
}
5364
}
5465

5566
pub fn canonical_url(path: &Utf8PathBuf) -> Result<Url, ()> {

crates/driver/src/lib.rs

Lines changed: 27 additions & 8 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::{urlext::canonical_url, InputDb};
7+
use common::{config::DependencyDescription, urlext::canonical_url, InputDb};
88
pub use db::DriverDataBase;
99

1010
use common::{
@@ -13,7 +13,7 @@ use common::{
1313
};
1414
use hir::hir_def::TopLevelMod;
1515
use resolver::{
16-
files::{File, FilesResolver},
16+
files::{File, FilesResolutionError, FilesResolver},
1717
ingot::ingot_graph_resolver,
1818
ResolutionHandler, Resolver,
1919
};
@@ -22,7 +22,13 @@ use url::Url;
2222

2323
pub fn setup_workspace(
2424
path: &Utf8PathBuf,
25-
) -> (DriverDataBase, Workspace, Vec<WorkspaceSetupDiagnostics>) {
25+
) -> (
26+
DriverDataBase,
27+
Workspace,
28+
Url,
29+
Vec<Url>,
30+
Vec<WorkspaceSetupDiagnostics>,
31+
) {
2632
let mut db = DriverDataBase::default();
2733
let ingot_url = canonical_url(path).unwrap();
2834
let workspace = db.workspace();
@@ -31,12 +37,22 @@ pub fn setup_workspace(
3137
workspace,
3238
};
3339
let mut ingot_graph_resolver = ingot_graph_resolver(node_handler);
34-
let _graph = ingot_graph_resolver.transient_resolve(&ingot_url).unwrap();
40+
let graph = ingot_graph_resolver.transient_resolve(&ingot_url).unwrap();
41+
let dependency_urls = graph
42+
.node_weights()
43+
.filter(|weight| *weight != &ingot_url)
44+
.cloned()
45+
.collect();
3546

3647
let diagnostics = ingot_graph_resolver
3748
.take_diagnostics()
3849
.into_iter()
39-
.map(|diagnostic| WorkspaceSetupDiagnostics::UnresolvableIngotDependency)
50+
.map(
51+
|diagnostic| WorkspaceSetupDiagnostics::UnresolvableIngotDependency {
52+
target: diagnostic.0,
53+
error: diagnostic.1,
54+
},
55+
)
4056
.chain(
4157
ingot_graph_resolver
4258
.node_resolver
@@ -46,7 +62,7 @@ pub fn setup_workspace(
4662
)
4763
.collect();
4864

49-
(db, workspace, diagnostics)
65+
(db, workspace, ingot_url, dependency_urls, diagnostics)
5066
}
5167

5268
fn _dump_scope_graph(db: &DriverDataBase, top_mod: TopLevelMod) -> String {
@@ -57,9 +73,12 @@ fn _dump_scope_graph(db: &DriverDataBase, top_mod: TopLevelMod) -> String {
5773

5874
// Maybe the driver should eventually only support WASI?
5975

60-
#[derive(Clone, Debug)]
76+
#[derive(Debug)]
6177
pub enum WorkspaceSetupDiagnostics {
62-
UnresolvableIngotDependency,
78+
UnresolvableIngotDependency {
79+
target: Url,
80+
error: FilesResolutionError,
81+
},
6382
IngotDependencyCycle,
6483
FileError,
6584
}

crates/fe/src/check.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@ use common::urlext::canonical_url;
33
use url::Url;
44

55
pub fn check(path: &Utf8PathBuf) {
6-
let (db, workspace, diagnostics) = driver::setup_workspace(path);
6+
let (db, workspace, base_ingot_url, dependency_ingot_urls, diagnostics) =
7+
driver::setup_workspace(path);
78

89
for diagnostic in diagnostics {
910
println!("{:?}", diagnostic);
1011
}
1112

12-
let ingot = workspace
13-
// should probably get url from setup
14-
.containing_ingot(&db, &canonical_url(path).unwrap())
15-
.unwrap();
13+
let ingot = workspace.containing_ingot(&db, &base_ingot_url).unwrap();
1614
let diags = db.run_on_ingot(ingot);
17-
diags.emit(&db);
15+
if !diags.is_empty() {
16+
diags.emit(&db);
17+
}
18+
19+
for dependency_url in dependency_ingot_urls {
20+
println!("{}", dependency_url);
21+
let ingot = workspace.containing_ingot(&db, &dependency_url).unwrap();
22+
let diags = db.run_on_ingot(ingot);
23+
if !diags.is_empty() {
24+
diags.emit(&db);
25+
}
26+
}
1827
}

crates/resolver/src/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
}
5858

5959
#[derive(Debug)]
60-
pub struct UnresolvableNode<N, E>(N, E);
60+
pub struct UnresolvableNode<N, E>(pub N, pub E);
6161

6262
#[derive(Debug)]
6363
pub struct UnresolvableRootNode;

todo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- format workspace setup errors
2+
- add resolved graph to workspace and use it for easier access of salsa ingots

0 commit comments

Comments
 (0)