mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
feat(mentions): implement fuzzy search for file/folder mentions
Adds fuzzy search functionality using Fuse.js to improve file and folder search in mentions.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { mentionRegex } from "../../../src/shared/context-mentions"
|
import { mentionRegex } from "../../../src/shared/context-mentions"
|
||||||
|
import Fuse from "fuse.js"
|
||||||
|
|
||||||
export function insertMention(
|
export function insertMention(
|
||||||
text: string,
|
text: string,
|
||||||
@@ -147,13 +148,21 @@ export function getContextMenuOptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get matching items, separating by type
|
// Initialize Fuse instance for fuzzy search
|
||||||
const matchingItems = queryItems.filter((item) =>
|
const fuse = new Fuse(queryItems, {
|
||||||
item.value?.toLowerCase().includes(lowerQuery) ||
|
keys: ["value", "label", "description"],
|
||||||
item.label?.toLowerCase().includes(lowerQuery) ||
|
threshold: 0.6,
|
||||||
item.description?.toLowerCase().includes(lowerQuery)
|
shouldSort: true,
|
||||||
)
|
isCaseSensitive: false,
|
||||||
|
ignoreLocation: false,
|
||||||
|
minMatchCharLength: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Get fuzzy matching items
|
||||||
|
const fuseResults = query ? fuse.search(query) : []
|
||||||
|
const matchingItems = fuseResults.map(result => result.item)
|
||||||
|
|
||||||
|
// Separate matches by type
|
||||||
const fileMatches = matchingItems.filter(item =>
|
const fileMatches = matchingItems.filter(item =>
|
||||||
item.type === ContextMenuOptionType.File ||
|
item.type === ContextMenuOptionType.File ||
|
||||||
item.type === ContextMenuOptionType.Folder
|
item.type === ContextMenuOptionType.Folder
|
||||||
|
|||||||
Reference in New Issue
Block a user