MCPcopy Create free account
hub / github.com/SplootCode/splootcode / filterSuggestions

Function filterSuggestions

packages/editor/src/components/insert_box.tsx:27–86  ·  view source on GitHub ↗
(
  staticSuggestions: RenderedSuggestion[],
  staticSuggestionsKeys: Set<string>,
  autocompleters: CursorAutocompleter[],
  userInput: string
)

Source from the content-addressed store, hash-verified

25}
26
27async function filterSuggestions(
28 staticSuggestions: RenderedSuggestion[],
29 staticSuggestionsKeys: Set<string>,
30 autocompleters: CursorAutocompleter[],
31 userInput: string
32): Promise<RenderedSuggestion[]> {
33 if (autocompleters.length === 0) {
34 return []
35 }
36
37 const dynamicSuggestions: RenderedSuggestion[] = []
38 const dynamicSuggestionsKeys: Set<string> = new Set()
39 for (const autocompleter of autocompleters) {
40 const prefixSuggestions = await autocompleter.getPrefixSuggestions(userInput)
41 if (prefixSuggestions) {
42 if (userInput.length <= 1) {
43 return prefixSuggestions
44 }
45 const options: Fuse.IFuseOptions<RenderedSuggestion> = {
46 keys: [
47 { name: 'exactMatch', weight: 0.8 },
48 { name: 'searchTerms', weight: 0.1 },
49 { name: 'display', weight: 0.1 },
50 ],
51 isCaseSensitive: true,
52 threshold: 1.0,
53 distance: 0,
54 findAllMatches: false,
55 fieldNormWeight: 2.0,
56 }
57 const suggestions = prefixSuggestions
58 const fuse = new Fuse(suggestions, options)
59 const results = fuse.search(userInput).map((res) => res.item)
60 return results
61 }
62 const newDynamicSuggestions = (await autocompleter.getDynamicSuggestions(userInput)).filter((suggestion) => {
63 const isNew = !staticSuggestionsKeys.has(suggestion.key) && !dynamicSuggestionsKeys.has(suggestion.key)
64 dynamicSuggestionsKeys.add(suggestion.key)
65 return isNew
66 })
67 dynamicSuggestions.push(...newDynamicSuggestions)
68 }
69
70 const options: Fuse.IFuseOptions<RenderedSuggestion> = {
71 keys: [
72 { name: 'exactMatch', weight: 0.8 },
73 { name: 'searchTerms', weight: 0.1 },
74 { name: 'display', weight: 0.1 },
75 ],
76 isCaseSensitive: true,
77 distance: 0,
78 findAllMatches: false,
79 fieldNormWeight: 2.0,
80 }
81 const fuse = new Fuse(staticSuggestions, options)
82 const results = fuse.search(userInput).map((res) => res.item)
83 const dynamicFuse = new Fuse(dynamicSuggestions, options)
84 const dynamicResults = dynamicFuse.search(userInput).map((res) => res.item)

Callers 2

prefixMatchMethod · 0.85
InsertBoxClass · 0.85

Calls 2

getPrefixSuggestionsMethod · 0.45
getDynamicSuggestionsMethod · 0.45

Tested by

no test coverage detected