-
Notifications
You must be signed in to change notification settings - Fork 199
Fix codebase indexing for plain text files #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WebMad
wants to merge
5
commits into
Zoo-Code-Org:main
Choose a base branch
from
WebMad:fix/931-index-txt-files
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d0cf9c
fix(code-index): index plain text files
WebMad f34dd54
fix(tree-sitter): skip plain text definition parsing
WebMad c8b5491
fix(code-index): address plain text review feedback
WebMad 7446f33
fix(tree-sitter): preserve Scala structural parsing
WebMad 7dde9a1
test(code-index): remove redundant async usage
WebMad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
58 changes: 58 additions & 0 deletions
58
src/services/code-index/processors/__tests__/parser.txt.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { CodeParser } from "../parser" | ||
| import { scannerExtensions, shouldUseFallbackChunking } from "../../shared/supported-extensions" | ||
|
|
||
| vi.mock("../../../../../packages/telemetry/src/TelemetryService", () => ({ | ||
| TelemetryService: { | ||
| instance: { | ||
| captureEvent: vi.fn(), | ||
| }, | ||
| }, | ||
| })) | ||
|
|
||
| describe("CodeParser - plain text support", () => { | ||
| it("supports .txt files through fallback chunking", async () => { | ||
| expect(scannerExtensions).toContain(".txt") | ||
| expect(shouldUseFallbackChunking(".txt")).toBe(true) | ||
|
|
||
| const content = [ | ||
| "Zoo Code plain text indexing regression test.", | ||
| "This sentence contains searchable content that only exists in the text file.", | ||
| "The fallback parser should preserve every line while creating an indexable chunk.", | ||
| ].join("\n") | ||
|
|
||
| const blocks = await new CodeParser().parseFile("manual.txt", { | ||
| content, | ||
| fileHash: "txt-file-hash", | ||
| }) | ||
|
|
||
| expect(blocks).toHaveLength(1) | ||
| expect(blocks[0]).toMatchObject({ | ||
| file_path: "manual.txt", | ||
| type: "fallback_chunk", | ||
| start_line: 1, | ||
| end_line: 3, | ||
| content, | ||
| fileHash: "txt-file-hash", | ||
| segmentHash: expect.any(String), | ||
| }) | ||
| }) | ||
|
|
||
| it("parses uppercase .TXT extensions", async () => { | ||
| expect(shouldUseFallbackChunking(".TXT")).toBe(true) | ||
|
|
||
| const content = "Uppercase plain-text extension content long enough to produce a fallback chunk." | ||
| const blocks = await new CodeParser().parseFile("manual.TXT", { | ||
| content, | ||
| fileHash: "uppercase-txt-file-hash", | ||
| }) | ||
|
|
||
| expect(blocks).toHaveLength(1) | ||
| expect(blocks[0]).toMatchObject({ | ||
| file_path: "manual.TXT", | ||
| type: "fallback_chunk", | ||
| content, | ||
| fileHash: "uppercase-txt-file-hash", | ||
| segmentHash: expect.any(String), | ||
| }) | ||
| }) | ||
| }) | ||
|
WebMad marked this conversation as resolved.
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Extensions that should not be parsed for structural definitions and should | ||
| * instead use line-based fallback chunking where indexing is supported. | ||
| */ | ||
| export const fallbackExtensions = [".txt", ".vb", ".scala", ".swift"] as const | ||
|
|
||
| /** | ||
| * Fallback extensions that do not have a structural parser. Scala and Swift | ||
| * still support structural parsing outside code indexing. | ||
| */ | ||
| export const nonStructuralExtensions = [".txt", ".vb"] as const | ||
|
|
||
| /** | ||
| * Check whether a file extension should bypass structural parsing. | ||
| * | ||
| * @param extension File extension, including the leading dot | ||
| */ | ||
| export function isFallbackExtension(extension: string): boolean { | ||
| return (fallbackExtensions as readonly string[]).includes(extension.toLowerCase()) | ||
| } | ||
|
|
||
| /** | ||
| * Check whether a file extension should bypass structural parsing entirely. | ||
| * | ||
| * @param extension File extension, including the leading dot | ||
| */ | ||
| export function isNonStructuralExtension(extension: string): boolean { | ||
| return (nonStructuralExtensions as readonly string[]).includes(extension.toLowerCase()) | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/services/tree-sitter/__tests__/plainTextIntegration.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Mocks must come first, before imports | ||
|
|
||
| vi.mock("fs/promises", () => ({ | ||
| readFile: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock("../../../utils/fs", () => ({ | ||
| fileExistsAtPath: vi.fn().mockResolvedValue(true), | ||
| })) | ||
|
|
||
| vi.mock("../languageParser", () => ({ | ||
| loadRequiredLanguageParsers: vi.fn(), | ||
| })) | ||
|
|
||
| import * as fs from "fs/promises" | ||
| import { loadRequiredLanguageParsers } from "../languageParser" | ||
| import { parseSourceCodeDefinitionsForFile } from "../index" | ||
|
|
||
| describe("Non-structural Extension Integration Tests", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it.each(["manual.txt", "legacy.vb"])( | ||
| "returns undefined for %s without loading a tree-sitter parser", | ||
| async (filePath) => { | ||
| const result = await parseSourceCodeDefinitionsForFile(filePath) | ||
|
|
||
| expect(result).toBeUndefined() | ||
| }, | ||
| ) | ||
|
|
||
| afterEach(() => { | ||
| expect(loadRequiredLanguageParsers).not.toHaveBeenCalled() | ||
| expect(fs.readFile).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.