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

Function extractCodeTokens

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

Source from the content-addressed store, hash-verified

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