Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions codegraph-kernel/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ pub struct KernelResolver {
ts_imported_type_memo: HashMap<(String, String), Option<String>>,
/// `(package, type)` → the project file declaring the package with that type in it.
ts_ambient_memo: HashMap<(String, String), Option<String>>,
/// `file` → its ambient/global scope scan (None when unreadable). The
/// scan parses the file and ambient-module lookup walks every `.d.ts`
/// once per import, so each file is scanned once and shared — upstream
/// memoizes the same way (TS_GLOBAL_SCOPES).
ts_scope_memo: HashMap<String, Option<Rc<ts_known::TsScopeScan>>>,
/// `(file, type as written)` → what the name names there.
ts_named_type_memo: HashMap<(String, String), ts_known::TsNamedType>,
/// Whether the project declares a `createInstance` returning an `InstanceType` of its constructor argument.
Expand Down Expand Up @@ -935,6 +940,7 @@ impl KernelResolver {
ts_field_reading: HashSet::new(),
ts_imported_type_memo: HashMap::new(),
ts_ambient_memo: HashMap::new(),
ts_scope_memo: HashMap::new(),
ts_named_type_memo: HashMap::new(),
ts_create_instance_declared: None,
python_bound_memo: HashMap::new(),
Expand Down
11 changes: 10 additions & 1 deletion codegraph-kernel/src/resolve/ts_known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,16 @@ pub(super) struct TsScopeScan {
}

impl KernelResolver {
pub(super) fn ts_scope_scan(&mut self, file: &str, r: &ResolveRefIn) -> Option<TsScopeScan> {
pub(super) fn ts_scope_scan(&mut self, file: &str, r: &ResolveRefIn) -> Option<Rc<TsScopeScan>> {
if let Some(memo) = self.ts_scope_memo.get(file) {
return memo.clone();
}
let scan = self.ts_scope_scan_uncached(file, r).map(Rc::new);
self.ts_scope_memo.insert(file.to_string(), scan.clone());
scan
}

fn ts_scope_scan_uncached(&mut self, file: &str, r: &ResolveRefIn) -> Option<TsScopeScan> {
let source = self.read_file(file)?;
let mut site = r.clone(); site.file_path = file.to_string(); site.language = "typescript".to_string();
let tree = self.js_binding_tree(&source, &site)?;
Expand Down