From baca562c9c98ba2f9079a712325b48d10f7735c7 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Mon, 8 Jan 2024 17:53:35 +0900 Subject: [PATCH] feat(lsp): keep track of project file location Extend the `mabo-project` crate to additional store the location from wheret the project file was loaded. This is currently used to log the location in the LPS when loading a folder and searching for Mabo projects in it. --- crates/mabo-lsp/src/handlers/mod.rs | 6 +++++- crates/mabo-project/src/lib.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/mabo-lsp/src/handlers/mod.rs b/crates/mabo-lsp/src/handlers/mod.rs index 675fa97..7bea1fb 100644 --- a/crates/mabo-lsp/src/handlers/mod.rs +++ b/crates/mabo-lsp/src/handlers/mod.rs @@ -38,7 +38,11 @@ pub fn initialize( .root_uri .and_then(|root| mabo_project::discover(root.path()).ok()) { - for path in projects.into_iter().flat_map(|project| project.files) { + for path in projects + .into_iter() + .inspect(|project| debug!(path = as_debug!(project.project_path); "found project")) + .flat_map(|project| project.files) + { let Ok(text) = std::fs::read_to_string(&path) else { error!(path = as_debug!(path); "failed reading file content"); continue; diff --git a/crates/mabo-project/src/lib.rs b/crates/mabo-project/src/lib.rs index bf3c546..3964d6d 100644 --- a/crates/mabo-project/src/lib.rs +++ b/crates/mabo-project/src/lib.rs @@ -103,6 +103,8 @@ pub struct Package { pub struct Project { /// Parsed content of the `Mabo.toml` project file. pub project_file: ProjectFile, + /// Location of the `Mabo.toml` project file. + pub project_path: PathBuf, /// Resolved final list of files to process. pub files: Vec, } @@ -163,6 +165,7 @@ fn load_project(base: &Path, file: &Path) -> Result { Ok(Project { project_file, + project_path: file.to_owned(), files, }) }