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

Function decoratorsInTree

src/graph/branch-guards.ts:2223–2244  ·  view source on GitHub ↗
(root: SyntaxNode, source: string, line: number)

Source from the content-addressed store, hash-verified

2221}
2222
2223export function decoratorsInTree(root: SyntaxNode, source: string, line: number): DefinitionDecorators | null {
2224 const row = line - 1;
2225 const col = firstNonBlankColumn(source, row);
2226 let node: SyntaxNode | null = innermostAt(root, row, col);
2227 if (!node) return null;
2228 // Up to the definition the line belongs to.
2229 let definition: SyntaxNode | null = null;
2230 for (let up = 0; node && up < 12; up++, node = node.parent) {
2231 if (DEFINITION_TYPES.has(node.type)) {
2232 definition = node;
2233 break;
2234 }
2235 }
2236 if (!definition) return null;
2237 // A Python decorated function is the child of the node that holds the decorators.
2238 const holder = definition.parent && definition.parent.type === 'decorated_definition' ? definition.parent : definition;
2239 const own = decoratorsOn(holder);
2240 let cls: SyntaxNode | null = holder.parent;
2241 for (let up = 0; cls && up < 6 && !CLASS_TYPES.has(cls.type); up++) cls = cls.parent;
2242 const clsHolder = cls && cls.parent && cls.parent.type === 'decorated_definition' ? cls.parent : cls;
2243 return { own, class: clsHolder ? decoratorsOn(clsHolder) : [] };
2244}
2245
2246/** Decorator texts on one definition node: its own leading decorator children, its modifiers/attribute lists, or the siblings before it. */
2247function decoratorsOn(definition: SyntaxNode): string[] {

Callers 2

decoratorsForFileFunction · 0.85
decoratorsInSourceFunction · 0.85

Calls 4

firstNonBlankColumnFunction · 0.85
innermostAtFunction · 0.85
decoratorsOnFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected