Skip to content

feat(review): definition search core (git grep on the side being reviewed) - #169

Merged
backnotprop merged 1 commit into
mainfrom
feat/codenav-core
Nov 20, 2026
Merged

backnotprop merged 1 commit into
mainfrom
feat/codenav-core

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Adds plannotator_tui_review::codenav, the search core for a later "go to definition" in the review screen. There are no keys or UI in this PR.

It ports the browser app's search-based code navigation (packages/shared/code-nav.ts):

  • Whole-word search for an identifier.
  • Definition patterns for TS/JS, Python, Go and Rust, then the generic patterns. Each match is a Definition or a Reference, plus the kind of symbol it defines.
  • Path exclusions: node_modules and the other tool-output names at any depth; vendor, target, build, dist and coverage only at the root. A directory the origin file is in is never excluded.
  • Ranking: same file +1000, else a changed file +500, else the same folder +200. A test file gets −300 unless the origin is a test file. A definition gets +100, and +50 more because definitions are "likely". Ties keep search order.
  • Caps: 50 matches per file, 500 matches read, 50 kept, 5 s for a jump and 3 s for a hover. Lines are cut to 200 characters.

One difference from the browser: it runs git grep -n -w -F against the side of the diff the person is looking at, not rg over the working tree:

  • a commit or tree: git grep <rev>. This also works in the bare cache repository a pull request review fetches into.
  • staged: git grep --cached
  • working tree: git grep --untracked. Like rg, this includes untracked files that are not ignored.

The API:

  • search(repo, &SideSource, &Query { file, line, word, changed }) returns Found { definitions, references, capped, complete, elapsed }. search_with takes its own time limit.
  • Found::best(&query) gives the jump target: the best definition that is not on the current line, else the best reference.
  • identifiers_on_line(line, language) and identifier_at(line, column, language) find the words on a line. They skip keywords, numbers, strings and comments, as far as a single-line lexer can.
  • changed_paths(&capture.files) lists the changed files, with both paths of a rename.
  • Language::from_path follows the browser's detectLanguage. The language's files are limited with pathspecs that match ripgrep 15.1's --type globs.

Where git grep cannot match rg, the module docs list the gap:

  • --max-filesize 1M has no git grep equivalent.
  • On a commit or staged side, a tracked file that .gitignore also matches is still searched.
  • -w treats only ASCII letters, digits and _ as word characters.
  • rg skips hidden files. This port does the same, except in the directories the origin file is in.

Tests:

  • The browser's code-nav.test.ts cases for classifyMatch (every language and the generic fallback), the classifyMatchDetailed table, rankLocations, the buildRgArgs exclusions (as pathspecs), isCodeNavPathAllowed, and the real-ripgrep vendor/node_modules cases ([Bug] Code navigation excludes Java packages containing vendor, causing empty References backnotprop/plannotator#1558), run through git grep on a real repo.
  • New cases: each language, the exact ranking weights, a working tree with untracked and ignored files, staged content versus disk, an old revision, a bare repository, whole-word matching, the caps, the time limit, and the identifier lexer.

Size: regex was already compiled only as a proc-macro dependency. regex-automata with meta and regex-syntax were already in the binary through diffs-rs. Release binary on macOS arm64:

  • before: 10,113,568 bytes; after: 10,113,552. Nothing calls the module yet, so it is stripped.
  • With a temporary call from main (not committed): 10,263,808, so +150 KB once the UI uses it. Of that, the regex crate is about 17 KB; the rest is the module itself.

…ewed

Port the browser app's search-based code navigation (packages/shared/code-nav.ts)
to plannotator-tui-review as codenav: whole-word search, the TS/JS, Python, Go
and Rust definition patterns with the generic fallback, the path exclusions and
the ranking and caps. It searches with git grep against the side of the diff on
screen (a commit, the index, or the working tree with untracked files), so it
works on old versions and on a pull request fetched into a bare cache repository.

No keys or UI yet.
@backnotprop
backnotprop added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit a3be4f8 Nov 20, 2026
3 checks passed
@backnotprop
backnotprop deleted the feat/codenav-core branch November 20, 2026 01:20
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.

1 participant