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

Function attributedDeclarations

src/resolution/frameworks/drupal.ts:493–520  ·  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

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