Skip to content

Commit 252ff93

Browse files
author
wutian
committed
Handle path properly on Windows, update logic & test cases
1 parent 4c9698e commit 252ff93

File tree

4 files changed

+299
-136
lines changed

4 files changed

+299
-136
lines changed

src/integrations/workspace/RipgrepResultCache.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class RipgrepResultCache {
2121

2222
constructor(rgPath: string, targetPath: string, rgArgs: string[] = [], fileLimit: number = 5000) {
2323
this.rgPath = rgPath
24-
this._targetPath = pathResolve(targetPath).split(sep).join("/")
24+
this._targetPath = pathResolve(targetPath)
2525
this.fileLimit = fileLimit
2626
this.rgArgs = rgArgs.length > 0 ? rgArgs : ["--files"]
2727
}
@@ -99,10 +99,7 @@ export class RipgrepResultCache {
9999
}
100100

101101
private fileAddedOrRemoved(filePath: string): void {
102-
const normalizedFilePath = filePath.split(sep).join("/")
103-
const normalizedTargetPath = this._targetPath
104-
105-
const relativePath = relative(normalizedTargetPath, pathResolve(normalizedTargetPath, normalizedFilePath))
102+
const relativePath = relative(this._targetPath, pathResolve(this._targetPath, filePath))
106103
const parentDir = dirname(relativePath)
107104

108105
if (parentDir !== "." && parentDir !== "") {
@@ -207,7 +204,7 @@ export class RipgrepResultCache {
207204

208205
try {
209206
// Stream build subtrees for all invalid directories (pass directory paths directly)
210-
const invalidDirectories = Array.from(this.invalidatedDirectories)
207+
const invalidDirectories = Array.from(this.invalidatedDirectories).map((dir) => dir.split("/").join(sep))
211208
const subtree = await this.buildTreeStreaming(invalidDirectories)
212209

213210
// Merge subtrees into main tree (replace original invalid parts)
@@ -233,9 +230,8 @@ export class RipgrepResultCache {
233230
args.push(...targetPaths)
234231
}
235232

236-
const originalPath = this._targetPath.split("/").join(sep)
237233
const child = spawn(this.rgPath, args, {
238-
cwd: originalPath,
234+
cwd: this._targetPath,
239235
stdio: ["pipe", "pipe", "pipe"],
240236
})
241237

@@ -246,7 +242,7 @@ export class RipgrepResultCache {
246242
// Stream add file paths to simplified tree structure
247243
const addFileToTree = (filePath: string) => {
248244
// ripgrep output is already relative path, use directly
249-
const parts = filePath.split("/").filter(Boolean)
245+
const parts = filePath.split(sep).filter(Boolean)
250246
let currentNode: SimpleTreeNode = tree
251247

252248
for (let i = 0; i < parts.length; i++) {

0 commit comments

Comments
 (0)