diff --git a/ast/src/builder/core.rs b/ast/src/builder/core.rs index d3ce23cc..27aba69e 100644 --- a/ast/src/builder/core.rs +++ b/ast/src/builder/core.rs @@ -14,6 +14,7 @@ use crate::lang::{ }; use crate::lang::{ArrayGraph, BTreeMapGraph}; use crate::repo::Repo; +use crate::lang::call_finder::{parse_imports_for_file, IMPORT_CACHE}; use git_url_parse::GitUrl; use lsp::{git::get_commit_hash, strip_tmp, Cmd as LspCmd, DidOpen}; @@ -635,6 +636,11 @@ impl Repo { &import.file, ); } + + // Populate import cache after adding Import nodes + if let Some(import_data) = parse_imports_for_file(filename, &self.lang, graph) { + IMPORT_CACHE.insert(filename.to_string(), Some(import_data)); + } } let mut stats = std::collections::HashMap::new(); diff --git a/ast/src/lang/call_finder.rs b/ast/src/lang/call_finder.rs index 2a67a841..66bed230 100644 --- a/ast/src/lang/call_finder.rs +++ b/ast/src/lang/call_finder.rs @@ -6,7 +6,7 @@ use std::sync::LazyLock; use tree_sitter::QueryCursor; type ImportCache = DashMap)>>>; -static IMPORT_CACHE: LazyLock = LazyLock::new(DashMap::new); +pub static IMPORT_CACHE: LazyLock = LazyLock::new(DashMap::new); pub fn clear_import_cache() { IMPORT_CACHE.clear(); @@ -115,7 +115,7 @@ pub fn get_imports_for_file( result } -fn parse_imports_for_file( +pub fn parse_imports_for_file( current_file: &str, lang: &Lang, graph: &G,