Skip to content

The code index reads Lua files with a tree-less lane - #743

Merged
zlareb1 merged 3 commits into
ClickHouse:mainfrom
rahulsjha:feat/lua-lane
Nov 18, 2026
Merged

zlareb1 merged 3 commits into
ClickHouse:mainfrom
rahulsjha:feat/lua-lane

Conversation

@rahulsjha

Copy link
Copy Markdown
Contributor

Closes: #625

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The code index reads Lua files: functions become symbols, f(…) and a.b(…) calls become call edges, and require("a.b") becomes an include of the repository's a/b.lua or a/b/init.lua.

Why

.lua was in _CODE_TEXT_EXTENSIONS, so Lua files were chunked and searchable but code.symbol, code.callers and code.outline knew nothing in them.

Scope and risk

A tree-less lane, following docs/development/adding-language-support.md and shaped like lang_proto.py / lang_jsonnet.py:

  • server/code/domain/extract/lang_lua.py: parse_lua(path, source) -> ParsedFile, reference_sites, SITE_RULES, CHUNK_OPTIONS, wanted_paths / resolve_imports.
    • Symbols: function a.b(), function a:b(), function f(), local function f(), M.f = function() and local f = function() → function symbols named by the last part and qualified by the module path (<mod>::a.b; a method's : reads as ., the signature keeps it). A span runs to the end that closes the function: blocks open at function, if, do (which for / while use) and repeat, and close at end / until. Strings, long brackets ([[…]], [==[…]==]) and comments (--, --[[…]]) are skipped, so a keyword inside them moves nothing.
    • Call sites: f(…) and a.b(…) → call sites on the bare name, bound by lane_units.bind_sites (same file 1.0, repository-unique 0.6, ambiguous → nothing). Lua's base functions (print, ipairs, setmetatable, …) and standard libraries (string.*, table.*, math.*, …) name nothing; obj:m() is not a site, the receiver's type being unknown.
    • Includes: require("a.b") / require "a.b" → a/b.lua or a/b/init.lua under the file's directory and its nearest ancestors (lane_units.ancestor_dirs), then the root, settled against the namespace's live paths; a module the repository does not hold (a rock, a C module) resolves to nothing; a .. or absolute path names nothing.
  • Registration: ".lua": "lua" in LANG_BY_EXTENSION, removed from _CODE_TEXT_EXTENSIONS; _parse_lua in _PARSERS, lua in LANE_UNIT_LANGS and _lane_module; "lua": SCRIPT in name_scope.
  • Extractor stamp: lang_lua.py is listed in NON_EXTRACTOR_MODULES and no stamped module changes, so existing deployments re-chunk nothing. A namespace that already indexed Lua as text gains the rows with loom code backfill --paths-file of its .lua files.
  • Cost: each regex is bounded (unclosed strings / long brackets run to the end once, as Lua's lexer reads them), and a parameter list stops at the first token that can't be a parameter, so an unclosed header costs its own length.

Compatibility, rollout and rollback

  • Wire: none (new rows for .lua files only).
  • Operator steps: none required; a backfill of .lua files gives an already-indexed namespace its Lua symbols and edges.
  • Rollback: reverting returns .lua to plain text; the Lua rows written meanwhile stay until the files are re-indexed.

Tests

  • tests/unit/test_code_lang_lua.py (15 tests): symbols, spans and signatures; a method, long comment, string holding end function ( and nested if / repeat … until; builtins / library / method calls are not sites; binding same file first then repository-unique; a name defined twice binds to nothing; require candidates (nearest first, init.lua, a slash path, a .. escape); detection (.lua is no longer text); chunks; and 7 linear-time cases (assert_linear) over pathological inputs (unclosed headers, long brackets, if runs, require(").
  • tests/fixtures/code_lanes/lua/ (synthetic, listed in NOTICE.md): a vector module and a menu scene that requires it. LANES in tests/code_lanes/corpus.py gains lua/, and the corpus resolves its includes and binds its sites like proto's. expected.json regenerated with python -m tests.code_lanes.corpus --write; its diff is only the two Lua files (menu.lua includes lua/game/lib/vec.lua; 5 call edges; 445 → 451 edges).
  • SAMPLES in tests/unit/lane_walks.py gains lua for test_code_regex_cost.py.

Run in Linux (python:3.12, uv sync --frozen --all-extras, as CI):

pytest tests/unit/test_code_lang_lua.py tests/unit/test_code_extractor_stamp.py tests/unit/test_code_lanes_corpus.py
       test_code_regex_cost.py::test_every_registered_lane_has_a_sample_that_reads_as_it -k "lua or stamp or corpus or ..."   41 passed
pytest tests/unit/test_code_regex_cost.py, main and this branch back to back in one container:
  main:   4 failed, 764 passed (rerun: 7 failed, a different set: python-import-statements, proto, gotemplate, cpp-deep-includes, vue-sites, …)
  branch: 2 failed, 769 passed (rerun: 1 failed, cpp-deep-includes, which also fails on main) — every lua case passes;
  the failures are timing flakes on this machine (Docker on a laptop), none in a lua case
ruff format --check / ruff check                                                                                            clean

the lane on a sample module: symbols with spans, init.lua resolution, and the sites (no builtins, nothing from the comment or the string).

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I read every registration point against the adding-language-support guide, checked the parser on a sample module, ran the lane, corpus, stamp and cost tests in Linux and reviewed the regenerated expected.json.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (ruff format and check, and the lane / corpus / stamp / cost tests above were run; the full make test-unit was not)
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py). (expected.json regenerated; no other generated file changes)
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (n/a)
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version. (n/a)
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed. (n/a)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes. (code-index overview language table; adding-language-support lane list)
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

`.lua` files were chunked as plain text, so code.symbol, code.callers and code.outline knew nothing in them. A tree-less lane (no new tree-sitter dependency), in the shape of lang_proto.py, now reads them:

- `function a.b()`, `function a:b()`, `function f()`, `local function f()`, `M.f = function()` and `local f = function()` are `function` symbols qualified by the module path (`<mod>::a.b`), spanning to the `end` that closes them;
- `f(...)` and `a.b(...)` are call sites bound by lane_units.bind_sites (same file 1.0, repository-unique 0.6); Lua's own functions, its standard libraries and method calls on an unknown receiver name nothing;
- `require("a.b")` is an include of `a/b.lua` or `a/b/init.lua` under the file's directory and its nearest ancestors, then the root; a module the repository does not hold resolves to nothing.

Strings, long brackets and comments are skipped, so a keyword inside them moves no block. The module is outside the extractor stamp (listed in NON_EXTRACTOR_MODULES), so existing deployments re-chunk nothing; a namespace gains its Lua rows by a backfill of its `.lua` files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rahul <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: request changes. The function-length gate fails on this head; the inline comment names the required split. The Lua and extractor-stamp tests pass locally. The corpus tests could not complete on this host because the bounded tree-sitter child process exits with status 1; CI must verify that surface.

Comment thread server/code/domain/extract/lang_lua.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A second required check fails on this head: the test inventory does not claim the Lua fixtures.

@zlareb1 zlareb1 self-assigned this Nov 17, 2026
@rahulsjha

Copy link
Copy Markdown
Contributor Author

Hi @zlareb1, this one is ready for review: the Lua lane for #625. The lane, corpus and stamp tests pass in Linux, the regenerated expected.json only adds the two Lua fixtures, and it stays outside the extractor stamp. Happy to adjust anything.

… an inventory workflow

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Rahul <[email protected]>
@rahulsjha

Copy link
Copy Markdown
Contributor Author

@zlareb1 thanks, both fixed in cba885c: lua_units now calls two helpers, _call_sites and _requires (the function-length gate is back at its baseline, 55/51, with no ratchet change), and lua is in _LANG_WORKFLOWS in tests/inventory/build.py (test_test_inventory.py 23 passed). test_code_lang_lua.py, ruff and mypy still pass.

@rahulsjha

Copy link
Copy Markdown
Contributor Author

The one failing check on the last run is test_a_file_of_many_units_parses_in_linear_time[if a then ], a timing test (0.10 s → 0.84 s for 4× the input). I measured the Lua lane on this branch, best of three each:

unit                                  4k      16k     64k     16k/4k  64k/16k
'if a then '                          0.036s  0.156s  0.622s  4.3x    4.0x
'function a.b(x) return c(x) end\n'   0.208s  0.861s  3.967s  4.1x    4.6x
'local function f(\n'                 0.112s  0.368s  1.524s  3.3x    4.1x
'--[[ '                               0.001s  0.003s  0.012s  3.8x    4.0x

That's linear up to 64k units, so I read the CI result as a slow runner rather than a regression. I've merged the latest main into the branch to get a fresh run.

@zlareb1

zlareb1 commented Nov 18, 2026

Copy link
Copy Markdown
Member

Hi @rahulsjha , you have made many contributions on the repo. Would you like to publish a blog about your changes or loom?

@rahulsjha

Copy link
Copy Markdown
Contributor Author

Sure, I will make a Loom video with my experience and details.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function-length and fixture-inventory findings are fixed. The 59 focused Lua, extractor-stamp and inventory tests pass, and the function-length gate passes without changing its baseline. No further findings in symbol spans, call binding or require resolution; CI is running.

@zlareb1 zlareb1 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged.

@zlareb1
zlareb1 merged commit 4853291 into ClickHouse:main Nov 18, 2026
49 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a tree-less Lua lane: the code index reads .lua files as text only

3 participants