Skip to content

Commit 4848dc3

Browse files
author
Grant Wuerker
committed
ingot init fixes
1 parent 9d9a9d0 commit 4848dc3

File tree

15 files changed

+232
-41
lines changed

15 files changed

+232
-41
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: 2 additions & 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
@@ -49,6 +50,7 @@ macro_rules! impl_db_default {
4950
$db_type: $crate::core::HasBuiltinCore,
5051
{
5152
fn default() -> Self {
53+
$crate::tracing::info!("Initializing database");
5254
let mut db = Self {
5355
storage: salsa::Storage::default(),
5456
index: None,

crates/driver/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub fn ingot_graph_resolver<'a>() -> IngotGraphResolver<'a> {
3737

3838
pub fn init_ingot(db: &mut DriverDataBase, ingot_url: &Url) -> Vec<IngotInitDiagnostics> {
3939
tracing::info!(target: "resolver", "Starting workspace ingot resolution for: {}", ingot_url);
40+
41+
// Log the dependency graph URLs for debugging (before resolution)
42+
let urls = db.graph().all_urls(db);
43+
let urls_display: Vec<_> = urls.iter().map(|url| url.to_string()).collect();
44+
tracing::info!(target: "resolver", "Dependency graph URL set (before resolution): {}", urls_display.join(", "));
45+
4046
let mut diagnostics: Vec<IngotInitDiagnostics> = {
4147
let mut handler = InputHandler::from_db(db, ingot_url.clone());
4248
let mut ingot_graph_resolver = ingot_graph_resolver();
@@ -75,6 +81,11 @@ pub fn init_ingot(db: &mut DriverDataBase, ingot_url: &Url) -> Vec<IngotInitDiag
7581
all_diagnostics
7682
};
7783

84+
// Log the dependency graph URLs for debugging (after resolution)
85+
let urls = db.graph().all_urls(db);
86+
let urls_display: Vec<_> = urls.iter().map(|url| url.to_string()).collect();
87+
tracing::info!(target: "resolver", "Dependency graph URL set (after resolution): {}", urls_display.join(", "));
88+
7889
// Check for cycles after graph resolution (now that handler is dropped)
7990
let cyclic_subgraph = db.graph().cyclic_subgraph(db);
8091

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

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ impl Backend {
1212
pub fn new(client: ClientSocket) -> Self {
1313
let db = DriverDataBase::default();
1414

15+
tracing::info!("Initializing backend");
16+
1517
let workers = tokio::runtime::Builder::new_multi_thread()
1618
.worker_threads(1)
1719
.enable_all()

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ async fn discover_and_load_ingots(
5555
backend: &mut Backend,
5656
root_path: &std::path::Path,
5757
) -> Result<(), ResponseError> {
58+
info!(target: "resolver", "workspace content {}", backend.db.workspace().all_files(&backend.db).len());
59+
5860
// Find all fe.toml files in the workspace
5961
let pattern = format!("{}/**/fe.toml", root_path.to_string_lossy());
6062
let config_paths = glob::glob(&pattern)
@@ -103,6 +105,8 @@ async fn discover_and_load_ingots(
103105
}
104106
}
105107

108+
info!(target: "resolver", "workspace content 2 {}", backend.db.workspace().all_files(&backend.db).len());
109+
106110
Ok(())
107111
}
108112

@@ -255,6 +259,27 @@ pub async fn handle_file_change(
255259
.db
256260
.workspace()
257261
.update(&mut backend.db, url.clone(), contents);
262+
263+
// If this is a .fe file, check if its ingot is loaded
264+
if path.extension().and_then(|s| s.to_str()) == Some("fe") {
265+
// Walk up to find fe.toml
266+
let mut current = path.parent();
267+
while let Some(dir) = current {
268+
let fe_toml = dir.join("fe.toml");
269+
if fe_toml.exists() {
270+
// Found ingot root, check if it's loaded
271+
if let Ok(ingot_url) = Url::from_directory_path(dir) {
272+
let loaded_ingots = backend.db.graph().all_urls(&backend.db);
273+
if !loaded_ingots.contains(&ingot_url) {
274+
info!("Ingot not loaded, initializing: {:?}", dir);
275+
load_ingot_files(backend, dir).await?;
276+
}
277+
}
278+
break;
279+
}
280+
current = dir.parent();
281+
}
282+
}
258283
}
259284
}
260285
ChangeKind::Create => {

crates/language-server/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use async_lsp::client_monitor::ClientProcessMonitorLayer;
3333
use std::sync::Arc;
3434
use std::sync::atomic::{AtomicUsize, Ordering};
3535
use tower::ServiceBuilder;
36+
use tracing_subscriber::fmt::time;
3637

3738
#[tokio::main]
3839
async fn main() {
@@ -59,7 +60,9 @@ async fn main() {
5960
async fn start_stdio_server() {
6061
let (server, client) = async_lsp::MainLoop::new_server(|client| {
6162
let tracing_layer = TracingLayer::default();
62-
let lsp_service = setup(client.clone(), "LSP actor".to_string());
63+
64+
let pid = std::process::id();
65+
let lsp_service = setup(client.clone(), format!("LSP actor {}", pid));
6366
ServiceBuilder::new()
6467
.layer(LifecycleLayer::default())
6568
.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"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn a() -> u256 { 1 }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[ingot]
2+
name = "ingot_b"
3+
version = "0.1.0"
4+
5+
[dependencies]
6+
ingot_a = { path = "../ingot_a" }

0 commit comments

Comments
 (0)