-
Notifications
You must be signed in to change notification settings - Fork 270
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
Merged
Merged
Changes from 2 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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
| 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", | ||
| }) | ||
| }) | ||
|
|
||
| it("matches uppercase .TXT extensions", () => { | ||
| expect(shouldUseFallbackChunking(".TXT")).toBe(true) | ||
| }) | ||
|
WebMad marked this conversation as resolved.
Outdated
|
||
| }) | ||
|
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
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
| // 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("Plain Text Integration Tests", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it("returns undefined without loading a tree-sitter parser", async () => { | ||
| const result = await parseSourceCodeDefinitionsForFile("manual.txt") | ||
|
|
||
| expect(result).toBeUndefined() | ||
| 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.