All files / client/src/lib source-navigation.ts

100% Statements 7/7
100% Branches 6/6
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                          9x 5x       4x 7x   4x    
import type { SourceLocation } from "@shared/source-project";
 
export interface SourceNavigationTab {
  id: string;
  name: string;
  path?: string;
}
 
/** Resolve only the full project path; basenames are intentionally ambiguous. */
export function findTabForSourceLocation(
  tabs: readonly SourceNavigationTab[],
  location: SourceLocation,
): SourceNavigationTab | undefined {
  const exactPath = tabs.find((tab) => tab.path === location.file);
  if (exactPath) return exactPath;
 
  // Legacy tabs may have no path. Only use their name when it is unique;
  // never guess between duplicate basenames.
  const legacyMatches = tabs.filter(
    (tab) => !tab.path && tab.name === location.file,
  );
  return legacyMatches.length === 1 ? legacyMatches[0] : undefined;
}