Populate the FTS5 index with comments and string literals - #6
Open
mutoharohfiqhiabcd-source wants to merge 1 commit into
Open
mutoharohfiqhiabcd-source wants to merge 1 commit into
mutoharohfiqhiabcd-source wants to merge 1 commit into
Conversation
docs/development.md has carried this as a TODO since the initial schema:
"The FTS5 table schema exists but is not yet populated or exposed via MCP
tools." The TextElement dataclass was declared for it, but nothing ever
produced a TextElement, so code_text_fts was always empty -- the only
statement touching it was a DELETE -- and every MATCH query returned nothing.
This wires the missing path end to end:
extract -> cache -> worker -> sqlite writer -> code_text_fts
Extraction
- C/C++/ObjC++/Metal and Rust reuse the tree-sitter trees already built for
symbol extraction, walking for comment and string_literal nodes. A matched
node is not descended into, so a comment body cannot yield duplicate
children.
- Python uses the stdlib tokenizer, since Python is parsed through `ast`
here and no Python grammar is bundled.
- Comment markers and surrounding quotes are stripped. Content is capped at
2000 chars and 5000 elements per file, so a generated header cannot bloat
the index.
Caching
- FileCache gains text_elements, with CACHE_VERSION 6 -> 7, so an
incremental run reuses them exactly like symbols. Older caches are
invalidated by the version bump.
Measured on a 600-file C++ project:
symbols 7597
code_text_fts 27998 (18267 comments, 9731 string literals)
index time ~20s, up from ~17s
Known limitation: the existing schema's unicode61 tokenizer does not segment
CJK. A run of Chinese characters becomes a single token, so substring queries
against it match nothing. `tokenize='trigram'` would fix that and enable
substring search generally, but it changes the documented schema, so it felt
better left as a follow-up than smuggled into this change.
Test status on Windows is unchanged by this commit: tests/ reports 26 failed /
41 passed both with and without it (the failures are pre-existing and shell/
git-hook related, not related to indexing).
This branch has not been deployed
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.
What
Populates
code_text_fts, which has existed in the schema since day one but was never written to.docs/development.mdhas carried this as an open TODO:The
TextElementdataclass was declared for it too, but nothing ever produced one. The only statement touching the table was aDELETE, so everyMATCHquery returned nothing:This wires up the missing path end to end:
Extraction
commentandstring_literalnodes. A matched node is not descended into, so a comment body cannot produce duplicate children.tokenizemodule, since Python is parsed throughasthere and no Python grammar is bundled as a dependency.Caching
FileCachegainstext_elements, withCACHE_VERSIONbumped 6 → 7 so older caches are invalidated. Incremental runs reuse them exactly like symbols — a second run on an unchanged tree reportsCache: 600 cached, 0 parsed.Measured
On a 600-file C++ project (583 C/C++ headers/sources, 17 Python):
Queries that previously returned nothing now work:
Known limitation
The existing schema uses
tokenize='unicode61 remove_diacritics 2', which does not segment CJK. A run of Chinese characters becomes a single token, so substring queries against it match nothing:Switching to
tokenize='trigram'would fix that and enable substring search generally, but it changes the schema documented indocs/architecture.mdanddocs/development.md. I left it out rather than smuggle a schema change into this PR — happy to follow up if you want it.Test status
Unchanged by this commit. On Windows,
tests/reports 26 failed / 41 passed both with and without these changes — the failures are pre-existing and concentrated in the shell/git-hook tests (test_update_context.py,test_setup_permissions.py), not in indexing.Note
This was developed on top of #5 (Windows compatibility) because that fix is what makes
map.pyrunnable on Windows at all, then rebased ontomainso the diff here is FTS-only. #5 is independent of this change; it's just a prerequisite for testing it on Windows.