Просмотр исходного кода

core: keep windows @mentions finding project files

Shoubhit Dash 4 месяцев назад
Родитель
Сommit
19a503aa7e

+ 3 - 1
packages/app/src/components/prompt-input.tsx

@@ -573,7 +573,8 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       const pinned: AtOption[] = open.map((path) => ({ type: "file", path, display: path, recent: true }))
       if (!query.trim()) return [...agents, ...pinned]
       const pathy = /[./\\]/.test(query)
-      const paths = await files.searchFiles(query)
+      const seek = query.replaceAll("\\", "/")
+      const paths = await files.searchFiles(seek)
       const fileOptions: AtOption[] = paths
         .filter((path) => !seen.has(path))
         .map((path) => ({ type: "file", path, display: path }))
@@ -583,6 +584,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     key: atKey,
     filterKeys: ["display"],
     stale: false,
+    fuzzy: (query) => !/[./\\]/.test(query),
     groupBy: (item) => {
       if (item.type === "agent") return "agent"
       if (item.recent) return "recent"

+ 5 - 1
packages/opencode/test/file/fff.test.ts

@@ -1,4 +1,4 @@
-import { describe, expect, test } from "bun:test"
+import { afterEach, describe, expect, test } from "bun:test"
 import fs from "fs/promises"
 import path from "path"
 import { tmpdir } from "../fixture/fixture"
@@ -10,6 +10,10 @@ async function write(file: string, body: string) {
   await fs.writeFile(file, body)
 }
 
+afterEach(async () => {
+  await Instance.disposeAll()
+})
+
 describe("file.fff", () => {
   test("allowed respects hidden filter", async () => {
     expect(Fff.allowed({ rel: "visible.txt", hidden: true })).toBe(true)

+ 3 - 1
packages/ui/src/hooks/use-filtered-list.tsx

@@ -15,6 +15,7 @@ export interface FilteredListProps<T> {
   onSelect?: (value: T | undefined, index: number) => void
   noInitialSelection?: boolean
   stale?: boolean
+  fuzzy?: boolean | ((filter: string) => boolean)
 }
 
 export function useFilteredList<T>(props: FilteredListProps<T>) {
@@ -31,11 +32,12 @@ export function useFilteredList<T>(props: FilteredListProps<T>) {
     async ({ filter, items }) => {
       const query = filter ?? ""
       const needle = query.toLowerCase()
+      const fuzzy = typeof props.fuzzy === "function" ? props.fuzzy(query) : (props.fuzzy ?? true)
       const all = (await Promise.resolve(items)) || []
       const result = pipe(
         all,
         (x) => {
-          if (!needle) return x
+          if (!needle || !fuzzy) return x
           if (!props.filterKeys && Array.isArray(x) && x.every((e) => typeof e === "string")) {
             return fuzzysort.go(needle, x).map((x) => x.target) as T[]
           }