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