(
source: SubjectSource,
root: string,
name: string,
opts: ProviderQueryOptions = {},
)
| 198 | * chat turn with no answer at all. |
| 199 | */ |
| 200 | export async function resolveSubject( |
| 201 | source: SubjectSource, |
| 202 | root: string, |
| 203 | name: string, |
| 204 | opts: ProviderQueryOptions = {}, |
| 205 | ): Promise<ResolvedSubject | undefined> { |
| 206 | const bare = bareNameOf(name); |
| 207 | if (bare.length === 0) { |
| 208 | return undefined; |
| 209 | } |
| 210 | const hits = await source |
| 211 | .searchSymbols(root, bare, SUBJECT_SEARCH_LIMIT, opts) |
| 212 | .catch(() => [] as SymbolSearchHit[]); |
| 213 | const usable = hits.filter( |
| 214 | (hit) => subjectScore(hit, name) > 0 && (hit.filePath ?? '').length > 0, |
| 215 | ); |
| 216 | const ordered = orderCandidates(usable, name); |
| 217 | const best = ordered[0]; |
| 218 | if (best === undefined) { |
| 219 | return undefined; |
| 220 | } |
| 221 | const filePath = best.filePath ?? ''; |
| 222 | const line = best.line ?? (await source |
| 223 | .declarationLineOf(root, filePath, best.name, opts) |
| 224 | .catch(() => undefined)); |
| 225 | |
| 226 | // The declaration line is what is resolved against, never a call line: the |
| 227 | // same rule the closure walk states, and for the same reason. |
| 228 | if (line !== undefined) { |
| 229 | const resolved = await source |
| 230 | .resolveSymbolAt(root, filePath, line, opts) |
| 231 | .catch(() => undefined); |
| 232 | if (resolved?.kind === 'ok') { |
| 233 | return { |
| 234 | symbol: resolved.symbol, |
| 235 | candidates: ordered, |
| 236 | alternatives: ordered.slice(1), |
| 237 | ambiguous: ordered.length > 1 |
| 238 | && subjectScore(ordered[1], name) === subjectScore(best, name), |
| 239 | }; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // The index named a place but would not resolve it. The place is still the |
| 244 | // honest answer; what it lacks is a `nodeId`, and every consumer reads that |
| 245 | // absence as "not indexed as a node", which is exactly what happened. |
| 246 | const fallback = twinTargetOf({ |
| 247 | name: best.name, |
| 248 | qualifiedName: best.qualifiedName, |
| 249 | kind: best.kind, |
| 250 | filePath, |
| 251 | startLine: line, |
| 252 | }); |
| 253 | if (fallback === undefined) { |
| 254 | return undefined; |
| 255 | } |
| 256 | return { |
| 257 | symbol: fallback, |
no test coverage detected