Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7289f0f
The code extra installs tree-sitter-ruby and the parse child loads it
VanshajPoonia Dec 4, 2026
71a5334
A lane can cut its chunks on one symbol kind
VanshajPoonia Dec 4, 2026
f457c00
Ruby files are indexed with symbols, calls and inheritance
VanshajPoonia Dec 4, 2026
16ca9ce
The code index docs list Ruby among the parsed languages
VanshajPoonia Dec 4, 2026
71d4660
A bare word in a pattern guard, a rescue list or a superclass is a ca…
VanshajPoonia Dec 4, 2026
6df1f9b
A method defined on an instance is not indexed as a method of its class
VanshajPoonia Dec 4, 2026
5a85650
A method that starts on the last line of another is its own chunk
VanshajPoonia Dec 4, 2026
4f17b0b
The SQL of a root Ruby file is scoped like its methods
VanshajPoonia Dec 4, 2026
896b0b3
The Ruby lane's doc comment cut is marked as no setting
VanshajPoonia Dec 4, 2026
b64b8d2
The overview lists Ruby beside Lua so the translated table keeps its …
VanshajPoonia Dec 4, 2026
7316e3a
A root Ruby file's tables keep their dialect when an island narrows b…
VanshajPoonia Dec 4, 2026
0c56bb5
A class built by Struct.new or Class.new holds the methods of its block
VanshajPoonia Dec 4, 2026
8c9db68
The dialect narrowing test passes its fake repository as Any, as the …
VanshajPoonia Dec 4, 2026
8fc9b0d
A call inside SQL that creates a table or function binds from its method
VanshajPoonia Dec 4, 2026
3acdaa5
A class named like its base in another file inherits from it
VanshajPoonia Dec 4, 2026
db30bc9
An eval without a receiver defines on what self is, not where a def w…
VanshajPoonia Dec 4, 2026
0e06e7c
A built class keeps its name through ::Struct, a chained call and ||=
VanshajPoonia Dec 4, 2026
8a1948e
A multiple assignment reads the receiver of an attribute or element t…
VanshajPoonia Dec 4, 2026
6d3a248
Each heredoc of a call is a statement on its own lines
VanshajPoonia Dec 4, 2026
57650b3
Two docstrings of the lane keep to three lines
VanshajPoonia Dec 4, 2026
5bcbfb7
A SQL function outside a method is no chunk of its own
VanshajPoonia Dec 4, 2026
4005bb2
A built class names nothing when a call after its block returns somet…
VanshajPoonia Dec 4, 2026
7aadd3d
The chunk coverage test says what holds, not what Ruby files were
VanshajPoonia Dec 4, 2026
84b7446
The heredoc line helper returns an int the mypy gate can check
VanshajPoonia Dec 4, 2026
9eabff7
Merge main into the Ruby code lane
VanshajPoonia Dec 5, 2026
a224e58
A relative constant names the class its enclosing namespace holds
VanshajPoonia Dec 5, 2026
cb99cf4
A qualified constant the file never defines is read as written
VanshajPoonia Dec 5, 2026
21c6f2a
Merge main into the Ruby code lane
VanshajPoonia Dec 6, 2026
122bf43
A block, lambda or rescue clause keeps its own local variables
VanshajPoonia Dec 6, 2026
8ae3e9d
New in a singleton definition constructs the constant it is defined on
VanshajPoonia Dec 6, 2026
3a3ed66
A rescue variable stays a local after its clause
VanshajPoonia Dec 6, 2026
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: 3 additions & 3 deletions docs/architecture/code-index-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ Tree-sitter modules import lazily, so a server with the code workers off boots w

Python search responses omit a prefixed class docstring when the skeleton already contains its text.

Files without a tree fall back to whole-line windows; lanes without a grammar cut on
their symbol spans (`lane_units.span_chunks`). A chunk id is
Files without a tree fall back to whole-line windows; lanes without a grammar, and Ruby,
cut on their symbol spans (`lane_units.span_chunks`, one chunk per method for Ruby). A chunk id is
`uuid5("loom://code/{namespace}/{path}#{scope}@{sha16}")`. It is content-addressed, so
an unchanged chunk keeps its id and hash and the embed step skips it without a lookup.
Identical chunks in one file get an ordinal suffix.
Expand Down Expand Up @@ -999,7 +999,7 @@ reach for a changed class or module-level chunk (see Cost).
INI), a document (Markdown, reStructuredText, MDX, HTML), a style sheet, a Prisma
schema, a FlatBuffers schema, an Angular component template, a file of Terraform
values (`.tfvars`), a file with no extension, and a language with no parser (Kotlin,
Swift, C#, Ruby, PHP). A unit of such a file has no function of its own file to
Swift, C#, PHP). A unit of such a file has no function of its own file to
follow, so it stays where the table scores it, among the functions. A namespace
whose main language has no parser is therefore ranked as for a shorter question. A
CMake file is among them as a config file, although its functions and macros are
Expand Down
10 changes: 6 additions & 4 deletions docs/development/adding-language-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add a new language where it moves no stamp:
| `server/code/domain/extract/lang_<lang>.py` | no | The lane: `parse_<lang>(path, source) -> ParsedFile` with symbols, includes and call sites. |
| `server/code/domain/extract/lang_detect.py` | no | `LANG_BY_EXTENSION` (and the shell rules): which files are this language. |
| `server/code/app/index/ingest_parse.py` | no | A `_parse_<lang>` wrapper in `_PARSERS`; include resolution in `ingest_resolve.py` if the lane has imports. |
| `server/code/domain/extract/lane_units.py` | no | Shared helpers for a lane **without** a grammar: `span_chunks` and the `bind_sites` reference binder. |
| `server/code/domain/extract/lane_units.py` | no | Shared helpers for the `LANE_UNIT_LANGS` lanes: `span_chunks` and the `bind_sites` reference binder. |
| `server/code/domain/extract/treesitter.py` | **yes** | `lang_for_path` for the stamped core languages only. Adding an extension here re-chunks every namespace. |
| `chunker.py`, `edges_treesitter.py`, the other `STAGE_MODULES` | **yes** | Shared chunking and edge extraction. Change them only when the extraction itself changes for everyone. |

Expand All @@ -35,21 +35,23 @@ Every module under `server/code/domain/extract/` is either in a stage of `STAGE_

| Shape | Examples | You provide |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Grammar lane | `lang_typescript.py`, `lang_rust.py`, `lang_go.py`, `lang_java.py` | A tree-sitter grammar dependency in `pyproject.toml`; symbols and call sites from the tree; chunks and edges come from the shared chunker and edge walker. |
| Grammar lane | `lang_typescript.py`, `lang_rust.py`, `lang_go.py`, `lang_java.py`, `lang_ruby.py` | A tree-sitter grammar dependency in `pyproject.toml`; symbols and sites from the tree; chunks and edges from the shared chunker and edge walker, or `lane_units` (below). |
| Tree-less lane | `lang_proto.py`, `lang_thrift.py`, `lang_gotemplate.py`, `lang_hcl.py`, `lang_k8s.py`, `lang_jsonnet.py`, `lang_lua.py`, `lang_graphql.py` (`LANE_UNIT_LANGS`) | A hand-written scanner; `ParsedFile.tree` stays `None`; chunks from `lane_units.span_chunks`, edges from `reference_sites` + `SITE_RULES` bound by `lane_units.bind_sites`. |
| Include-only lane | `tla`, `flatbuffers`, `cmake`, `doc` (`_LANE_INCLUDE_LANGS`) | Symbols and includes resolved by the simple lane resolver. |
| Embedded language | SQL inside Go and Java (`go_sql_units`, `java_sql_units`), shell islands in Dockerfiles and Makefiles | Units joined into the host file's parse (`_join_island_symbols`), usually behind a kill switch setting. |
| Embedded language | SQL inside Go, Java and Ruby (`go_sql_units`, `java_sql_units`, `ruby_sql_units`), shell islands in Dockerfiles and Makefiles | Units joined into the host file's parse (`_join_island_symbols`), usually behind a kill switch setting. |
| Chunk-only | `.css`, text files (`lang_text.py`) | Nothing but detection: the file is chunked and searchable with no symbols. |

A grammar lane's grammar is **not** in `STAMPED_GRAMMARS`, so upgrading it moves no stamp. The lane owns re-deriving its rows.

The shared chunker and edge walker are in the stamp and know only the stamped languages and the ones already in their tables. A new grammar lane keeps its tree but takes its chunks from `lane_units.span_chunks` and its call and inherits edges from `reference_sites` bound by `lane_units.bind_sites`, as a tree-less lane does. `lang_ruby.py` is the model: add the language to `LANE_UNIT_LANGS` and give the module `CHUNK_OPTIONS`, `SITE_RULES`, `reference_sites`, and `wanted_paths` and `resolve_imports` when it has imports.

## 2. Write the parser

`parse_<lang>(path: str, source: bytes) -> ParsedFile` returns the language tag, the symbols (`treesitter.Symbol`: qualified name, kind, span, signature), the includes and what the edge stage needs. Follow the nearest existing lane:

- **Qualified names** follow the language's module path (Rust: the crate path from the file path; `mod.rs` / `lib.rs` name their directory). A symbol id hashes the qualified name and normalized signature, so an unstable name churns rows on every re-index.
- **Includes** resolve against the paths the namespace holds (`wanted_paths`, then `resolve_imports` / `resolve_uses` in the lane, called from `ingest_resolve.py`). External packages resolve to nothing, not to a guess.
- **Call edges** bind same-file-unique names first, then repository-unique ones at lower confidence, and nothing when a name is ambiguous (`lane_units.bind_sites` does this for tree-less lanes).
- **Call edges** bind same-file-unique names first, then repository-unique ones at lower confidence, and nothing when a name is ambiguous (`lane_units.bind_sites` does this for the `LANE_UNIT_LANGS` lanes).
- **Container kinds** (a class, an impl block) belong in the lane. Registering one in the chunker's per-language table changes `chunker.py` and moves the stamp.

Register the lane:
Expand Down
1 change: 1 addition & 0 deletions docs/features/code-index/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ still gets file-level impact.
| Terraform / HCL (`.tf`, `.tfvars`, `.hcl`), Kubernetes manifests | yes | references (`reads`) | — |
| Jsonnet (`.jsonnet`, `.libsonnet`) | yes | calls, imports | — |
| Lua (`.lua`) | yes | calls, `require` includes | — |
| Ruby (`.rb`, `.rake`, `.gemspec`, `Gemfile`, `Rakefile`) | yes | calls, `require` includes, inherits (superclasses, mixins); SQL islands | — |
| GraphQL schemas (`.graphql`, `.gql`) | yes | type uses, inherits (`implements`) | — |
| TLA+ (`.tla`, TLC configs), CMake (`CMakeLists.txt`, `.cmake`) | yes | includes; TLA+ operators; the CMake link graph | — |
| Markdown and docs (`.md`, `.mdc`, `.mdx`, `.rst`, `.html`, `.htm`) | sections (`.md` only) | relative links, backticked names as `reads` to the code | — |
Expand Down
3 changes: 2 additions & 1 deletion docs/features/integrations/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ JavaScript, Go, Rust and Java source a unit is a place when it is a definition (
function or method, a class, a named symbol); the file's leading comments and imports
and its module-level code are not, and neither is any unit of a source file the index
could not parse. A unit of any other file is a place: a notebook, a component file, SQL,
shell, configuration, and source the index reads as text (Kotlin, Ruby, PHP, C#, Swift).
shell, configuration, and source in a language that rule does not name (Kotlin, Ruby,
PHP, C#, Swift).
A document is a place when the request asks for documentation or the prompt names the
file: `.md`, `.mdx`, `.markdown`, `.rst`, `.adoc`, a change log, release notes or a
README by its name (`CHANGES`, `HISTORY` and `NEWS` as written, `changelog`,
Expand Down
4 changes: 2 additions & 2 deletions integrations/claude-code-plugin/hooks/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ in.
symbol); the file's leading comments and imports and its module-level code
are not, and neither is any unit of a source file the index could not parse.
A unit of any other file is a place: a notebook, a component file, SQL,
shell, configuration, and source the index reads as text (Kotlin, Ruby, PHP,
C#, Swift). A document is a place when the request asks for documentation
shell, configuration, and source in a language not named above (Kotlin, Ruby,
PHP, C#, Swift). A document is a place when the request asks for documentation
or the prompt names the file: `.md`, `.mdx`, `.markdown`, `.rst`, `.adoc`,
a change log, release notes or a README by its name (`CHANGES`, `HISTORY`
and `NEWS` as written, `changelog`, `release notes` and `readme` in any
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ code = [
"tree-sitter-typescript>=0.23",
"tree-sitter-javascript>=0.23",
"tree-sitter-rust>=0.23",
# Go and Java (lane parsers + SQL islands)
# Go, Java and Ruby (lane parsers + SQL islands)
"tree-sitter-go>=0.23",
"tree-sitter-java>=0.23",
"tree-sitter-ruby>=0.23",
"numpy>=1.26",
]
# scripts/scip_harness only (protobuf parse of scip-clang output). Never a
Expand Down
6 changes: 3 additions & 3 deletions server/code/app/index/ingest_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def _chunks_for(

text = source.decode("utf-8", "replace")
return prisma_chunks(pf), {}, list(prisma_units(path, text).facets)
if pf.lang in LANE_UNIT_LANGS:
# No tree — the lane's own symbol spans cut the chunks (one per message /
# service / define / manifest document)
if pf.lang in LANE_UNIT_LANGS and not parse_error:
# The lane's own symbol spans cut the chunks (a message, a define, a Ruby method);
# a file whose parse failed is line windows
from server.code.domain.extract.lane_units import span_chunks

lane = _lane_module(pf.lang)
Expand Down
63 changes: 35 additions & 28 deletions server/code/app/index/ingest_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,18 +896,20 @@ async def _text(path: str) -> str:


async def _lane_site_edges(repo: CodeRepo, org: str, ns: str, pf: ParsedFile) -> list[Any]:
"""The reference sites of a tree-less lane (an rpc's request type, a template's
`include "x"`) bound by `lane_units.bind_sites` over the lane's gated name table —
same-file unique at 1.0, repository-unique at 0.6, nothing when ambiguous."""
"""A `LANE_UNIT_LANGS` lane's reference sites (an rpc's request type, a Ruby call)
bound by `lane_units.bind_sites` over the lane's gated name table — same-file unique
at 1.0, repository-unique at 0.6, nothing when ambiguous."""
from server.code.domain.extract.lane_units import bind_sites

lane = _lane_module(pf.lang)
sites = lane.reference_sites(pf)
if not sites:
return []
names = sorted({n for _l, n, _k in sites})
table = gate_name_table(await repo.name_candidates(org, ns, names), pf.lang)
return bind_sites(pf, sites, table, lane.SITE_RULES)
rules = lane.SITE_RULES
# a site that binds only inside its file needs no repository-wide candidates
names = sorted({n for _l, n, k in sites if k in rules and rules[k].allow_repo_wide})
table = gate_name_table(await repo.name_candidates(org, ns, names), pf.lang) if names else {}
return bind_sites(pf, sites, table, rules)


async def _ts_island_edges(repo: CodeRepo, org: str, ns: str, pf: ParsedFile) -> list[Any]:
Expand Down Expand Up @@ -939,23 +941,24 @@ async def _scope_dialects_for(
ns: str,
table: dict[str, list[tuple[str, str, str]]],
) -> dict[str, str]:
"""{module scope: dialect} for the defining files of every name the table holds MORE
than one definition of — the file-level `dialect` facet that `narrow_by_dialect`
reads. One id → path read, then one facet read per path; a file whose tables are all
unambiguous pays nothing."""
from server.code.domain.extract.lang_python import module_scope

ambiguous_ids = [c[0] for cands in table.values() if len(cands) > 1 for c in cands]
if not ambiguous_ids:
"""{candidate's scope: its file's `dialect` facet} for every name the table holds MORE
than one definition of, as `narrow_by_dialect` reads it. One id → path read, then one
facet read per path; a file whose tables are all unambiguous pays nothing."""
ambiguous = [c for cands in table.values() if len(cands) > 1 for c in cands][:200]
if not ambiguous:
return {}
paths = await repo.symbol_paths_for_ids(org, ns, ambiguous_ids[:200])
out: dict[str, str] = {}
paths = await repo.symbol_paths_for_ids(org, ns, [c[0] for c in ambiguous])
by_path: dict[str, str] = {}
for path in sorted(set(paths.values())):
for f in await repo.live_facets_for_path(org, ns, path):
if str(f["facet_kind"]) == "dialect" and int(f["ordinal"]) == 0:
out[module_scope(path)] = str(f["name"])
by_path[path] = str(f["name"])
break
return out
return {
qn.split("::", 1)[0]: by_path[paths[sid]]
for sid, qn, _kind in ambiguous
if paths.get(sid) in by_path
}


async def _sql_object_edges(repo: CodeRepo, org: str, ns: str, pf: ParsedFile) -> list[Any]:
Expand All @@ -974,10 +977,11 @@ async def _sql_object_edges(repo: CodeRepo, org: str, ns: str, pf: ParsedFile) -
names |= col.names
table = await repo.name_candidates(org, ns, sorted(names)) if names else {}
gated = gate_name_table(table, SQL_LANG)
edges = sql_edges(pf.path, module_scope(pf.path), statements, pf.symbols, gated, rw_kinds=True)
mod = module_scope(pf.path)
edges = sql_edges(pf.path, mod, statements, pf.symbols, gated, rw_kinds=True)
if ju.dbt:
edges.extend(jinja_edges(pf.path, ju, gated, rw_kinds=True))
edges.extend(col.edges(pf, statements, gated))
edges.extend(col.edges(pf, mod, statements, gated))
return edges


Expand Down Expand Up @@ -1005,8 +1009,9 @@ def for_statements(cls, statements: list[Any]) -> _ColumnAsk:
hyps = column_hypotheses(statements, known)
return cls(known, hyps, hyps | column_names(statements, known))

def edges(self, pf: ParsedFile, statements: list[Any], gated: dict[str, Any]) -> list[Any]:
from server.code.domain.extract.lang_python import module_scope
def edges(
self, pf: ParsedFile, mod: str, statements: list[Any], gated: dict[str, Any]
) -> list[Any]:
from server.code.domain.extract.lang_sql_columns import (
column_edges,
known_from_name_table,
Expand All @@ -1018,7 +1023,7 @@ def edges(self, pf: ParsedFile, statements: list[Any], gated: dict[str, Any]) ->
known = merge_known(self.known, known_from_name_table(gated, self.hypotheses))
return column_edges(
pf.path,
module_scope(pf.path),
mod,
statements,
known,
pf.symbols,
Expand All @@ -1034,15 +1039,17 @@ async def _py_island_edges(repo: CodeRepo, org: str, ns: str, pf: ParsedFile) ->
from server.code.domain.extract.lang_python import module_scope
from server.code.domain.extract.lang_sql_objects import reference_names, sql_edges

statements = (
py_sql_units(pf).statements if pf.lang == "python" else _code_sql_units(pf).statements
)
if pf.lang == "python":
statements, mod = py_sql_units(pf).statements, module_scope(pf.path)
else:
units = _code_sql_units(pf)
statements, mod = units.statements, units.scope # the scope the parse named them by
if not statements:
return []
col = _ColumnAsk.for_statements(statements)
names = reference_names(statements) | col.names
table = await repo.name_candidates(org, ns, sorted(names)) if names else {}
gated = gate_name_table(table, SQL_LANG)
edges = sql_edges(pf.path, module_scope(pf.path), statements, pf.symbols, gated, rw_kinds=True)
edges.extend(col.edges(pf, statements, gated))
edges = sql_edges(pf.path, mod, statements, pf.symbols, gated, rw_kinds=True)
edges.extend(col.edges(pf, mod, statements, gated))
return edges
Loading
Loading