Back to the room

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

Code Observatory / function

parse_treesitter

codeintel.parsers.treesitter_parser.parse_treesitter

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

Calls (12)
SymbolFileResolved by
ParseResultbase.pythrough an import
Symbolbase.pythrough an import
add_callbase.pyunique name
add_identifierbase.pyunique name
_end_linetreesitter_parser.pysame file
_file_commenttreesitter_parser.pysame file
_get_parsertreesitter_parser.pysame file
_go_receiver_typetreesitter_parser.pysame file
_leading_commenttreesitter_parser.pysame file
_rust_impl_typetreesitter_parser.pysame file
_signaturetreesitter_parser.pysame file
_texttreesitter_parser.pysame file
Called by (1)
SymbolFileResolved by
parse_file__init__.pythrough an import
Inside (1)
SymbolFileResolved by
treesitter_parsertreesitter_parser.pysame file
codeintel.parsers.treesitter_parser.parse_treesitterbackend/app/codeintel/parsers/treesitter_parser.py, lines 403–462Open source
def parse_treesitter(path: str, source: str, language: str, grammar: str, module_path: str) -> ParseResult:    """Extract symbols. Raises ImportError when the grammar is unavailable."""    parser = _get_parser(grammar)    spec = LANGUAGES[grammar]    src = source.encode("utf-8", errors="replace")    tree = parser.parse(src)    root = tree.root_node    line_count = max(1, source.count("\n") + (0 if source.endswith("\n") else 1))    module = Symbol(        name=path.rsplit("/", 1)[-1],        qualified_name=module_path,        kind="module",        start_line=1,        end_line=line_count,        signature=f"file {path}",        docstring=_file_comment(root, src),    )    symbols: list[Symbol] = [module]    imports: list[str] = []    by_qualified: dict[str, Symbol] = {module.qualified_name: module}    # Iterative DFS. Each frame: (node, enclosing symbol, qualifier prefix).    stack: list[tuple[object, Symbol, str]] = [(root, module, module_path)]    while stack:        node, owner, prefix = stack.pop()        ntype = node.type        child_owner, child_prefix = owner, prefix        if ntype in spec.namespaces:            ns = spec.namespaces[ntype](node, src)            if ns:                child_prefix = f"{prefix}.{ns}" if prefix else ns        definition = spec.defs.get(ntype)        name = definition.name(node, src) if definition else None        if (            definition            and name            and definition.kind in ("function", "method")            and owner.kind in ("function", "method")        ):            # Nested functions / closures belong to the enclosing function's            # chunk (same rule as the Python extractor).            owner.add_identifier(name)            name = None        if definition and name:            kind = definition.kind            parent_qual = owner.qualified_name            qual_prefix = prefix            if grammar == "go" and ntype == "method_declaration":                receiver = _go_receiver_type(node, src)                if receiver:                    qual_prefix = f"{module_path}.{receiver}" if module_path else receiver                    parent_qual = qual_prefix            elif kind == "function" and owner.kind in ("class", "impl", "trait", "interface", "struct", "type"):                kind = "method"            if grammar == "go" and ntype == "type_spec":                type_node = node.child_by_field_name("type")                kind = {"struct_type": "struct", "interface_type": "interface"}.get(

Shows the first 60 of 115 lines. The rest is on GitHub at this commit.

What the index recorded

Signature
def parse_treesitter(path: str, source: str, language: str, grammar: str, module_path: str) -> ParseResult:
File
backend/app/codeintel/parsers/treesitter_parser.py
Lines
403–517
Parser
python-ast
Git blob
bf0c9a8044cadd3452ebf5ffa82b866ae00395a9
Call sites
29 named, 13 resolved, 16 left unlinked
Outside this subset
1 more edges reach code outside the graph shown here

Read it on GitHub at this commit