* Resolve a symbol by name using indexed queries instead of scanning all files. * Uses getNodesByName (O(log n) indexed lookup) instead of iterating every file.
( name: string, kind: string | null, preferredDirs: string[], context: ResolutionContext, kinds?: Set<string> )
| 177 | * Uses getNodesByName (O(log n) indexed lookup) instead of iterating every file. |
| 178 | */ |
| 179 | function resolveByNameAndKind( |
| 180 | name: string, |
| 181 | kind: string | null, |
| 182 | preferredDirs: string[], |
| 183 | context: ResolutionContext, |
| 184 | kinds?: Set<string> |
| 185 | ): string | null { |
| 186 | const candidates = context.getNodesByName(name); |
| 187 | if (candidates.length === 0) return null; |
| 188 | |
| 189 | // Filter by kind |
| 190 | const kindFiltered = candidates.filter((n) => { |
| 191 | if (kinds) return kinds.has(n.kind); |
| 192 | if (kind) return n.kind === kind; |
| 193 | return true; |
| 194 | }); |
| 195 | |
| 196 | if (kindFiltered.length === 0) return null; |
| 197 | |
| 198 | // Prefer candidates in framework-conventional directories |
| 199 | const preferred = kindFiltered.filter((n) => |
| 200 | preferredDirs.some((d) => n.filePath.includes(`/${d}/`)) |
| 201 | ); |
| 202 | |
| 203 | if (preferred.length > 0) return preferred[0]!.id; |
| 204 | |
| 205 | // Fall back to any match |
| 206 | return kindFiltered[0]!.id; |
| 207 | } |
no test coverage detected