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

Method extractMethod

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

* Extract a method

(node: SyntaxNode)

Source from the content-addressed store, hash-verified

2800 * Extract a method
2801 */
2802 private extractMethod(node: SyntaxNode): void {
2803 if (!this.extractor) return;
2804
2805 // For languages with receiver types (Go, Rust), include receiver in qualified name
2806 // so FTS can match "scrapeLoop.run" → qualified_name "...::scrapeLoop::run"
2807 const receiverType = this.extractor.getReceiverType?.(node, this.source);
2808
2809 // For most languages, only extract as method if inside a class-like node
2810 // Languages with methodsAreTopLevel (e.g. Go) always treat them as methods
2811 // Languages with getReceiverType (e.g. Rust) extract as method when receiver is found
2812 if (!this.isInsideClassLikeNode() && !this.extractor.methodsAreTopLevel && !receiverType) {
2813 // Skip method_definition nodes inside object literals (getters/setters/methods
2814 // in inline objects). These are ephemeral and create noise (e.g., Svelte context
2815 // objects: `ctx.set({ get view() { ... } })`).
2816 if (node.parent?.type === 'object' || node.parent?.type === 'object_expression') {
2817 const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
2818 ?? getChildByField(node, this.extractor.bodyField);
2819 this.visitParameterDefaults(node, body);
2820 if (body) {
2821 this.visitFunctionBody(body, '');
2822 }
2823 return;
2824 }
2825 // Not inside a class-like node and no receiver type, treat as function
2826 this.extractFunction(node);
2827 return;
2828 }
2829
2830 const name = extractName(node, this.source, this.extractor);
2831
2832 // Check for misparse artifacts (e.g. C++ "switch" inside macro-confused class body)
2833 if (this.extractor.isMisparsedFunction?.(name, node)) {
2834 const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
2835 ?? getChildByField(node, this.extractor.bodyField);
2836 if (body) {
2837 this.visitFunctionBody(body, '');
2838 }
2839 return;
2840 }
2841
2842 const docstring = this.docstringFor(node);
2843 const signature = this.extractor.getSignature?.(node, this.signatureSource);
2844 const visibility = this.extractor.getVisibility?.(node);
2845 const isAsync = this.extractor.isAsync?.(node);
2846 const isStatic = this.extractor.isStatic?.(node);
2847 // Only persist abstract when true — a false return must not mint `isAbstract: false`
2848 // on every ordinary method (breaks kernel↔wasm parity JSON equality).
2849 const isAbstract = this.extractor.isAbstract?.(node) ? true : undefined;
2850 const returnType = this.extractor.getReturnType?.(node, this.source);
2851 // A method that is a top-level declaration (Go: `func (r *T) Name()`) has
2852 // the same exportedness rule as a function — the name's case — and a
2853 // consumer asking "can another package name this?" needs it on methods
2854 // too. Class members keep the flag unset: their reachability is the
2855 // class's, and the languages whose isExported walks the parent chain
2856 // (JS/TS) would otherwise re-mark every member of an exported class.
2857 const isExported = this.extractor.methodsAreTopLevel
2858 ? this.extractor.isExported?.(node, this.source)
2859 : undefined;

Callers 2

dispatchNodeMethod · 0.95
extractFunctionMethod · 0.95

Calls 12

isInsideClassLikeNodeMethod · 0.95
visitFunctionBodyMethod · 0.95
extractFunctionMethod · 0.95
docstringForMethod · 0.95
createNodeMethod · 0.95
extractDecoratorsForMethod · 0.95
getChildByFieldFunction · 0.90
extractNameFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected