module
Noir::ImportGraph
Overview
Shared file-level import-graph traversal for cross-file route / DTO resolution.
Today the JVM-style flavour is implemented (Java, Kotlin): a file
belongs to a package whose dotted path is reflected in its
directory layout (src/main/java/com/foo/Bar.java ↔
package com.foo), and imports map to file paths under the
inferred source root. This is the pattern called out as
duplication in #1107 for TreeSitterJavaDtoIndex and
TreeSitterKotlinDtoIndex.
Caveats / non-goals:
- Python / Ruby / JS-style cross-file resolution doesn't share
this exact source-root inference. When those frameworks
migrate, expect a sibling helper (or a
mode:parameter) on this module rather than forcing them through this code path. - The traversal is one level deep — we yield the directly visible files, not files reachable through their imports. Recursive resolution is the caller's job (and usually unnecessary; one level covers the controller-→-DTO case).
Defined in:
miniparsers/import_graph.crConstant Summary
-
JS_RESOLVE_EXTENSIONS =
["ts", "tsx", "js", "jsx", "mjs", "cjs"]
Class Method Summary
-
.related_files(path : String, package_name : String, imports : Indexable(ImportRef), extension : String, &block : String -> ) : Nil
Yields every file path that should be considered when resolving symbols visible to
path: - .resolve_relative_import(from_file : String, import_specifier : String, extensions : Array(String) = JS_RESOLVE_EXTENSIONS, boundary : String | Nil = nil) : String | Nil
-
.source_root_for(file_path : String, package_name : String) : String | Nil
Infer the source root by stripping the package path from the file's directory.
Class Method Detail
Infer the source root by stripping the package path from the
file's directory. src/main/java/com/foo/Bar.java with package
com.foo returns src/main/java. Returns nil when the package
path doesn't actually trail the file's directory (the source
tree is laid out differently and we can't safely resolve
imports).