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

Function attributedDeclarations

src/resolution/frameworks/drupal.ts:492–519  ·  view source on GitHub ↗

* Every declaration that carries attributes. Read from the source, not from * `stripCommentsForRegex`, to which a `#[` is a comment like any other `#`.

(content: string)

Source from the content-addressed store, hash-verified

490 * `stripCommentsForRegex`, to which a `#[` is a comment like any other `#`.
491 */
492function attributedDeclarations(content: string): AttributedDeclaration[] {
493 const out: AttributedDeclaration[] = [];
494 const lineOf = makeLineAt(content, 1);
495 ATTRIBUTE_START.lastIndex = 0;
496 let m: RegExpExecArray | null;
497 while ((m = ATTRIBUTE_START.exec(content)) !== null) {
498 const start = m.index + m[0].length - 2;
499 const attributes: Attribute[] = [];
500 let at = start;
501 while (content.startsWith('#[', at)) {
502 const close = matchBracket(content, at + 1);
503 if (close < 0) break;
504 const body = /^\s*\\?([\w\\]+)\s*(\()?/.exec(content.slice(at + 2, close));
505 if (body) {
506 const open = at + 2 + body[0].length - 1;
507 const end = body[2] ? matchBracket(content, open) : -1;
508 attributes.push({ name: body[1]!.split('\\').pop()!, args: end > 0 ? content.slice(open + 1, end) : '' });
509 }
510 at = skipTrivia(content, close + 1);
511 }
512 ATTRIBUTE_START.lastIndex = Math.max(at, m.index + m[0].length);
513 DECLARATION.lastIndex = at;
514 const decl = DECLARATION.exec(content);
515 if (!decl) continue;
516 out.push({ attributes, line: lineOf(start), offset: at, method: decl[1], className: decl[2] });
517 }
518 return out;
519}
520
521/** The first string an attribute's arguments open with, by position or as `name:`. */
522function firstArgument(args: string, name: string): string | null {

Callers 1

extractFunction · 0.85

Calls 6

makeLineAtFunction · 0.90
matchBracketFunction · 0.90
pushMethod · 0.80
skipTriviaFunction · 0.70
lineOfFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected