Skip to content

Commit 879be72

Browse files
author
Grant Wuerker
committed
ingot init fixes
1 parent b32ee44 commit 879be72

File tree

18 files changed

+310
-77
lines changed

18 files changed

+310
-77
lines changed

crates/common/src/dependencies/graph.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ impl DependencyGraph {
2626
self.node_map(db).contains_key(url)
2727
}
2828

29+
/// Returns all URLs in the dependency graph.
30+
pub fn all_urls(&self, db: &dyn InputDb) -> Vec<Url> {
31+
self.node_map(db).keys().cloned().collect()
32+
}
33+
2934
/// Returns a subgraph containing all cyclic nodes and all nodes that lead to cycles.
3035
///
3136
/// This method identifies strongly connected components (SCCs) in the graph and returns

crates/common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod urlext;
99

1010
use dependencies::DependencyGraph;
1111
use file::Workspace;
12+
pub use tracing;
1213

1314
#[salsa::db]
1415
// Each database must implement InputDb explicitly with its own storage mechanism

crates/driver/src/files.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1 @@
1-
use camino::Utf8PathBuf;
2-
31
pub const FE_TOML: &str = "fe.toml";
4-
5-
pub fn find_project_root() -> Option<Utf8PathBuf> {
6-
let mut path = Utf8PathBuf::from_path_buf(
7-
std::env::current_dir().expect("Unable to get current directory"),
8-
)
9-
.expect("Expected utf8 path");
10-
11-
loop {
12-
let fe_toml = path.join(FE_TOML);
13-
if fe_toml.is_file() {
14-
return Some(path);
15-
}
16-
17-
if !path.pop() {
18-
break;
19-
}
20-
}
21-
22-
None
23-
}

crates/driver/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,27 @@ pub fn ingot_graph_resolver<'a>() -> IngotGraphResolver<'a> {
3232
.with_required_directory("src")
3333
.with_required_file("src/lib.fe")
3434
.with_pattern("src/**/*.fe");
35+
3536
GraphResolverImpl::new(files_resolver)
3637
}
3738

3839
pub fn init_ingot(db: &mut DriverDataBase, ingot_url: &Url) -> Vec<IngotInitDiagnostics> {
40+
// Check if ingot is already initialized
41+
if db.graph().contains_url(db, ingot_url) {
42+
tracing::info!(target: "resolver", "Ingot already initialized: {}", ingot_url);
43+
return Vec::new();
44+
}
45+
3946
tracing::info!(target: "resolver", "Starting workspace ingot resolution for: {}", ingot_url);
47+
4048
let mut diagnostics: Vec<IngotInitDiagnostics> = {
4149
let mut handler = InputHandler::from_db(db, ingot_url.clone());
4250
let mut ingot_graph_resolver = ingot_graph_resolver();
4351

52+
// Always enable search mode for the initial URL
53+
// It will auto-disable after the first resolution so dependencies use exact paths
54+
ingot_graph_resolver.node_resolver.search_mode = true;
55+
4456
// Root ingot resolution should never fail since directory existence is validated earlier.
4557
// If it fails, it indicates a bug in the resolver or an unexpected system condition.
4658
if let Err(err) = ingot_graph_resolver.graph_resolve(&mut handler, ingot_url) {
@@ -304,6 +316,7 @@ impl<'a> GraphResolutionHandler<Url, DiGraph<Url, (SmolStr, DependencyArguments)
304316
let from_url = &graph[edge.source()];
305317
let to_url = &graph[edge.target()];
306318
let (alias, arguments) = edge.weight();
319+
307320
dependency_graph.add_dependency(
308321
self.db,
309322
from_url,
@@ -312,5 +325,11 @@ impl<'a> GraphResolutionHandler<Url, DiGraph<Url, (SmolStr, DependencyArguments)
312325
arguments.clone(),
313326
);
314327
}
328+
329+
// Log total ingot count after resolution
330+
let total_ingots = dependency_graph.all_urls(self.db).len();
331+
if total_ingots > 0 {
332+
tracing::info!(target: "resolver", "Total ingots in workspace: {}", total_ingots);
333+
}
315334
}
316335
}

crates/fe/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub enum Command {
3333
}
3434

3535
fn default_project_path() -> Utf8PathBuf {
36-
driver::files::find_project_root().unwrap_or(Utf8PathBuf::from("."))
36+
// With search mode enabled in init_ingot, we can just use the current directory
37+
// The FilesResolver will walk up to find the ingot root
38+
Utf8PathBuf::from(".")
3739
}
3840

3941
fn main() {

crates/fe/src/tree.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ pub type IngotGraphResolver =
7373
resolver::graph::GraphResolverImpl<FilesResolver, TreeHandler, (SmolStr, DependencyArguments)>;
7474

7575
pub fn tree_resolver() -> IngotGraphResolver {
76-
let files_resolver = FilesResolver::new().with_required_file("fe.toml");
76+
let files_resolver = FilesResolver::new()
77+
.with_required_file("fe.toml")
78+
.with_search_mode();
7779
resolver::graph::GraphResolverImpl::new(files_resolver)
7880
}
7981

crates/language-server/src/backend/db.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

crates/language-server/src/functionality/handlers.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ pub async fn handle_file_change(
255255
.db
256256
.workspace()
257257
.update(&mut backend.db, url.clone(), contents);
258+
259+
// If this is a .fe file, check if its ingot is loaded
260+
if path.extension().and_then(|s| s.to_str()) == Some("fe") {
261+
// Use init_ingot to find and load the ingot root
262+
// It will walk up from the file's directory to find fe.toml
263+
let diagnostics = init_ingot(&mut backend.db, &url);
264+
265+
// Log any diagnostics
266+
for diagnostic in diagnostics {
267+
warn!(
268+
"Ingot initialization diagnostic for file {:?}: {}",
269+
path, diagnostic
270+
);
271+
}
272+
}
258273
}
259274
}
260275
ChangeKind::Create => {

crates/language-server/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ async fn main() {
5959
async fn start_stdio_server() {
6060
let (server, client) = async_lsp::MainLoop::new_server(|client| {
6161
let tracing_layer = TracingLayer::default();
62-
let lsp_service = setup(client.clone(), "LSP actor".to_string());
62+
63+
let pid = std::process::id();
64+
let lsp_service = setup(client.clone(), format!("LSP actor {}", pid));
6365
ServiceBuilder::new()
6466
.layer(LifecycleLayer::default())
6567
.layer(CatchUnwindLayer::default())
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[ingot]
2+
name = "ingot_a"
3+
version = "0.1.0"

0 commit comments

Comments
 (0)