MCPcopy Create free account
hub / github.com/Effect-TS/effect / resolveSymbol

Function resolveSymbol

packages/tools/jsdocs/src/Jsdocs.ts:2321–2347  ·  view source on GitHub ↗
(link: ParsedInlineLink)

Source from the content-addressed store, hash-verified

2319 }
2320 }
2321 const resolveSymbol = (link: ParsedInlineLink): JSDocApiSeeLinkResolution | undefined => {
2322 if (link.symbol === undefined) return undefined
2323 const symbol = link.symbol
2324 const exact = bySourceRange.get(sourceRangeKey(symbol.file, symbol.range))
2325 if (exact !== undefined) return { _tag: "Resolved", apiId: exact.id, apiFqn: exact.apiFqn }
2326 const names = seeTargetNames(link)
2327 const candidates = (bySourceFile.get(symbol.file) ?? []).filter((api) =>
2328 apiMatchesSeeTarget(api, names) &&
2329 (rangeContains(symbol.range, api.source.range) ||
2330 rangeContains(api.source.range, symbol.range) ||
2331 rangeOverlaps(symbol.range, api.source.range))
2332 ).sort((self, that) => rangeWidth(self.source.range) - rangeWidth(that.source.range))
2333 const unique = Array.from(new Map(candidates.map((candidate) => [candidate.id, candidate])).values())
2334 if (unique.length === 1) return { _tag: "Resolved", apiId: unique[0].id, apiFqn: unique[0].apiFqn }
2335 if (unique.length > 1) {
2336 return { _tag: "Unresolved", reason: "ambiguous", candidates: unique.map((candidate) => candidate.id) }
2337 }
2338 const sameFileByName = (bySourceFile.get(symbol.file) ?? []).filter((api) => apiMatchesSeeTarget(api, names))
2339 const uniqueByName = Array.from(new Map(sameFileByName.map((candidate) => [candidate.id, candidate])).values())
2340 if (uniqueByName.length === 1) {
2341 return { _tag: "Resolved", apiId: uniqueByName[0].id, apiFqn: uniqueByName[0].apiFqn }
2342 }
2343 if (uniqueByName.length > 1) {
2344 return { _tag: "Unresolved", reason: "ambiguous", candidates: uniqueByName.map((candidate) => candidate.id) }
2345 }
2346 return undefined
2347 }
2348 return (
2349 context: { readonly moduleName: string; readonly namespacePath: ReadonlyArray<string> },
2350 link: ParsedInlineLink

Callers 1

Calls 10

sourceRangeKeyFunction · 0.85
seeTargetNamesFunction · 0.85
apiMatchesSeeTargetFunction · 0.85
rangeContainsFunction · 0.85
rangeOverlapsFunction · 0.85
rangeWidthFunction · 0.85
fromMethod · 0.80
getMethod · 0.65
filterMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected