[DIT-13463]: Stable occurrence index on scan candidates - #152
Closed
laurakoye wants to merge 1 commit into
Closed
Conversation
Contributor
Author
|
Closing since this PR should really branch off of text-extract |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds
occurrence_indexto scan candidates: which repeat this string is within its file, counting from 0 in source order.If a file has three
"Save"strings, only the line number tells them apart today — and line numbers move whenever someone adds an import. The index doesn't, so a code link can still say which occurrence it points at after the file shifts.assignOccurrenceIndexes(hits)inlib/src/scan/extract.ts, exported so it can be unit tested.(line, column)first, which is the point of the PR. The JS extractor emits hits grouped by node kind (lang/extractors/javascript.ts:37), not source order, so counting them as they arrive gives an index that changes between runs of an unmodified file. Sorting happens on indices internally, so emitted candidate order is unchanged.occurrence_indexadded toDittoScanCandidateSchema.Nothing server-side is needed to merge — zod strips unknown keys, so the field is ignored on arrival for now. A ditto-app follow-up adds it to
PtdCandidateSchema, where the code link write will read it.Context
DIT-13463, part of DIT-13405.
A code link identifies a hardcoded string by (file, value, occurrence index) — never by line number, which is display-only. This is the last of those three fields. Schema design.
Screenshots
None — extraction output only.
Test Plan
Testing successfully completed locally via:
yarn test lib/src/scan— 136 tests pass, 6 newScan
v0-demo, edit it, scan again.--localskips auth, upload and classification, so no server or token needed.In
v0-demo/src/features/payments/SendMoney.tsx, add an import and a const above the component so every line shifts down, then add one moret("send.title")below the two already there.Every line moved by 3. Every index stayed. The new occurrence is
#2because it comes after the others in the file.Known limit: add that third
t("send.title")above the existing two instead and it becomes#0, renumbering the rest. Keyed strings survive that viai18nKey; hardcoded ones fall through to the value-in-file rung during reconciliation. The index only has to be stable against edits elsewhere in the file, not against inserting a new copy of itself.