fix(frameworks): a framework resolves only references written in its own languages

Merged
CO
2mo ago
+270-11

Problem

ReferenceResolver.resolveOneInner's Strategy 1 ran every detected framework's resolve() on every reference, whatever its language. Each FrameworkResolver declares languages, but only extraction read it (getApplicableFrameworks in parse-worker.ts / tree-sitter.ts). gateFrameworkLanguage only rejects a target across a code boundary, and passes every calls result, so a JS framework's naming rule could still resolve a Go reference to a Go node.

In etcd (Express is detected there by the file-content scan; there's no package.json), 7 Go references carried {"framework":"express","resolvedBy":"framework"}. One example: func (s *mockServer) Logger() *zap.Logger linked its result type to the method itself, through Express's logger middleware rule.

Several resolvers had already grown their own if (ref.language …) return null for this (React #2211, Vue, SwiftUI/UIKit/Vapor, Spring after #1825, Go since #2408). Express, NestJS, Angular Router, Django/Flask/FastAPI, Rails, Laravel, Play, Drupal, ASP.NET, Rust and CICS had none, and Svelte had one only for $store subscriptions.

Fix

  • New getResolvingFrameworks(detected, language) in frameworks/index.ts. Strategy 1 now loops only over the frameworks that read the reference's language: resolveLanguages if set, else languages, and frameworks declaring neither stay universal (Vue, Nuxt, Astro). The per-language list is memoized on the resolver and cleared in initialize().
  • New optional FrameworkResolver.resolveLanguages, for a resolver whose resolve() reads languages it extracts nothing from. Widening languages instead would run extract() on those files, and an applicable framework with extract() also takes a file off the kernel's deferred-decode path. Two resolvers need it:
    • svelte: ['svelte', 'typescript', 'javascript']. SvelteKit route modules (+page.server.js, hooks.server.ts) import $lib/… / $app/…, and Svelte 5 runes live in .svelte.ts / .svelte.js. Without this, svelte-realworld loses 12 $lib import edges from .js route modules.
    • aspnet: ['csharp', 'razor']. A Razor page's @model IndexModel names the PageModel in the code-behind beside it. Its folder namespace (…Pages.Basket) is never @using-imported, so only ASP.NET's beside-the-page pick finds it. Without this, eShopOnWeb loses 4 correct @model edges, and 34 more get re-resolved by plain name matching.
  • claimsReference() deliberately stays universal (there's a comment at the pre-filter). Narrowing it too dropped 858 correct protobuf C++ calls written with a leading :: (::_pbi::PrivateAccess::GenerateParseTable). The name pre-filter reads no leading ::, and those calls get past it only because the Swift ↔ Objective-C bridge (detected because protobuf ships 3 .swift files) claims any name with a : in it. A C++-only repo already drops them (rocksdb: 822 refs). I've filed that as a follow-up; once the pre-filter reads a leading ::, claims can be narrowed the same way.
  • Removed the stale "languages gates only extraction" comments in react.ts / swift.ts.

Cross-language resolvers audited

Each one lists the language its references are written in, so none is affected:

resolverresolve languagesevidence (framework edges, unchanged)
Drupal routing.yml → PHP controllerphp, yamladmin-toolbar: 16 from yaml, 31 from php
React Native bridge (JS → native)JS/TS/TSX/JSX (+objc for extraction)rn-geolocation 4, async-storage 16
Swift ↔ Objective-C bridgeswift, objcasync-storage 11, expo-wechat 1, protobuf 16
Expo modules (native side resolves nothing; JS side)swift,kotlin / TS, TSX, JS, JSXexpo-wechat 1
Fabric view (resolves nothing; a synthesizer bridges)——
SvelteKit $lib / runessvelte + TS/JS via resolveLanguagessvelte-realworld 12 from .js
ASP.NET Razor @modelcsharp + razor via resolveLanguageseShopOnWeb 38 from .cshtml

Open PRs that add bridge resolvers already declare their source languages: #878 (Tauri: the JS family + svelte + rust) and #714 (Salesforce). #2331's Lua→Rust bridge isn't a FrameworkResolver.

Validation

A/B on 28 repos at main 5ace306b (#2403 landed after; it touches sync's failed-ref tails only, so a fresh index is unaffected). The two arms used the same dist and the same kernel, differing only in the changed resolver files. Each repo was fully indexed per arm, and resolved edges were diffed by site (source, line, col, refName, refKind), with synthesized edges and unresolved statuses diffed too.

repolanguagesframework edgeschanged sites
etcdGo (+Express detected)14184 dropped, 2 retargeted, 1 metadata
harborGo, TS, Python17326 dropped
traefikGo, TSX6902 metadata
bitwardenTS, Rust5351 dropped
prometheus, gin-vue-admin, chushiGo + TS/Vue/JSX2974 / 90 / 390
protobufC++, Go, Java, C#, PHP, ObjC, Swift…160
admin-toolbar (Drupal), laravel-realworldPHP, YAML, JS47 / 120
rn-geolocation, async-storage, expo-obytes, expo-wechatRN / Expo4 / 31 / 3 / 20
eshop, clean-archC#, Razor / C#, TS, JSX55 / 130
fastapi-template, svelte-realworld, nuxt-movies, staluxPython+TSX, Svelte, Vue, Astro12 / 43 / 8 / 780
proshop, bookbrainz-site, outlineExpress/Koa + JSX/TSX20 / 26 / 2770
play-samples, spring-petclinic, vispanaScala/Java/routes, Java, Java+JS116 / 10 / 10
vapor-clean, carddemoSwift, COBOL/CICS39 / 240

No edge was added and no synthesized edge changed anywhere. Every changed site came from Express's naming rules applied to another language's code:

  • etcd, dropped (all wrong):
    • func (s *mockServer) Logger() *zap.Logger and func (s *EtcdServer) Logger() *zap.Logger: the result type linked to the method itself.
    • isLearnerReady(lg *zap.Logger, …): the parameter type linked to the EtcdServer.Logger method.
    • a.options.AuthStore.Authenticate(…) inside applierV3backend.Authenticate: linked to the calling method itself.
    • All four are now unresolved. zap is external, and the auth store's receiver type isn't inferred.
  • etcd, retargeted: srv.(AuthServer).Authenticate(ctx, in) at rpc_grpc.pb.go:1813,1820 went from the client's AuthClient.Authenticate to UnimplementedAuthServer.Authenticate. That's what name matching gives every other handler in the file (srv.(KVServer).Range → UnimplementedKVServer.Range). The exact target, the asserted interface's method, is a pre-existing Go gap, filed separately.
  • etcd / traefik, metadata only: Validate(…) and sanitizeDomains(…) keep their same-file target, now by exact name (0.7) instead of Express (0.8).
  • harbor, dropped (all wrong):
    • self.jaeger.validate() and self.otel.validate() were linked to InternalTLS.validate; the receivers are a JaegerExporter and an OtelExporter.
    • Four conf['trace'].validate()-style calls were linked to the calling validate function itself.
  • bitwarden, dropped (wrong): biometric_lock_system.inner.authenticate(…) inside the napi authenticate was linked to that function itself.

Tests

  • __tests__/framework-resolve-language.test.ts:
    • getResolvingFrameworks unit cases.
    • The etcd shape (Express beside Go): fails on main, passes here.
    • Two controls that pin the exemptions, both passing on main: a SvelteKit +page.server.ts import * as api from '$lib/api', and two Razor Index pages that each bind @model IndexModel to their own code-behind. Dropping typescript from Svelte's or razor from ASP.NET's resolveLanguages fails exactly the matching control.
  • tsc --noEmit is clean.
  • The 77 framework/bridge-related test files pass. Five timed out at 5 s while 28 repos were indexing next to them, and all five passed serially.
  • Full suite on this Windows box, run in parallel under load: 6381 passed and 44 failed. All 44 were in the load-sensitive sync, git, WAL, MCP and oversize files: 41 timeouts, an EBUSY, a 2.1 s vs 2.0 s timing bound, and one oversize-file assertion.
  • Rerun serially with long timeouts, those 22 files pass (976 of 978, 1 skipped). The one exception is function-ref's #1820 "module global" case, which hits its own 60 s limit on main 5ace306b too.

🤖 Generated with Claude Code