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

Function readPath

src/resolution/rust-scopes.ts:274–297  ·  view source on GitHub ↗

A path at `at` — `Commands::Build`, `Self::A` — as its segments and the offset after it.

(code: string, at: number)

Source from the content-addressed store, hash-verified

272
273/** A path at `at` — `Commands::Build`, `Self::A` — as its segments and the offset after it. */
274function readPath(code: string, at: number): { segments: string[]; end: number } {
275 const segments: string[] = [];
276 let p = at;
277 for (;;) {
278 const id = identAt(code, p);
279 if (!id) break;
280 segments.push(id);
281 p += id.length;
282 let q = skipSpace(code, p);
283 if (!code.startsWith('::', q)) break;
284 q = skipSpace(code, q + 2);
285 // A turbofish: `Foo::<T>::Bar`, `Vec::<u8>`.
286 if (code[q] === '<') {
287 const end = angleClose(code, q);
288 if (end < 0) break;
289 p = end + 1;
290 q = skipSpace(code, p);
291 if (!code.startsWith('::', q)) break;
292 q = skipSpace(code, q + 2);
293 }
294 p = q;
295 }
296 return { segments, end: p };
297}
298
299type Emit = (name: string, at: number, site: RustPatternSite | undefined) => void;
300

Callers 1

walkPatternFunction · 0.85

Calls 4

identAtFunction · 0.85
angleCloseFunction · 0.85
pushMethod · 0.80
skipSpaceFunction · 0.70

Tested by

no test coverage detected