feat(map): code navigator on the repository and pull request pages
The Map tab shows a commit's TypeScript and JavaScript code as blocks inside blocks: folders, files, declarations and class members. Zoom goes from Architecture to Code, where the blocks show the code. Selecting a name in a code card adds its definition to a trace below the map, drawn as the refs line, so a reader follows a path through the code without jumping around it. On a pull request, the map marks each changed file and declaration with its added and removed lines. The Changes list and the ] and [ keys step through every change, and Diff only folds the unchanged lines in each card. refs builds the map of a commit on push, for the default branch and the branches of open pull requests, and on first view of any other commit. Migration 0032 stores one gzipped map per commit.
6 decisions
Index TypeScript and JavaScript with a small lexical outliner that runs in the Worker.
Why
- The repository uses TypeScript 7, which has no JavaScript compiler API.
- The TypeScript 5 compiler is too large and too slow for a Worker request or queue message.
- The outliner indexes this repository (167 files, 1290 symbols) in about 4 seconds, including the reads from Artifacts.
Paths considered
- Chosen
- typescript-compiler-apiIt does not fit the Worker size and memory limits.
- tree-sitter-wasmIt adds a WebAssembly build and a grammar per language for names the outliner already finds.
Assumes
- Uses through `ns.member` and method calls on objects of unknown type are not linked. Readers accept that for now.
Touches
lexer.tsoutline.tsgraph.ts
Store one gzipped code map per commit in D1, and serve it from a route keyed by commit with an immutable cache.
Why
- A commit never changes, so its map never changes and the browser can keep it for good.
- The page loader then sends only the map's state, which cut the page from 987 KB to 15 KB.
Paths considered
- Chosen
- per-symbol-rowsThousands of rows per commit for data that is always read whole.
- map-in-loaderIt made every visit download and decode the whole map with the page.
Assumes
- A map over 1.9 MB gzipped is stored as too large. No current repository is near that.
Touches
0032_code_maps.sqlstore.tsrepo-code-graph.tsrepo-code-file.ts
Build a commit's map on push for the default branch and open pull request branches, and on first view for any other commit.
Why
- Maps for the pages people open most are ready before anyone opens them.
- A claim row makes each commit build once, even when a push and a view race.
Paths considered
- Chosen
- every-pushed-branchTask branches without a pull request are rarely mapped and would cost a build per push.
Touches
code-maps.tspushes.ts
Lay out each block's children as a storyline, callers left and the code they use right, wrapping into rows when a block gets much wider than it is tall.
Why
- The order of reading follows the order of calls, as in a story.
- Without wrapping, the map of this repository was a thin band that used a third of the screen.
Touches
layout.ts
Draw folder and file names and change counts in screen space, and leave out a label that would cover another one.
Why
- Names scaled with the map were unreadable when zoomed out and overlapped each other.
- Labels hide while the map moves and come back when it rests, so a zoom moves one layer only.
Touches
map-view.tsxapp.css
Give the Map pages the full width and the full height of the window.
Why
- The owner asked for the map to take the full page.
- A canvas gains nothing from the 1080 px reading column.
Touches
shell.tsxrepo.tsxfill.ts