MCPcopy Create free account
hub / github.com/backnotprop/plannotator / resolveCodeNav

Function resolveCodeNav

packages/shared/code-nav.ts:366–432  ·  view source on GitHub ↗
(
  runtime: CodeNavRuntime,
  request: CodeNavRequest,
  cwd: string,
  changedFiles: string[],
)

Source from the content-addressed store, hash-verified

364let rgAvailable: boolean | null = null;
365
366export async function resolveCodeNav(
367 runtime: CodeNavRuntime,
368 request: CodeNavRequest,
369 cwd: string,
370 changedFiles: string[],
371): Promise<CodeNavResponse> {
372 const start = Date.now();
373
374 if (rgAvailable === null) {
375 const check = await runtime.runCommand("rg", ["--version"], {
376 cwd,
377 timeoutMs: 2000,
378 });
379 rgAvailable = check.exitCode === 0;
380 }
381
382 if (!rgAvailable) {
383 return {
384 backend: "unavailable",
385 complete: true,
386 definitions: [],
387 references: [],
388 searchScope: "head",
389 stats: { elapsedMs: Date.now() - start, capped: false },
390 };
391 }
392
393 const args = buildRgArgs(request.symbol, request.language);
394
395 const result = await runtime.runCommand("rg", args, {
396 cwd,
397 timeoutMs: 5000,
398 });
399
400 // Exit code 1 = no matches (normal), exit code 2 = error
401 if (result.exitCode === 2) {
402 return {
403 backend: "search",
404 complete: true,
405 definitions: [],
406 references: [],
407 searchScope: "head",
408 stats: { elapsedMs: Date.now() - start, capped: false },
409 };
410 }
411
412 const locations = parseRgJsonOutput(
413 result.stdout,
414 request.symbol,
415 request.language,
416 );
417
418 const ranked = rankLocations(locations, {
419 sourceFilePath: request.filePath,
420 changedFiles,
421 isTestFile: isTestFile(request.filePath),
422 });
423

Callers 2

handleCodeNavResolveFunction · 0.90
startReviewServerFunction · 0.85

Calls 4

buildRgArgsFunction · 0.85
parseRgJsonOutputFunction · 0.85
rankLocationsFunction · 0.85
isTestFileFunction · 0.85

Tested by

no test coverage detected