(
path: string,
result: { content: string; totalLines: number; attachment?: unknown },
pattern: string,
readHint: string,
options?: GrepOptions
)
| 58 | * `path`. `readHint` is the path to suggest in the "use read(...)" message. |
| 59 | */ |
| 60 | export function grepReadResult( |
| 61 | path: string, |
| 62 | result: { content: string; totalLines: number; attachment?: unknown }, |
| 63 | pattern: string, |
| 64 | readHint: string, |
| 65 | options?: GrepOptions |
| 66 | ): GrepMatch[] | string[] | GrepCountEntry[] { |
| 67 | if (result.attachment) { |
| 68 | throw new WorkspaceFileGrepError( |
| 69 | `Cannot grep "${path}" — it has no searchable text (image/binary). Use read("${readHint}") to view it.` |
| 70 | ) |
| 71 | } |
| 72 | if (isNonGreppablePlaceholder(result.content, result.totalLines)) { |
| 73 | throw new WorkspaceFileGrepError(result.content) |
| 74 | } |
| 75 | return grep(new Map([[path, result.content]]), pattern, undefined, options) |
| 76 | } |
| 77 | |
| 78 | export interface ReadResult { |
| 79 | content: string |
no test coverage detected