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

Function pluginDefinitions

src/resolution/frameworks/drupal.ts:563–599  ·  view source on GitHub ↗

A class's plugin definitions: its attributes and its docblock's annotations, each with an `id`.

(content: string, declarations: readonly AttributedDeclaration[])

Source from the content-addressed store, hash-verified

561
562/** A class's plugin definitions: its attributes and its docblock's annotations, each with an `id`. */
563function pluginDefinitions(content: string, declarations: readonly AttributedDeclaration[]): { type: string; id: string; className: string; line: number }[] {
564 const out: { type: string; id: string; className: string; line: number }[] = [];
565 const seen = new Set<string>();
566 const add = (type: string, id: string, className: string, line: number): void => {
567 const key = `${type}:${id}:${className}`;
568 if (seen.has(key)) return;
569 seen.add(key);
570 out.push({ type, id, className, line });
571 };
572 for (const decl of declarations) {
573 if (!decl.className) continue;
574 for (const attribute of decl.attributes) {
575 if (NOT_PLUGIN_ATTRIBUTES.has(attribute.name)) continue;
576 const id = firstArgument(attribute.args, 'id') ?? /\bid\s*:\s*['"]([^'"]+)['"]/.exec(attribute.args)?.[1];
577 if (id) add(attribute.name, id, decl.className, decl.line);
578 }
579 }
580 const lineOf = makeLineAt(content, 1);
581 const doc = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*(?:#\[[^\n]*\n\s*)*(?:(?:abstract|final|readonly)\s+)*class\s+([A-Za-z_]\w*)/g;
582 let m: RegExpExecArray | null;
583 while ((m = doc.exec(content)) !== null) {
584 const bodyAt = m.index + 3;
585 const annotation = /^[ \t]*\*[ \t]*@([A-Z]\w*)\s*\(/gm;
586 annotation.lastIndex = 0;
587 let a: RegExpExecArray | null;
588 while ((a = annotation.exec(m[1]!)) !== null) {
589 const open = a.index + a[0].length - 1;
590 const close = matchBracket(m[1]!, open);
591 if (close < 0) continue;
592 const body = m[1]!.slice(open, close);
593 const id = /(?:^|[\s,(])id\s*=\s*"([^"]+)"/.exec(body)?.[1] ?? /^\(\s*"([^"]+)"/.exec(body)?.[1];
594 if (id) add(a[1]!, id, m[2]!, lineOf(bodyAt + a.index + a[0].indexOf('@')));
595 annotation.lastIndex = close;
596 }
597 }
598 return out;
599}
600
601function extractDrupalPlugins(
602 filePath: string,

Callers 1

extractDrupalPluginsFunction · 0.85

Calls 7

makeLineAtFunction · 0.90
matchBracketFunction · 0.90
firstArgumentFunction · 0.85
hasMethod · 0.80
addFunction · 0.70
lineOfFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected