()
| 355 | } |
| 356 | |
| 357 | function listProjectDescriptors(): ProjectDescriptor[] { |
| 358 | const rootPaths = new Map<string, string>(); |
| 359 | for (const rootPath of getKnownRootPaths()) { |
| 360 | rootPaths.set(normalizeRootKey(rootPath), rootPath); |
| 361 | } |
| 362 | for (const [projectKey, rootPath] of discoveredProjectPaths.entries()) { |
| 363 | rootPaths.set(projectKey, rootPath); |
| 364 | } |
| 365 | for (const project of getAllProjects()) { |
| 366 | rootPaths.set(normalizeRootKey(project.rootPath), project.rootPath); |
| 367 | } |
| 368 | |
| 369 | const descriptors = Array.from(rootPaths.values()) |
| 370 | .map((rootPath) => buildProjectDescriptor(rootPath)) |
| 371 | .sort((a, b) => { |
| 372 | if (a.active !== b.active) return a.active ? -1 : 1; |
| 373 | if (a.source !== b.source) { |
| 374 | const weight: Record<ProjectDescriptor['source'], number> = { |
| 375 | root: 0, |
| 376 | subdirectory: 1, |
| 377 | ad_hoc: 2 |
| 378 | }; |
| 379 | return weight[a.source] - weight[b.source]; |
| 380 | } |
| 381 | return a.label.localeCompare(b.label); |
| 382 | }); |
| 383 | |
| 384 | const duplicates = new Set<string>(); |
| 385 | const counts = new Map<string, number>(); |
| 386 | for (const descriptor of descriptors) { |
| 387 | counts.set(descriptor.label, (counts.get(descriptor.label) ?? 0) + 1); |
| 388 | } |
| 389 | for (const [label, count] of counts.entries()) { |
| 390 | if (count > 1) { |
| 391 | duplicates.add(label); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | return descriptors.map((descriptor) => { |
| 396 | if (!duplicates.has(descriptor.label)) { |
| 397 | return descriptor; |
| 398 | } |
| 399 | |
| 400 | const containingRoot = getContainingKnownRoot(descriptor.rootPath); |
| 401 | const rootHint = |
| 402 | (containingRoot && getKnownRootLabel(containingRoot)) || |
| 403 | (containingRoot && path.basename(containingRoot)) || |
| 404 | path.basename(descriptor.rootPath); |
| 405 | |
| 406 | return { |
| 407 | ...descriptor, |
| 408 | label: `${descriptor.label} (${rootHint})` |
| 409 | }; |
| 410 | }); |
| 411 | } |
| 412 | |
| 413 | function getActiveProjectDescriptor(): ProjectDescriptor | undefined { |
| 414 | if (!activeProjectKey) return undefined; |
no test coverage detected