* Strip prose punctuation wrapped around a token without eating punctuation * that is PART of the path: quotes/backticks always strip; a trailing `)`/`]` * strips only when the token has no matching opener (so `(protected)` and * `[id]` segments survive, while "…(see src/foo.ts)" loses its parent
(token: string)
| 214 | * agent wants from it. |
| 215 | */ |
| 216 | function stripWrapping(token: string): { path: string; lines: { start: number; end: number } | null } { |
| 217 | let s = token; |
| 218 | for (;;) { |
| 219 | const first = s[0]; |
| 220 | if (!first) break; |
| 221 | if ('\'"`<'.includes(first)) { s = s.slice(1); continue; } |
| 222 | if (first === '(' && !s.includes(')')) { s = s.slice(1); continue; } |
| 223 | if (first === '[' && !s.includes(']')) { s = s.slice(1); continue; } |
| 224 | if (first === '{' && !s.includes('}')) { s = s.slice(1); continue; } |
| 225 | break; |
| 226 | } |
| 227 | for (;;) { |
| 228 | const last = s[s.length - 1]; |
| 229 | if (!last) break; |
| 230 | if ('\'"`>.,;!?'.includes(last)) { s = s.slice(0, -1); continue; } |
| 231 | if (last === ')' && !s.includes('(')) { s = s.slice(0, -1); continue; } |
| 232 | if (last === ']' && !s.includes('[')) { s = s.slice(0, -1); continue; } |
| 233 | if (last === '}' && !s.includes('{')) { s = s.slice(0, -1); continue; } |
| 234 | break; |
| 235 | } |
| 236 | const ref = LINE_REF_SUFFIX.exec(s); |
| 237 | if (!ref) return { path: s, lines: null }; |
| 238 | return { |
| 239 | path: s.slice(0, ref.index), |
| 240 | lines: ref[1] !== undefined ? lineSpan(ref[1], ref[2]) : lineSpan(ref[3], ref[4]), |
| 241 | }; |
| 242 | } |
| 243 | |
| 244 | /** Normalize a span into the repo-relative shape the files table stores. */ |
| 245 | function normalizeSpan(span: string): string { |
no test coverage detected