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

Function splitRustTopLevel

src/resolution/rust-scopes.ts:719–734  ·  view source on GitHub ↗
(text: string, sep: string)

Source from the content-addressed store, hash-verified

717
718/** `text` parted at its top-level `sep`s, outside `()`, `[]`, `{}` and `<>` (`->` closes nothing). */
719export function splitRustTopLevel(text: string, sep: string): string[] {
720 const parts: string[] = [];
721 let depth = 0;
722 let start = 0;
723 for (let i = 0; i < text.length; i++) {
724 const c = text[i]!;
725 if (c === '(' || c === '[' || c === '{' || c === '<') depth++;
726 else if (c === ')' || c === ']' || c === '}' || (c === '>' && text[i - 1] !== '-' && text[i - 1] !== '=')) depth--;
727 else if (c === sep && depth === 0) {
728 parts.push(text.slice(start, i));
729 start = i + 1;
730 }
731 }
732 parts.push(text.slice(start));
733 return parts.map((p) => p.trim()).filter((p) => p !== '');
734}
735
736/**
737 * The bounds a generic parameter `name` is declared with, read from the

Callers 2

takeFunction · 0.85
rustBoundsOfFunction · 0.85

Calls 2

pushMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected