MCPcopy
hub / github.com/codeaashu/claude-code / parseGrepOutput

Function parseGrepOutput

web/components/tools/ToolGrep.tsx:40–65  ·  view source on GitHub ↗
(result: string)

Source from the content-addressed store, hash-verified

38}
39
40function parseGrepOutput(result: string): GrepGroup[] {
41 const lines = result.split("\n").filter(Boolean);
42 const groups: Map<string, GrepMatch[]> = new Map();
43
44 for (const line of lines) {
45 // Format: "file:lineNo:content" or "file:content" or just "file"
46 const colonMatch = line.match(/^([^:]+):(\d+):(.*)$/);
47 if (colonMatch) {
48 const [, file, lineNo, content] = colonMatch;
49 if (!groups.has(file)) groups.set(file, []);
50 groups.get(file)!.push({ file, lineNo: parseInt(lineNo, 10), content });
51 } else if (line.match(/^[^:]+$/)) {
52 // Files-only mode
53 if (!groups.has(line)) groups.set(line, []);
54 } else {
55 // fallback: treat entire line as content with unknown file
56 if (!groups.has("")) groups.set("", []);
57 groups.get("")!.push({ file: "", content: line });
58 }
59 }
60
61 return Array.from(groups.entries()).map(([file, matches]) => ({
62 file,
63 matches,
64 }));
65}
66
67function highlightPattern(text: string, pattern: string): React.ReactNode {
68 try {

Callers 1

ToolGrepFunction · 0.85

Calls 5

entriesMethod · 0.80
getMethod · 0.65
hasMethod · 0.45
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected