Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / function

_resolve_path_import

codeintel.graph._resolve_path_import

PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.

PHAROS at 975a38dMIT license

Around this symbol

Search all symbols

Loading

Called by (1)
SymbolFileResolved by
build_edgesgraph.pysame file
Inside (1)
SymbolFileResolved by
graphgraph.pysame file
codeintel.graph._resolve_path_importbackend/app/codeintel/graph.py, lines 102–141Open source
def _resolve_path_import(src_path: str, spec: str, language: str, files: dict[str, ChunkNode],                         by_basename: dict[str, list[ChunkNode]]) -> list[ChunkNode]:    """Resolve JS/TS/C/C++/Go/Rust/Java import specs to module chunks in the repo."""    src_dir = posixpath.dirname(src_path)    if language in ("javascript", "typescript"):        if not spec.startswith("."):            return []  # package import, not a repo file        base = posixpath.normpath(posixpath.join(src_dir, spec))        candidates = [base] + [base + ext for ext in _JS_EXTS] + [f"{base}/index{ext}" for ext in _JS_EXTS]        # ESM TypeScript imports name the compiled file: './x.js' means x.ts.        stem, ext = posixpath.splitext(base)        candidates += [stem + ts for ts in _TS_FOR_JS.get(ext, ())]        for cand in candidates:            if cand in files:                return [files[cand]]        return []    if language in ("c", "cpp"):        local = posixpath.normpath(posixpath.join(src_dir, spec))        if local in files:            return [files[local]]        matches = [m for m in by_basename.get(posixpath.basename(spec), []) if m.path.endswith(spec)]        return matches if len(matches) == 1 else []    if language == "go":        # Import paths name directories; match files in a directory whose        # path is a suffix of the import path.        hits = [m for m in files.values() if m.language == "go" and spec.endswith(posixpath.dirname(m.path) or "\0")]        return hits[:10]    if language == "rust":        segs = [s for s in spec.replace("{", " ").split("::") if s and s not in ("crate", "self", "super")]        for end in range(len(segs), 0, -1):            stem = "/".join(segs[:end])            for cand in (f"src/{stem}.rs", f"src/{stem}/mod.rs", f"{stem}.rs"):                if cand in files:                    return [files[cand]]        return []    if language == "java":        suffix = spec.replace(".", "/") + ".java"        matches = [m for p, m in files.items() if p.endswith(suffix)]        return matches if len(matches) == 1 else []    return []

What the index recorded

Signature
def _resolve_path_import(src_path: str, spec: str, language: str, files: dict[str, ChunkNode], by_basename: dict[str, list[ChunkNode]]) -> list[ChunkNode]:
File
backend/app/codeintel/graph.py
Lines
102–141
Parser
python-ast
Git blob
3791a0283d18722675047af567570cb2c1911c63
Call sites
14 named, 0 resolved, 14 left unlinked

Read it on GitHub at this commit