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 symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| ParseResult | base.py | through an import |
| Symbol | base.py | through an import |
| add_call | base.py | unique name |
| add_identifier | base.py | unique name |
| _end_line | treesitter_parser.py | same file |
| _file_comment | treesitter_parser.py | same file |
| _get_parser | treesitter_parser.py | same file |
| _go_receiver_type | treesitter_parser.py | same file |
| _leading_comment | treesitter_parser.py | same file |
| _rust_impl_type | treesitter_parser.py | same file |
| _signature | treesitter_parser.py | same file |
| _text | treesitter_parser.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| parse_file | __init__.py | through an import |
| Symbol | File | Resolved by |
|---|---|---|
| treesitter_parser | treesitter_parser.py | same 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
