(nodes: readonly GraphNode[], filePath: string, range?: SourceFocusRange)
| 33 | } |
| 34 | |
| 35 | export function readerGraphFocus(nodes: readonly GraphNode[], filePath: string, range?: SourceFocusRange): { ids: Set<number>; message: string } { |
| 36 | const fileNodes = nodes.filter((node) => node.file_path && normalizedPath(node.file_path) === normalizedPath(filePath)); |
| 37 | if (fileNodes.length === 0) return { ids: new Set(), message: `${filePath} is not in the loaded graph layout.` }; |
| 38 | if (range) { |
| 39 | const overlapping = fileNodes.filter((node) => !['File', 'Folder', 'Module', 'Package', 'Namespace'].includes(node.label) |
| 40 | && node.start_line !== undefined && node.start_line <= range.endLine |
| 41 | && (node.end_line ?? node.start_line) >= range.startLine); |
| 42 | const symbols = overlapping.filter((node) => !['Class', 'Interface', 'Struct', 'Enum'].includes(node.label)); |
| 43 | const selected = symbols.length > 0 ? symbols : overlapping; |
| 44 | if (selected.length > 0) return { ids: new Set(selected.map((node) => node.id)), message: '' }; |
| 45 | return { ids: new Set(fileNodes.map((node) => node.id)), message: 'No indexed symbol overlaps this source range. Showing the file.' }; |
| 46 | } |
| 47 | return { ids: new Set(fileNodes.map((node) => node.id)), message: '' }; |
| 48 | } |
no test coverage detected