GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(app): populate project picker from home (#41158) · Ichinose-Kazuki/opencode@4a4ca8e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app/src/components
    • directory-picker-domain.test.ts
    • directory-picker-domain.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/components/directory-picker-domain.test.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/components/directory-picker-domain.test.ts
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ test("resolves directory autocomplete from the current browser root", async () =
139139
directories.push(input.location?.directory ?? "")
140140
return Promise.resolve({ data: [] })
141141
},
142+
list: () => Promise.resolve({ data: [] }),
142143
},
143144
},
144145
} as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"]
@@ -152,6 +153,70 @@ test("resolves directory autocomplete from the current browser root", async () =
152153
expect(directories).toEqual(["/repo", "/repo/src"])
153154
})
154155

156+
test("keeps indexed directory results for servers that support empty search", async () => {
157+
const sdk = {
158+
api: {
159+
file: {
160+
find: () => Promise.resolve({ data: [{ path: "projects/", type: "directory" }] }),
161+
list: () => Promise.reject(new Error("listing should not run when search returns results")),
162+
},
163+
},
164+
} as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"]
165+
const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" })
166+
167+
expect(await search("")).toEqual(["/home/luke/projects"])
168+
})
169+
170+
test("lists the default directory when empty search is unsupported", async () => {
171+
const calls: string[] = []
172+
const directories = Array.from({ length: 60 }, (_, index) => ({
173+
path: `project-${index}/`,
174+
type: "directory" as const,
175+
}))
176+
const sdk = {
177+
api: {
178+
file: {
179+
find: () => Promise.resolve({ data: [] }),
180+
list: (input: { location?: { directory?: string } }) => {
181+
calls.push(input.location?.directory ?? "")
182+
return Promise.resolve({
183+
data: [
184+
...directories,
185+
{ path: "README.md", type: "file" },
186+
],
187+
})
188+
},
189+
},
190+
},
191+
} as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"]
192+
const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" })
193+
194+
const results = await search("")
195+
expect(results).toHaveLength(60)
196+
expect(results.at(-1)).toBe("/home/luke/project-59")
197+
expect(calls).toEqual(["/home/luke"])
198+
})
199+
200+
test("matches the default directory listing when typed search is unsupported", async () => {
201+
const sdk = {
202+
api: {
203+
file: {
204+
find: () => Promise.resolve({ data: [] }),
205+
list: () =>
206+
Promise.resolve({
207+
data: [
208+
{ path: "Documents/", type: "directory" },
209+
{ path: "Downloads/", type: "directory" },
210+
],
211+
}),
212+
},
213+
},
214+
} as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"]
215+
const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/home/luke" })
216+
217+
expect(await search("documents")).toEqual(["/home/luke/Documents"])
218+
})
219+
155220
test("searches from an absolute root without a default base", async () => {
156221
const directories: string[] = []
157222
const sdk = {
Collapse file

‎packages/app/src/components/directory-picker-domain.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/components/directory-picker-domain.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,14 @@ export function createDirectorySearch(args: { sdk: ServerSDK; base: () => string
379379
.then((result) => result.data.map((entry) => entry.path))
380380
.catch(() => [])
381381
if (!active()) return []
382-
return results.map((path) => joinPickerPath(input.directory, path)).slice(0, 50)
382+
if (results.length) {
383+
return results.map((path) => joinPickerPath(input.directory, path)).slice(0, 50)
384+
}
385+
const fallback = query
386+
? await match(input.directory, query, 50)
387+
: (await directories(input.directory)).map((item) => item.absolute)
388+
if (!active()) return []
389+
return fallback
383390
}
384391
const segments = query.replace(/^\/+/, "").split("/")
385392
const head = segments.slice(0, -1).filter((part) => part && part !== ".")

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.