(
locations: CodeNavLocation[],
context: {
sourceFilePath: string;
changedFiles: string[];
isTestFile: boolean;
},
cap = 50,
)
| 277 | // --------------------------------------------------------------------------- |
| 278 | |
| 279 | export function rankLocations( |
| 280 | locations: CodeNavLocation[], |
| 281 | context: { |
| 282 | sourceFilePath: string; |
| 283 | changedFiles: string[]; |
| 284 | isTestFile: boolean; |
| 285 | }, |
| 286 | cap = 50, |
| 287 | ): { definitions: CodeNavLocation[]; references: CodeNavLocation[]; capped: boolean } { |
| 288 | const capped = locations.length > cap; |
| 289 | const changedSet = new Set(context.changedFiles); |
| 290 | |
| 291 | function score(loc: CodeNavLocation): number { |
| 292 | let s = 0; |
| 293 | |
| 294 | if (loc.filePath === context.sourceFilePath) s += 1000; |
| 295 | else if (changedSet.has(loc.filePath)) s += 500; |
| 296 | else if (sameDirectory(loc.filePath, context.sourceFilePath)) s += 200; |
| 297 | |
| 298 | if (isTestFile(loc.filePath) && !context.isTestFile) s -= 300; |
| 299 | |
| 300 | if (loc.kind === "definition") s += 100; |
| 301 | if (loc.confidence === "likely") s += 50; |
| 302 | |
| 303 | return s; |
| 304 | } |
| 305 | |
| 306 | const sorted = [...locations].sort((a, b) => score(b) - score(a)); |
| 307 | const truncated = sorted.slice(0, cap); |
| 308 | |
| 309 | return { |
| 310 | definitions: truncated.filter((l) => l.kind === "definition"), |
| 311 | references: truncated.filter((l) => l.kind === "reference"), |
| 312 | capped, |
| 313 | }; |
| 314 | } |
| 315 | |
| 316 | // --------------------------------------------------------------------------- |
| 317 | // Changed files extraction from unified diff patch |
no test coverage detected