( candidates: ReadonlyArray<C>, source: string )
| 1024 | * just for those. Mirrored in the kernel (go.rs `go_scoped_fn_ref_scopes`). |
| 1025 | */ |
| 1026 | export function goScopedFnRefScopes<C extends { name: string; fromNodeId: string; goNode?: SyntaxNode }>( |
| 1027 | candidates: ReadonlyArray<C>, |
| 1028 | source: string |
| 1029 | ): Map<C, number> { |
| 1030 | const groups = new Map<string, C[]>(); |
| 1031 | for (const c of candidates) { |
| 1032 | if (!c.goNode || c.name.includes('.')) continue; |
| 1033 | const key = `${c.fromNodeId}|${c.name}`; |
| 1034 | const group = groups.get(key); |
| 1035 | if (group) group.push(c); |
| 1036 | else groups.set(key, [c]); |
| 1037 | } |
| 1038 | const sites = new Map<C, GoFnRefSite>(); |
| 1039 | const units = new Map<number, SyntaxNode>(); |
| 1040 | const names = new Set<string>(); |
| 1041 | for (const group of groups.values()) { |
| 1042 | if (group.length < 2) continue; |
| 1043 | for (const c of group) { |
| 1044 | const site = goFnRefSite(c.goNode!); |
| 1045 | if (!site.unit) continue; |
| 1046 | sites.set(c, site); |
| 1047 | units.set(site.unit.id, site.unit); |
| 1048 | names.add(c.name); |
| 1049 | } |
| 1050 | } |
| 1051 | const out = new Map<C, number>(); |
| 1052 | if (units.size === 0) return out; |
| 1053 | const bound = goLocalBindings(units.values(), names, source); |
| 1054 | for (const [c, site] of sites) { |
| 1055 | if (bound.has(`${site.unit!.id}|${c.name}`)) out.set(c, site.scope); |
| 1056 | } |
| 1057 | return out; |
| 1058 | } |
no test coverage detected