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

Function extractCodeTokens

src/directory.ts:772–790  ·  view source on GitHub ↗
(prompt: string)

Source from the content-addressed store, hash-verified

770 * is excluded from the member-access form since it's a file reference, not a symbol.
771 */
772export function extractCodeTokens(prompt: string): string[] {
773 if (!prompt) return [];
774 const out = new Set<string>();
775 // camelCase / PascalCase-with-inner-cap (getUserId, parseToken, UserService) or
776 // snake_case (article_publish, get_user) — a whole identifier run that has an
777 // inner lower→upper transition or an underscore flanked by alphanumerics.
778 for (const m of prompt.matchAll(/[A-Za-z_$][\w$]*/g)) {
779 const w = m[0];
780 if (/[a-z][A-Z]/.test(w) || /[A-Za-z0-9]_[A-Za-z0-9]/.test(w)) out.add(w);
781 }
782 // call form: an identifier directly before '(' — parseToken(, render(). No
783 // whitespace before '(' so prose like "the function (entry point)" doesn't trip it.
784 for (const m of prompt.matchAll(/([A-Za-z_$][\w$]*)\(/g)) out.add(m[1]!);
785 // member access on identifiers (user.login) — but not a doc/data filename.
786 for (const m of prompt.matchAll(/([A-Za-z_$][\w$]*)\.([A-Za-z_$][\w$]*)/g)) {
787 if (!DOC_DATA_EXT.test(m[0])) { out.add(m[1]!); out.add(m[2]!); }
788 }
789 return [...out];
790}
791
792/**
793 * Cheap, graph-free candidate gate for the front-load hook: could `prompt` be a

Callers 3

mainFunction · 0.90
isStructuralPromptFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected