MCPcopy
hub / github.com/anomalyco/opencode / createFileEntries

Function createFileEntries

packages/app/src/components/dialog-select-file.tsx:139–179  ·  view source on GitHub ↗
(props: {
  file: ReturnType<typeof useFile>
  tabs: () => ReturnType<ReturnType<typeof useLayout>["tabs"]>
  language: ReturnType<typeof useLanguage>
})

Source from the content-addressed store, hash-verified

137}
138
139function createFileEntries(props: {
140 file: ReturnType<typeof useFile>
141 tabs: () => ReturnType<ReturnType<typeof useLayout>["tabs"]>
142 language: ReturnType<typeof useLanguage>
143}) {
144 const tabState = createSessionTabs({
145 tabs: props.tabs,
146 pathFromTab: props.file.pathFromTab,
147 normalizeTab: (tab) => (tab.startsWith("file://") ? props.file.tab(tab) : tab),
148 })
149 const recent = createMemo(() => {
150 const all = tabState.openedTabs()
151 const active = tabState.activeFileTab()
152 const order = active ? [active, ...all.filter((item) => item !== active)] : all
153 const seen = new Set<string>()
154 const category = props.language.t("palette.group.files")
155 const items: Entry[] = []
156
157 for (const item of order) {
158 const path = props.file.pathFromTab(item)
159 if (!path) continue
160 if (seen.has(path)) continue
161 seen.add(path)
162 items.push(createFileEntry(path, category))
163 }
164
165 return items.slice(0, ENTRY_LIMIT)
166 })
167
168 const root = createMemo(() => {
169 const category = props.language.t("palette.group.files")
170 const nodes = props.file.tree.children("")
171 const paths = nodes
172 .filter((node) => node.type === "file")
173 .map((node) => node.path)
174 .sort((a, b) => a.localeCompare(b))
175 return paths.slice(0, ENTRY_LIMIT).map((path) => createFileEntry(path, category))
176 })
177
178 return { recent, root }
179}
180
181function createSessionEntries(props: {
182 workspaces: () => string[]

Callers 1

DialogSelectFileFunction · 0.85

Calls 5

createSessionTabsFunction · 0.90
createFileEntryFunction · 0.85
pushMethod · 0.80
addMethod · 0.65
childrenMethod · 0.45

Tested by

no test coverage detected