Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/services/code-index/processors/__tests__/parser.txt.spec.ts
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",
})
Comment thread
WebMad marked this conversation as resolved.
})

it("matches uppercase .TXT extensions", () => {
expect(shouldUseFallbackChunking(".TXT")).toBe(true)
})
Comment thread
WebMad marked this conversation as resolved.
Outdated
})
Comment thread
WebMad marked this conversation as resolved.
1 change: 1 addition & 0 deletions src/services/code-index/shared/supported-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const scannerExtensions = allExtensions
* Note: Do NOT remove parser cases from languageParser.ts as they may be used elsewhere
*/
export const fallbackExtensions = [
".txt", // Plain text - no tree-sitter parser needed
".vb", // Visual Basic .NET - no dedicated WASM parser
".scala", // Scala - uses fallback chunking instead of Lua query workaround
".swift", // Swift - uses fallback chunking due to parser instability
Expand Down
31 changes: 31 additions & 0 deletions src/services/tree-sitter/__tests__/plainTextIntegration.spec.ts
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()
})
})
7 changes: 7 additions & 0 deletions src/services/tree-sitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const extensions = [
// Markdown
"md",
"markdown",
// Plain text
"txt",
// JSON
"json",
// CSS
Expand Down Expand Up @@ -111,6 +113,11 @@ export async function parseSourceCodeDefinitionsForFile(
return undefined
}

// Plain text files have no structural definitions to extract
if (ext === ".txt") {
Comment thread
WebMad marked this conversation as resolved.
Outdated
return undefined
}
Comment thread
WebMad marked this conversation as resolved.
Outdated

// Special case for markdown files
if (ext === ".md" || ext === ".markdown") {
// Check if we have permission to access this file
Expand Down
Loading