Skip to content

Commit edaf178

Browse files
author
Grant Wuerker
committed
renaming and git resolver cleanup
1 parent 6cb1c6d commit edaf178

File tree

5 files changed

+71
-97
lines changed

5 files changed

+71
-97
lines changed

crates/driver/src/handlers/remote.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use common::{
88
use resolver::{
99
ResolutionHandler, Resolver,
1010
files::{FilesResolver, FilesResource},
11-
git::{GitDependencyDescription, GitResolver, GitResource},
11+
git::{GitDescription, GitResolver, GitResource},
1212
graph::{DiGraph, GraphResolutionHandler, petgraph::visit::EdgeRef},
1313
};
1414
use smol_str::SmolStr;
@@ -18,13 +18,13 @@ use crate::{IngotInitDiagnostics, ingot_files_resolver};
1818

1919
#[derive(Clone)]
2020
struct RemoteFilesContext {
21-
description: GitDependencyDescription,
21+
description: GitDescription,
2222
checkout_path: Utf8PathBuf,
2323
}
2424

2525
pub struct RemoteIngotHandler<'a> {
2626
pub db: &'a mut dyn InputDb,
27-
ingot_urls: HashMap<GitDependencyDescription, Url>,
27+
ingot_urls: HashMap<GitDescription, Url>,
2828
pub diagnostics: Vec<IngotInitDiagnostics>,
2929
current_context: Option<RemoteFilesContext>,
3030
}
@@ -39,7 +39,7 @@ impl<'a> RemoteIngotHandler<'a> {
3939
}
4040
}
4141

42-
pub fn ingot_url(&self, description: &GitDependencyDescription) -> Option<&Url> {
42+
pub fn ingot_url(&self, description: &GitDescription) -> Option<&Url> {
4343
self.ingot_urls.get(description)
4444
}
4545

@@ -66,7 +66,7 @@ impl<'a> RemoteIngotHandler<'a> {
6666
has_config.then_some(())
6767
}
6868

69-
fn register_remote_mapping(&mut self, ingot_url: &Url, description: &GitDependencyDescription) {
69+
fn register_remote_mapping(&mut self, ingot_url: &Url, description: &GitDescription) {
7070
let remote = RemoteFiles {
7171
source: description.source.clone(),
7272
rev: SmolStr::new(description.rev.clone()),
@@ -84,12 +84,12 @@ impl<'a> RemoteIngotHandler<'a> {
8484
dependency: DependencyLocation,
8585
alias: SmolStr,
8686
arguments: DependencyArguments,
87-
) -> Option<(GitDependencyDescription, (SmolStr, DependencyArguments))> {
87+
) -> Option<(GitDescription, (SmolStr, DependencyArguments))> {
8888
match dependency {
8989
DependencyLocation::Local(local) => {
9090
match relative_path_within_checkout(context.checkout_path.as_path(), &local.url) {
9191
Ok(relative_path) => {
92-
let mut next_description = GitDependencyDescription::new(
92+
let mut next_description = GitDescription::new(
9393
context.description.source.clone(),
9494
context.description.rev.clone(),
9595
);
@@ -111,7 +111,7 @@ impl<'a> RemoteIngotHandler<'a> {
111111
}
112112
DependencyLocation::Remote(remote) => {
113113
let mut next_description =
114-
GitDependencyDescription::new(remote.source.clone(), remote.rev.to_string());
114+
GitDescription::new(remote.source.clone(), remote.rev.to_string());
115115
if let Some(path) = remote.path.clone() {
116116
next_description = next_description.with_path(path);
117117
}
@@ -123,31 +123,42 @@ impl<'a> RemoteIngotHandler<'a> {
123123

124124
impl<'a> ResolutionHandler<GitResolver> for RemoteIngotHandler<'a> {
125125
type Item = Vec<(
126-
GitDependencyDescription,
126+
GitDescription,
127127
(DependencyAlias, DependencyArguments),
128128
)>;
129129

130130
fn handle_resolution(
131131
&mut self,
132-
description: &GitDependencyDescription,
132+
description: &GitDescription,
133133
resource: GitResource,
134134
) -> Self::Item {
135+
// Compute ingot_path based on description.path
136+
let ingot_path = if let Some(relative) = &description.path {
137+
resource.checkout_path.join(relative)
138+
} else {
139+
resource.checkout_path.clone()
140+
};
141+
142+
// Convert ingot_path to URL
143+
let ingot_url = Url::from_directory_path(ingot_path.as_std_path())
144+
.expect("Failed to convert ingot path to URL");
145+
135146
self.ingot_urls
136-
.insert(description.clone(), resource.ingot_url.clone());
147+
.insert(description.clone(), ingot_url.clone());
137148

138149
let mut files_resolver = ingot_files_resolver();
139150
self.current_context = Some(RemoteFilesContext {
140151
description: description.clone(),
141152
checkout_path: resource.checkout_path.clone(),
142153
});
143-
let files_result = files_resolver.resolve(self, &resource.ingot_url);
154+
let files_result = files_resolver.resolve(self, &ingot_url);
144155
self.current_context = None;
145156

146157
for diagnostic in files_resolver.take_diagnostics() {
147158
let target_url = diagnostic
148159
.url()
149160
.cloned()
150-
.unwrap_or_else(|| resource.ingot_url.clone());
161+
.unwrap_or_else(|| ingot_url.clone());
151162
self.diagnostics
152163
.push(IngotInitDiagnostics::RemoteFileError {
153164
ingot_url: target_url,
@@ -160,7 +171,7 @@ impl<'a> ResolutionHandler<GitResolver> for RemoteIngotHandler<'a> {
160171
Err(error) => {
161172
self.diagnostics
162173
.push(IngotInitDiagnostics::RemoteFileError {
163-
ingot_url: resource.ingot_url.clone(),
174+
ingot_url: ingot_url.clone(),
164175
error: error.to_string(),
165176
});
166177
Vec::new()
@@ -171,7 +182,7 @@ impl<'a> ResolutionHandler<GitResolver> for RemoteIngotHandler<'a> {
171182

172183
impl<'a> ResolutionHandler<FilesResolver> for RemoteIngotHandler<'a> {
173184
type Item = Vec<(
174-
GitDependencyDescription,
185+
GitDescription,
175186
(DependencyAlias, DependencyArguments),
176187
)>;
177188

@@ -242,16 +253,16 @@ impl<'a> ResolutionHandler<FilesResolver> for RemoteIngotHandler<'a> {
242253

243254
impl<'a>
244255
GraphResolutionHandler<
245-
GitDependencyDescription,
246-
DiGraph<GitDependencyDescription, (DependencyAlias, DependencyArguments)>,
256+
GitDescription,
257+
DiGraph<GitDescription, (DependencyAlias, DependencyArguments)>,
247258
> for RemoteIngotHandler<'a>
248259
{
249260
type Item = DiGraph<Url, (DependencyAlias, DependencyArguments)>;
250261

251262
fn handle_graph_resolution(
252263
&mut self,
253-
_description: &GitDependencyDescription,
254-
graph: DiGraph<GitDependencyDescription, (DependencyAlias, DependencyArguments)>,
264+
_description: &GitDescription,
265+
graph: DiGraph<GitDescription, (DependencyAlias, DependencyArguments)>,
255266
) -> Self::Item {
256267
let mut converted: DiGraph<Url, (DependencyAlias, DependencyArguments)> = DiGraph::new();
257268
let mut node_map = HashMap::new();

crates/driver/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hir::hir_def::TopLevelMod;
2525
use resolver::{
2626
Resolver,
2727
files::{FilesResolutionDiagnostic, FilesResolutionError, FilesResolver},
28-
git::{GitDependencyDescription, GitResolutionError, GitResolver},
28+
git::{GitDescription, GitResolutionError, GitResolver},
2929
graph::{GraphResolver, GraphResolverImpl},
3030
ingot::{LocalGraphResolver, project_files_resolver},
3131
};
@@ -170,7 +170,7 @@ pub enum IngotInitDiagnostics {
170170
diagnostics: Vec<common::config::ConfigDiagnostic>,
171171
},
172172
UnresolvableRemoteDependency {
173-
target: GitDependencyDescription,
173+
target: GitDescription,
174174
error: GitResolutionError,
175175
},
176176
RemoteDependencyCycle {
@@ -369,8 +369,8 @@ fn remote_checkout_root(ingot_url: &Url) -> Utf8PathBuf {
369369
ingot_path
370370
}
371371

372-
fn git_description_from_request(request: &ExternalDependencyEdge) -> GitDependencyDescription {
373-
let mut description = GitDependencyDescription::new(
372+
fn git_description_from_request(request: &ExternalDependencyEdge) -> GitDescription {
373+
let mut description = GitDescription::new(
374374
request.remote.source.clone(),
375375
request.remote.rev.to_string(),
376376
);

crates/fe/src/tree.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ratatui::{
3131
use resolver::{
3232
ResolutionHandler, Resolver,
3333
files::{FilesResolver, FilesResource},
34-
git::{GitDependencyDescription, GitResolver, GitResource},
34+
git::{GitDescription, GitResolver, GitResource},
3535
graph::{
3636
DiGraph, GraphResolutionHandler, GraphResolver, GraphResolverImpl, NodeIndex,
3737
petgraph::{self, visit::EdgeRef},
@@ -534,8 +534,8 @@ fn tree_remote_checkout_root(ingot_url: &Url) -> Utf8PathBuf {
534534
ingot_path
535535
}
536536

537-
fn tree_git_description_from_request(request: &ExternalDependencyEdge) -> GitDependencyDescription {
538-
let mut description = GitDependencyDescription::new(
537+
fn tree_git_description_from_request(request: &ExternalDependencyEdge) -> GitDescription {
538+
let mut description = GitDescription::new(
539539
request.remote.source.clone(),
540540
request.remote.rev.to_string(),
541541
);
@@ -554,7 +554,7 @@ fn describe_remote_target(remote: &RemoteFiles) -> String {
554554

555555
struct TreeRemoteHandler {
556556
metadata: HashMap<Url, NodeMetadata>,
557-
ingot_urls: HashMap<GitDependencyDescription, Url>,
557+
ingot_urls: HashMap<GitDescription, Url>,
558558
diagnostics: Vec<String>,
559559
}
560560

@@ -567,7 +567,7 @@ impl TreeRemoteHandler {
567567
}
568568
}
569569

570-
fn ingot_url(&self, description: &GitDependencyDescription) -> Option<&Url> {
570+
fn ingot_url(&self, description: &GitDescription) -> Option<&Url> {
571571
self.ingot_urls.get(description)
572572
}
573573

@@ -581,23 +581,34 @@ impl TreeRemoteHandler {
581581
}
582582

583583
impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
584-
type Item = Vec<(GitDependencyDescription, TreeEdge)>;
584+
type Item = Vec<(GitDescription, TreeEdge)>;
585585

586586
fn handle_resolution(
587587
&mut self,
588-
description: &GitDependencyDescription,
588+
description: &GitDescription,
589589
resource: GitResource,
590590
) -> Self::Item {
591+
// Compute ingot_path based on description.path
592+
let ingot_path = if let Some(relative) = &description.path {
593+
resource.checkout_path.join(relative)
594+
} else {
595+
resource.checkout_path.clone()
596+
};
597+
598+
// Convert ingot_path to URL
599+
let ingot_url = Url::from_directory_path(ingot_path.as_std_path())
600+
.expect("Failed to convert ingot path to URL");
601+
591602
self.ingot_urls
592-
.insert(description.clone(), resource.ingot_url.clone());
603+
.insert(description.clone(), ingot_url.clone());
593604

594-
let config_path = resource.ingot_path.join("fe.toml");
605+
let config_path = ingot_path.join("fe.toml");
595606
let config_content = match std::fs::read_to_string(&config_path) {
596607
Ok(content) => content,
597608
Err(error) => {
598609
self.diagnostics.push(format!(
599610
"Remote file error at {}: {error}",
600-
resource.ingot_url
611+
ingot_url
601612
));
602613
return vec![];
603614
}
@@ -608,7 +619,7 @@ impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
608619
Err(error) => {
609620
self.diagnostics.push(format!(
610621
"Invalid remote fe.toml file in {}: {error}",
611-
resource.ingot_url
622+
ingot_url
612623
));
613624
return vec![];
614625
}
@@ -618,18 +629,18 @@ impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
618629
for diagnostic in &config.diagnostics {
619630
self.diagnostics.push(format!(
620631
"Erroneous remote fe.toml file in {}: {diagnostic}",
621-
resource.ingot_url
632+
ingot_url
622633
));
623634
}
624635
}
625636

626637
self.metadata.insert(
627-
resource.ingot_url.clone(),
638+
ingot_url.clone(),
628639
NodeMetadata::from_config(&config),
629640
);
630641

631642
let mut dependencies = Vec::new();
632-
for dependency in config.dependencies(&resource.ingot_url) {
643+
for dependency in config.dependencies(&ingot_url) {
633644
let alias = dependency.alias;
634645
let arguments = dependency.arguments;
635646
match dependency.location {
@@ -638,7 +649,7 @@ impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
638649
&local.url,
639650
) {
640651
Ok(relative_path) => {
641-
let mut next_description = GitDependencyDescription::new(
652+
let mut next_description = GitDescription::new(
642653
description.source.clone(),
643654
description.rev.clone(),
644655
);
@@ -650,12 +661,12 @@ impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
650661
Err(error) => {
651662
self.diagnostics.push(format!(
652663
"Remote dependency '{}' in {} points outside the repository: {error}",
653-
alias, resource.ingot_url
664+
alias, ingot_url
654665
));
655666
}
656667
},
657668
DependencyLocation::Remote(remote) => {
658-
let mut next_description = GitDependencyDescription::new(
669+
let mut next_description = GitDescription::new(
659670
remote.source.clone(),
660671
remote.rev.to_string(),
661672
);
@@ -671,15 +682,15 @@ impl ResolutionHandler<GitResolver> for TreeRemoteHandler {
671682
}
672683
}
673684

674-
impl GraphResolutionHandler<GitDependencyDescription, DiGraph<GitDependencyDescription, TreeEdge>>
685+
impl GraphResolutionHandler<GitDescription, DiGraph<GitDescription, TreeEdge>>
675686
for TreeRemoteHandler
676687
{
677688
type Item = DiGraph<Url, TreeEdge>;
678689

679690
fn handle_graph_resolution(
680691
&mut self,
681-
_description: &GitDependencyDescription,
682-
graph: DiGraph<GitDependencyDescription, TreeEdge>,
692+
_description: &GitDescription,
693+
graph: DiGraph<GitDescription, TreeEdge>,
683694
) -> Self::Item {
684695
let mut converted = DiGraph::new();
685696
let mut node_map = HashMap::new();

0 commit comments

Comments
 (0)