Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/app/src/components/directory-picker-domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@ test("searches from an absolute root without a default base", async () => {
expect(directories).toEqual(["/"])
})

test("lists the base directory instead of fuzzy matching an empty query", async () => {
const listed: Array<{ location?: { directory?: string }; path?: string }> = []
const found: string[] = []
const sdk = {
api: {
file: {
list: (input: { location?: { directory?: string }; path?: string }) => {
listed.push(input)
return Promise.resolve({
data: [
{ path: "src/", type: "directory" },
{ path: "tests/", type: "directory" },
{ path: "README.md", type: "file" },
],
})
},
find: (input: { query?: string }) => {
found.push(input.query ?? "")
return Promise.resolve({ data: [] })
},
},
},
} as unknown as Parameters<typeof createDirectorySearch>[0]["sdk"]
const search = createDirectorySearch({ sdk, home: () => "/home/luke", base: () => "/repo" })

expect(await search("")).toEqual(["/repo/src", "/repo/tests"])
expect(found).toEqual([])
expect(listed).toEqual([{ location: { directory: "/repo" }, path: "" }])
})

test("identifies the next directory level to preload", () => {
expect(
preloadTreeDirectories("src/", [
Expand Down
19 changes: 7 additions & 12 deletions packages/app/src/components/directory-picker-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export function createDirectorySearch(args: { sdk: ServerSDK; base: () => string
const existing = cache.get(key)
if (existing) return existing
const request = args.sdk.api.file
.list({ location: { directory: key } })
.list({ location: { directory: key }, path: "" })
.then((result) => result.data)
.catch(() => [])
.then((nodes) =>
Expand Down Expand Up @@ -374,19 +374,14 @@ export function createDirectorySearch(args: { sdk: ServerSDK; base: () => string
const pathInput = raw.startsWith("~") || !!pickerRoot(raw) || raw.includes("/")
const query = normalizePickerDrive(input.path)
if (!pathInput) {
const results = await args.sdk.api.file
.find({ location: { directory: input.directory }, query, type: "directory", limit: 50 })
.then((result) => result.data.map((entry) => entry.path))
.catch(() => [])
if (!active()) return []
if (results.length) {
return results.map((path) => joinPickerPath(input.directory, path)).slice(0, 50)
}
const fallback = query
? await match(input.directory, query, 50)
const results = query
? await args.sdk.api.file
.find({ location: { directory: input.directory }, query, type: "directory", limit: 50 })
.then((result) => result.data.map((entry) => joinPickerPath(input.directory, entry.path)))
.catch(() => [])
: (await directories(input.directory)).map((item) => item.absolute)
if (!active()) return []
return fallback
return results.slice(0, 50)
}
const segments = query.replace(/^\/+/, "").split("/")
const head = segments.slice(0, -1).filter((part) => part && part !== ".")
Expand Down
Loading