fix(chat): rank @ mention files and directories together by match quality

Directories and files were rendered as fixed category blocks, so an
exact file match sat below unrelated directories. Merge both result
sets and rank them with the shared fuzzy scorer against the full
relative path. Multi-word queries now match tokens in any order
(longest token queries the server, the rest filter client-side), and
path truncation keeps the parent segments next to the file name so
index.md-heavy trees stay distinguishable.
This commit is contained in:
Bohdan Triapitsyn
2026-08-24 14:30:00 +03:00
parent 279fa8b691
commit 0918bee566
4 changed files with 153 additions and 85 deletions
+9 -16
View File
@@ -66,29 +66,22 @@ export const truncatePathMiddle = (
return source;
}
const prefixBudget = Math.max(0, maxLength - (fileName.length + 2));
if (prefixBudget <= 0) {
return `…/${fileName}`;
}
let prefix = '';
for (const segment of segments) {
// Keep the segments closest to the file name: in trees full of index.md the
// parent directory is the distinguishing part, so drop leading segments.
let suffix = fileName;
for (let i = segments.length - 1; i >= 0; i--) {
const segment = segments[i];
if (!segment) {
continue;
}
const candidate = prefix ? `${prefix}/${segment}` : segment;
if (candidate.length > prefixBudget) {
const candidate = `${segment}/${suffix}`;
if (candidate.length + 2 > maxLength) {
break;
}
prefix = candidate;
suffix = candidate;
}
if (!prefix) {
const first = segments[0] ?? '';
prefix = first ? first.slice(0, prefixBudget) : '';
}
return prefix ? `${prefix}…/${fileName}` : `…/${fileName}`;
return `…/${suffix}`;
};
const normalizePath = (value: string) => {