MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / buildVisibleFilePickerTree

Function buildVisibleFilePickerTree

packages/core/src/widgets/filePicker.ts:92–131  ·  view source on GitHub ↗
(
  nodes: readonly FileNode[],
  matcher: ((node: FileNode) => boolean) | null,
  includeHidden: boolean,
)

Source from the content-addressed store, hash-verified

90}
91
92function buildVisibleFilePickerTree(
93 nodes: readonly FileNode[],
94 matcher: ((node: FileNode) => boolean) | null,
95 includeHidden: boolean,
96): readonly VisibleFilePickerNode[] {
97 const visible: VisibleFilePickerNode[] = [];
98
99 for (let i = 0; i < nodes.length; i++) {
100 const node = nodes[i];
101 if (node === undefined) continue;
102 if (!includeHidden && isHiddenFileNode(node)) continue;
103
104 const visibleChildren =
105 node.children && node.children.length > 0
106 ? buildVisibleFilePickerTree(node.children, matcher, includeHidden)
107 : EMPTY_VISIBLE_FILE_PICKER_NODES;
108 const hasChildren =
109 node.type === "directory" && (matcher === null || visibleChildren.length > 0);
110
111 const matchesSelf = matcher === null || matcher(node);
112 const keep =
113 matcher === null
114 ? true
115 : node.type === "directory"
116 ? matchesSelf || visibleChildren.length > 0
117 : matchesSelf;
118
119 if (!keep) continue;
120
121 visible.push(
122 Object.freeze({
123 node,
124 hasChildren,
125 children: visibleChildren,
126 }),
127 );
128 }
129
130 return visible.length === 0 ? EMPTY_VISIBLE_FILE_PICKER_NODES : Object.freeze(visible);
131}
132
133function appendVisibleFilePickerNodes(
134 entries: readonly VisibleFilePickerNode[],

Callers 1

Calls 2

isHiddenFileNodeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected