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

Method extractMethod

src/extraction/tree-sitter.ts:1743–1835  ·  view source on GitHub ↗

* Extract a method

(node: SyntaxNode)

Source from the content-addressed store, hash-verified

1741 * Extract a method
1742 */
1743 private extractMethod(node: SyntaxNode): void {
1744 if (!this.extractor) return;
1745
1746 // For languages with receiver types (Go, Rust), include receiver in qualified name
1747 // so FTS can match "scrapeLoop.run" → qualified_name "...::scrapeLoop::run"
1748 const receiverType = this.extractor.getReceiverType?.(node, this.source);
1749
1750 // For most languages, only extract as method if inside a class-like node
1751 // Languages with methodsAreTopLevel (e.g. Go) always treat them as methods
1752 // Languages with getReceiverType (e.g. Rust) extract as method when receiver is found
1753 if (!this.isInsideClassLikeNode() && !this.extractor.methodsAreTopLevel && !receiverType) {
1754 // Skip method_definition nodes inside object literals (getters/setters/methods
1755 // in inline objects). These are ephemeral and create noise (e.g., Svelte context
1756 // objects: `ctx.set({ get view() { ... } })`).
1757 if (node.parent?.type === 'object' || node.parent?.type === 'object_expression') {
1758 const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
1759 ?? getChildByField(node, this.extractor.bodyField);
1760 if (body) {
1761 this.visitFunctionBody(body, '');
1762 }
1763 return;
1764 }
1765 // Not inside a class-like node and no receiver type, treat as function
1766 this.extractFunction(node);
1767 return;
1768 }
1769
1770 const name = extractName(node, this.source, this.extractor);
1771
1772 // Check for misparse artifacts (e.g. C++ "switch" inside macro-confused class body)
1773 if (this.extractor.isMisparsedFunction?.(name, node)) {
1774 const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
1775 ?? getChildByField(node, this.extractor.bodyField);
1776 if (body) {
1777 this.visitFunctionBody(body, '');
1778 }
1779 return;
1780 }
1781
1782 const docstring = getPrecedingDocstring(node, this.source);
1783 const signature = this.extractor.getSignature?.(node, this.source);
1784 const visibility = this.extractor.getVisibility?.(node);
1785 const isAsync = this.extractor.isAsync?.(node);
1786 const isStatic = this.extractor.isStatic?.(node);
1787 const returnType = this.extractor.getReturnType?.(node, this.source);
1788 const extraProps: Partial<Node> = {
1789 docstring,
1790 signature,
1791 visibility,
1792 isAsync,
1793 isStatic,
1794 returnType,
1795 };
1796 if (receiverType) {
1797 extraProps.qualifiedName = this.composeReceiverQualifiedName(receiverType, name);
1798 }
1799
1800 const methodNode = this.createNode('method', name, node, extraProps);

Callers 2

visitNodeMethod · 0.95
extractFunctionMethod · 0.95

Calls 10

isInsideClassLikeNodeMethod · 0.95
visitFunctionBodyMethod · 0.95
extractFunctionMethod · 0.95
createNodeMethod · 0.95
extractDecoratorsForMethod · 0.95
getChildByFieldFunction · 0.90
getPrecedingDocstringFunction · 0.90
extractNameFunction · 0.85

Tested by

no test coverage detected