mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: ensure JSON files respect .rooignore during indexing (#6691)
Co-authored-by: Roo Code <roomote@roocode.com> Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
This commit is contained in:
parent
f9e85a5e84
commit
bbe3362359
3 changed files with 54 additions and 2 deletions
|
|
@ -19,7 +19,14 @@ vi.mock("vscode", () => {
|
|||
index: 0,
|
||||
},
|
||||
],
|
||||
createFileSystemWatcher: vi.fn().mockReturnValue({
|
||||
onDidCreate: vi.fn().mockReturnValue({ dispose: vi.fn() }),
|
||||
onDidChange: vi.fn().mockReturnValue({ dispose: vi.fn() }),
|
||||
onDidDelete: vi.fn().mockReturnValue({ dispose: vi.fn() }),
|
||||
dispose: vi.fn(),
|
||||
}),
|
||||
},
|
||||
RelativePattern: vi.fn().mockImplementation((base, pattern) => ({ base, pattern })),
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -32,6 +39,26 @@ vi.mock("../../../utils/path", () => {
|
|||
}
|
||||
})
|
||||
|
||||
// Mock fs/promises for RooIgnoreController
|
||||
vi.mock("fs/promises", () => ({
|
||||
default: {
|
||||
readFile: vi.fn().mockRejectedValue(new Error("File not found")), // Simulate no .gitignore/.rooignore
|
||||
},
|
||||
}))
|
||||
|
||||
// Mock file utils for RooIgnoreController
|
||||
vi.mock("../../../utils/fs", () => ({
|
||||
fileExistsAtPath: vi.fn().mockResolvedValue(false), // Simulate no .rooignore file
|
||||
}))
|
||||
|
||||
// Mock ignore module
|
||||
vi.mock("ignore", () => ({
|
||||
default: vi.fn().mockReturnValue({
|
||||
add: vi.fn(),
|
||||
ignores: vi.fn().mockReturnValue(false),
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock("../state-manager", () => ({
|
||||
CodeIndexStateManager: vi.fn().mockImplementation(() => ({
|
||||
onProgressUpdate: vi.fn(),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { CodeIndexServiceFactory } from "./service-factory"
|
|||
import { CodeIndexSearchService } from "./search-service"
|
||||
import { CodeIndexOrchestrator } from "./orchestrator"
|
||||
import { CacheManager } from "./cache-manager"
|
||||
import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
|
||||
import fs from "fs/promises"
|
||||
import ignore from "ignore"
|
||||
import path from "path"
|
||||
|
|
@ -312,6 +313,7 @@ export class CodeIndexManager {
|
|||
return
|
||||
}
|
||||
|
||||
// Create .gitignore instance
|
||||
const ignorePath = path.join(workspacePath, ".gitignore")
|
||||
try {
|
||||
const content = await fs.readFile(ignorePath, "utf8")
|
||||
|
|
@ -327,11 +329,16 @@ export class CodeIndexManager {
|
|||
})
|
||||
}
|
||||
|
||||
// Create RooIgnoreController instance
|
||||
const rooIgnoreController = new RooIgnoreController(workspacePath)
|
||||
await rooIgnoreController.initialize()
|
||||
|
||||
// (Re)Create shared service instances
|
||||
const { embedder, vectorStore, scanner, fileWatcher } = this._serviceFactory.createServices(
|
||||
this.context,
|
||||
this._cacheManager!,
|
||||
ignoreInstance,
|
||||
rooIgnoreController,
|
||||
)
|
||||
|
||||
// Validate embedder configuration before proceeding
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { codeParser, DirectoryScanner, FileWatcher } from "./processors"
|
|||
import { ICodeParser, IEmbedder, IFileWatcher, IVectorStore } from "./interfaces"
|
||||
import { CodeIndexConfigManager } from "./config-manager"
|
||||
import { CacheManager } from "./cache-manager"
|
||||
import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
|
||||
import { Ignore } from "ignore"
|
||||
import { t } from "../../i18n"
|
||||
import { TelemetryService } from "@roo-code/telemetry"
|
||||
|
|
@ -161,8 +162,17 @@ export class CodeIndexServiceFactory {
|
|||
vectorStore: IVectorStore,
|
||||
cacheManager: CacheManager,
|
||||
ignoreInstance: Ignore,
|
||||
rooIgnoreController?: RooIgnoreController,
|
||||
): IFileWatcher {
|
||||
return new FileWatcher(this.workspacePath, context, cacheManager, embedder, vectorStore, ignoreInstance)
|
||||
return new FileWatcher(
|
||||
this.workspacePath,
|
||||
context,
|
||||
cacheManager,
|
||||
embedder,
|
||||
vectorStore,
|
||||
ignoreInstance,
|
||||
rooIgnoreController,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,6 +183,7 @@ export class CodeIndexServiceFactory {
|
|||
context: vscode.ExtensionContext,
|
||||
cacheManager: CacheManager,
|
||||
ignoreInstance: Ignore,
|
||||
rooIgnoreController?: RooIgnoreController,
|
||||
): {
|
||||
embedder: IEmbedder
|
||||
vectorStore: IVectorStore
|
||||
|
|
@ -188,7 +199,14 @@ export class CodeIndexServiceFactory {
|
|||
const vectorStore = this.createVectorStore()
|
||||
const parser = codeParser
|
||||
const scanner = this.createDirectoryScanner(embedder, vectorStore, parser, ignoreInstance)
|
||||
const fileWatcher = this.createFileWatcher(context, embedder, vectorStore, cacheManager, ignoreInstance)
|
||||
const fileWatcher = this.createFileWatcher(
|
||||
context,
|
||||
embedder,
|
||||
vectorStore,
|
||||
cacheManager,
|
||||
ignoreInstance,
|
||||
rooIgnoreController,
|
||||
)
|
||||
|
||||
return {
|
||||
embedder,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue