MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / resolveSubject

Function resolveSubject

graph-ui/src/compiler/subject-resolver.ts:200–262  ·  view source on GitHub ↗
(
    source: SubjectSource,
    root: string,
    name: string,
    opts: ProviderQueryOptions = {},
)

Source from the content-addressed store, hash-verified

198 * chat turn with no answer at all.
199 */
200export 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,

Callers 3

compileFactsFunction · 0.90

Calls 7

twinTargetOfFunction · 0.90
bareNameOfFunction · 0.85
subjectScoreFunction · 0.85
orderCandidatesFunction · 0.85
searchSymbolsMethod · 0.65
declarationLineOfMethod · 0.65
resolveSymbolAtMethod · 0.65

Tested by

no test coverage detected