fix(opencode): add AbortSignal support to Ripgrep.files() and GlobTool (#10833)
This commit is contained in:
@@ -209,7 +209,10 @@ export namespace Ripgrep {
|
|||||||
hidden?: boolean
|
hidden?: boolean
|
||||||
follow?: boolean
|
follow?: boolean
|
||||||
maxDepth?: number
|
maxDepth?: number
|
||||||
|
signal?: AbortSignal
|
||||||
}) {
|
}) {
|
||||||
|
input.signal?.throwIfAborted()
|
||||||
|
|
||||||
const args = [await filepath(), "--files", "--glob=!.git/*"]
|
const args = [await filepath(), "--files", "--glob=!.git/*"]
|
||||||
if (input.follow !== false) args.push("--follow")
|
if (input.follow !== false) args.push("--follow")
|
||||||
if (input.hidden !== false) args.push("--hidden")
|
if (input.hidden !== false) args.push("--hidden")
|
||||||
@@ -235,6 +238,7 @@ export namespace Ripgrep {
|
|||||||
stdout: "pipe",
|
stdout: "pipe",
|
||||||
stderr: "ignore",
|
stderr: "ignore",
|
||||||
maxBuffer: 1024 * 1024 * 20,
|
maxBuffer: 1024 * 1024 * 20,
|
||||||
|
signal: input.signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
const reader = proc.stdout.getReader()
|
const reader = proc.stdout.getReader()
|
||||||
@@ -243,6 +247,8 @@ export namespace Ripgrep {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
input.signal?.throwIfAborted()
|
||||||
|
|
||||||
const { done, value } = await reader.read()
|
const { done, value } = await reader.read()
|
||||||
if (done) break
|
if (done) break
|
||||||
|
|
||||||
@@ -261,11 +267,13 @@ export namespace Ripgrep {
|
|||||||
reader.releaseLock()
|
reader.releaseLock()
|
||||||
await proc.exited
|
await proc.exited
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input.signal?.throwIfAborted()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tree(input: { cwd: string; limit?: number }) {
|
export async function tree(input: { cwd: string; limit?: number; signal?: AbortSignal }) {
|
||||||
log.info("tree", input)
|
log.info("tree", input)
|
||||||
const files = await Array.fromAsync(Ripgrep.files({ cwd: input.cwd }))
|
const files = await Array.fromAsync(Ripgrep.files({ cwd: input.cwd, signal: input.signal }))
|
||||||
interface Node {
|
interface Node {
|
||||||
path: string[]
|
path: string[]
|
||||||
children: Node[]
|
children: Node[]
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export const GlobTool = Tool.define("glob", {
|
|||||||
for await (const file of Ripgrep.files({
|
for await (const file of Ripgrep.files({
|
||||||
cwd: search,
|
cwd: search,
|
||||||
glob: [params.pattern],
|
glob: [params.pattern],
|
||||||
|
signal: ctx.abort,
|
||||||
})) {
|
})) {
|
||||||
if (files.length >= limit) {
|
if (files.length >= limit) {
|
||||||
truncated = true
|
truncated = true
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export const ListTool = Tool.define("list", {
|
|||||||
|
|
||||||
const ignoreGlobs = IGNORE_PATTERNS.map((p) => `!${p}*`).concat(params.ignore?.map((p) => `!${p}`) || [])
|
const ignoreGlobs = IGNORE_PATTERNS.map((p) => `!${p}*`).concat(params.ignore?.map((p) => `!${p}`) || [])
|
||||||
const files = []
|
const files = []
|
||||||
for await (const file of Ripgrep.files({ cwd: searchPath, glob: ignoreGlobs })) {
|
for await (const file of Ripgrep.files({ cwd: searchPath, glob: ignoreGlobs, signal: ctx.abort })) {
|
||||||
files.push(file)
|
files.push(file)
|
||||||
if (files.length >= LIMIT) break
|
if (files.length >= LIMIT) break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user