From 4597c687fa8c3928530cdb609f40d549b5874f7e Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Tue, 9 Jun 2026 22:04:17 -0400 Subject: [PATCH] fix(core): prefer shorter paths for tied search scores --- packages/core/src/filesystem/search.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/core/src/filesystem/search.ts b/packages/core/src/filesystem/search.ts index 80a575143..e78f6243e 100644 --- a/packages/core/src/filesystem/search.ts +++ b/packages/core/src/filesystem/search.ts @@ -202,18 +202,30 @@ export const fffLayer = Layer.effect( if (input.type === "file") { const found = result.value.fileSearch(input.query.trim(), options) if (!found.ok) throw found.error - return found.value.items.map((item) => ({ path: item.relativePath, type: "file" as const })) + return found.value.items.map((item, index) => ({ + path: item.relativePath, + type: "file" as const, + score: found.value.scores[index]?.total ?? 0, + })) } if (input.type === "directory") { const found = result.value.directorySearch(input.query.trim(), options) if (!found.ok) throw found.error - return found.value.items.map((item) => ({ path: item.relativePath, type: "directory" as const })) + return found.value.items.map((item, index) => ({ + path: item.relativePath, + type: "directory" as const, + score: found.value.scores[index]?.total ?? 0, + })) } const found = result.value.mixedSearch(input.query.trim(), options) if (!found.ok) throw found.error - return found.value.items.map((item) => ({ path: item.item.relativePath, type: item.type })) + return found.value.items.map((item, index) => ({ + path: item.item.relativePath, + type: item.type, + score: found.value.scores[index]?.total ?? 0, + })) })() - return items.map((item) => { + return items.sort((a, b) => b.score - a.score || a.path.length - b.path.length).map((item) => { const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "") const absolute = path.resolve(location.directory, relative) return new FileSystem.Entry({