( stdout: string, symbol: string, language?: string, )
| 200 | const PARSE_CAP = 500; |
| 201 | |
| 202 | export 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 |
no test coverage detected