MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / stripWrapping

Function stripWrapping

src/search/query-paths.ts:216–242  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

214 * agent wants from it.
215 */
216function 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. */
245function normalizeSpan(span: string): string {

Callers 1

extractQueryPathsFunction · 0.85

Calls 2

lineSpanFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected