* Extract a method
(node: SyntaxNode)
| 2919 | * Extract a method |
| 2920 | */ |
| 2921 | private extractMethod(node: SyntaxNode): void { |
| 2922 | if (!this.extractor) return; |
| 2923 | |
| 2924 | // For languages with receiver types (Go, Rust), include receiver in qualified name |
| 2925 | // so FTS can match "scrapeLoop.run" → qualified_name "...::scrapeLoop::run" |
| 2926 | const receiverType = this.extractor.getReceiverType?.(node, this.source); |
| 2927 | |
| 2928 | // For most languages, only extract as method if inside a class-like node |
| 2929 | // Languages with methodsAreTopLevel (e.g. Go) always treat them as methods |
| 2930 | // Languages with getReceiverType (e.g. Rust) extract as method when receiver is found |
| 2931 | if (!this.isInsideClassLikeNode() && !this.extractor.methodsAreTopLevel && !receiverType) { |
| 2932 | // Skip method_definition nodes inside object literals (getters/setters/methods |
| 2933 | // in inline objects). These are ephemeral and create noise (e.g., Svelte context |
| 2934 | // objects: `ctx.set({ get view() { ... } })`). |
| 2935 | if (node.parent?.type === 'object' || node.parent?.type === 'object_expression') { |
| 2936 | const body = this.extractor.resolveBody?.(node, this.extractor.bodyField) |
| 2937 | ?? getChildByField(node, this.extractor.bodyField); |
| 2938 | this.visitParameterDefaults(node, body); |
| 2939 | if (body) { |
| 2940 | this.visitFunctionBody(body, ''); |
| 2941 | } |
| 2942 | return; |
| 2943 | } |
| 2944 | // Not inside a class-like node and no receiver type, treat as function |
| 2945 | this.extractFunction(node); |
| 2946 | return; |
| 2947 | } |
| 2948 | |
| 2949 | const name = extractName(node, this.source, this.extractor); |
| 2950 | |
| 2951 | // Check for misparse artifacts (e.g. C++ "switch" inside macro-confused class body) |
| 2952 | if (this.extractor.isMisparsedFunction?.(name, node)) { |
| 2953 | const body = this.extractor.resolveBody?.(node, this.extractor.bodyField) |
| 2954 | ?? getChildByField(node, this.extractor.bodyField); |
| 2955 | if (body) { |
| 2956 | this.visitFunctionBody(body, ''); |
| 2957 | } |
| 2958 | return; |
| 2959 | } |
| 2960 | |
| 2961 | const docstring = this.docstringFor(node); |
| 2962 | const signature = this.extractor.getSignature?.(node, this.signatureSource); |
| 2963 | const visibility = this.extractor.getVisibility?.(node); |
| 2964 | const isAsync = this.extractor.isAsync?.(node); |
| 2965 | const isStatic = this.extractor.isStatic?.(node); |
| 2966 | // Only persist abstract when true — a false return must not mint `isAbstract: false` |
| 2967 | // on every ordinary method (breaks kernel↔wasm parity JSON equality). |
| 2968 | const isAbstract = this.extractor.isAbstract?.(node) ? true : undefined; |
| 2969 | const returnType = this.extractor.getReturnType?.(node, this.source); |
| 2970 | // A method that is a top-level declaration (Go: `func (r *T) Name()`) has |
| 2971 | // the same exportedness rule as a function — the name's case — and a |
| 2972 | // consumer asking "can another package name this?" needs it on methods |
| 2973 | // too. Class members keep the flag unset: their reachability is the |
| 2974 | // class's, and the languages whose isExported walks the parent chain |
| 2975 | // (JS/TS) would otherwise re-mark every member of an exported class. |
| 2976 | const isExported = this.extractor.methodsAreTopLevel |
| 2977 | ? this.extractor.isExported?.(node, this.source) |
| 2978 | : undefined; |
no test coverage detected