返回 DeepSeek-Reasonix
workspaceTreeSearch.ts
根目录 / desktop / frontend / src / lib / workspaceTreeSearch.ts
1 import type { DirEntry } from "./types";
2
3 export interface WorkspaceSearchRow {
4 path: string;
5 entry: DirEntry;
6 }
7
8 function basename(path: string): string {
9 const parts = path.split("/").filter(Boolean);
10 return parts[parts.length - 1] || path;
11 }
12
13 function treeSearchPath(entry: DirEntry): string {
14 const path = (entry.path || entry.name).replace(/\\/g, "/");
15 if (!entry.isDir || path.endsWith("/")) return path;
16 return path + "/";
17 }
18
19 export function mergeWorkspaceSearchResults(rows: WorkspaceSearchRow[], results: DirEntry[] | null): WorkspaceSearchRow[] {
20 if (!results || results.length === 0) return rows;
21 const merged = [...rows];
22 const seen = new Set(rows.map((row) => row.path));
23 for (const result of results) {
24 const path = treeSearchPath(result);
25 if (seen.has(path)) continue;
26 merged.push({ path, entry: { ...result, name: result.displayName || basename(path) } });
27 seen.add(path);
28 }
29 return merged;
30 }
31
31 lines TYPESCRIPT