Skip to content

The name index reads a clean document's first edit from the document, not from disk - #204

Merged
ww-mw merged 5 commits into
mainfrom
fix/name-index-first-edit
Nov 2, 2026
Merged

ww-mw merged 5 commits into
mainfrom
fix/name-index-first-edit

Conversation

@ww-mw

@ww-mw ww-mw commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Includes #193 (merged in for their shared CHANGELOG heading). Merge #193 first, or this one alone brings both.

Once a search has built the window's name index, the first edit of a clean data source makes the index read that file from disk instead of the document's text.

VS Code reports an edit to a clean document while the document still reads clean, and its dirty flag only after it, as an event carrying no change ([{changes:1, dirty:false}, {changes:0, dirty:true}], measured on CI in the #196 probe). reindexFile → dirtyBytesOf (src/host/nameIndex.ts) asked isDirty alone, so that first edit's reindex found no unsaved text and scanned the file: a whole-file read on the first edit after every open or save, and the file's old names in the index for that edit.

Found by #196: with the Search Data Source Entries suite run first, jsonBaselineFollowsDisk "an edit to a clean document does not read the file" counted that read and failed.

Tests first

The first commit is tests only (red run below):

Red, run 41364249428 at 7de21da (211 passing, 3 failing): (a) fails with one read of the file; (b) fails too: after the one-edit rename the search still offered only Number, never NumberRenamedOnce; and jsonBaselineFollowsDisk's no-read test fails as in #196.

Fix

  • extension.ts: onDidChangeTextDocument (content changes only, as before) passes the document to reindexFile.
  • nameIndex.ts: the reindex that answers that change reads that document's text, whatever its dirty flag says yet; it is held for that reindex alone. Any other reindex (the folder's watcher) reads as before: a dirty open document's text, else the file through the shared cache.
  • documentText.ts (new, vscode-free): the decision, textOverDisk, unit-tested in test/documentText.test.ts.
  • CHANGELOG.md: ## Unreleased with one bullet (View as Text from the Command Palette opens the dictionary's text #193 adds the same heading, so a trivial merge is expected).

Green, run 41364583282 at 6cc8777: 214 passing, 9 pending, 0 failing; both new tests, the search suite and jsonBaselineFollowsDisk pass. Locally npm run verify passes (1312 unit tests).

ww-mw added 5 commits November 1, 2026 17:35
The palette runs a command with no argument, and lists View as Text only
while a table has focus. A table is a webview, so there is no active text
editor to take the file from, and the command does nothing. The new test
opens the JSON dictionary's table, runs View as Text with no argument and
expects its text in a second tab: it fails on this commit.

Two more pin the palette's View as Table: from a text editor it opens the
table beside it, and on a compressed dictionary already in its table it
leaves the one tab as it is.
The palette passes no argument, and both toggle commands fell back to the
active text editor's document. The palette lists View as Text only while a
table has focus, when there is no active text editor (a table is a
webview), so the command found no file and did nothing.

Both commands now take the file from the active tab, a custom editor's or
a text editor's, and only then from the active text editor.
Once a search has built the window's name index, every content change of an
open data source reindexes its file from the document's text. VS Code reports
an edit to a clean document while it still reads clean, and the reindex, which
asks isDirty alone, reads that first edit's file from disk instead.

nameIndexFirstEdit builds the index through the real search command, then makes
one edit to a clean JSON dictionary: no read of the file is made, and a rename
made in that one edit is what the search offers, not the name the file had.
Both fail on this commit.

With them, the Search Data Source Entries suite held back from #196 (the real
command and QuickPick, which leaves the index built), its QuickPick helpers in
tools/quickPicks.ts, and tools/webviewTap.ts as #196 has it.
The name index reindexes a data source on each of its content changes, from
the document's text while the document is dirty. VS Code reports an edit to a
clean document while it still reads clean, and its dirty flag only after, as
an event with no change, so that first edit's reindex read the whole file from
disk and kept the names the file had: a rename made in one edit was not what
the search offered until the next edit or a save.

onDidChangeTextDocument now hands reindexFile the document, and the reindex
that answers it reads that document's text whatever its flag says. Any other
reindex (the folder's watcher) reads as before: a dirty open document's text,
else the file. The decision is documentText.ts's, unit-tested.
Both add ## Unreleased to CHANGELOG.md: one heading now, #193's bullet first, then this one's.
@ww-mw
ww-mw merged commit 52c7f87 into main Nov 2, 2026
4 checks passed
@ww-mw
ww-mw deleted the fix/name-index-first-edit branch November 2, 2026 14:57
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