MCPcopy Create free account
hub / github.com/backnotprop/plannotator / parseRgJsonOutput

Function parseRgJsonOutput

packages/shared/code-nav.ts:202–242  ·  view source on GitHub ↗
(
  stdout: string,
  symbol: string,
  language?: string,
)

Source from the content-addressed store, hash-verified

200const PARSE_CAP = 500;
201
202export function parseRgJsonOutput(
203 stdout: string,
204 symbol: string,
205 language?: string,
206): CodeNavLocation[] {
207 const locations: CodeNavLocation[] = [];
208 const lines = stdout.split("\n");
209
210 for (const line of lines) {
211 if (locations.length >= PARSE_CAP) break;
212 if (!line.trim()) continue;
213
214 let parsed: { type: string; data: RgMatchData };
215 try {
216 parsed = JSON.parse(line);
217 } catch {
218 continue;
219 }
220
221 if (parsed.type !== "match") continue;
222
223 const d = parsed.data;
224 const snippet = d.lines.text.trimEnd();
225 const column = d.submatches?.[0]?.start ?? 0;
226 const kind = classifyMatch(snippet, symbol, language);
227 const filePath = d.path.text.startsWith("./")
228 ? d.path.text.slice(2)
229 : d.path.text;
230
231 locations.push({
232 kind,
233 confidence: kind === "definition" ? "likely" : "possible",
234 filePath,
235 line: d.line_number,
236 column,
237 snippet: snippet.length > 200 ? snippet.slice(0, 200) + "…" : snippet,
238 });
239 }
240
241 return locations;
242}
243
244// ---------------------------------------------------------------------------
245// Match classification

Callers 2

code-nav.test.tsFile · 0.90
resolveCodeNavFunction · 0.85

Calls 3

classifyMatchFunction · 0.85
parseMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected