Boosting completions that are normally not present

Hi! I was wondering if there is a better way to apply boost to '<< custom >>' in this example, so that when the user types 'c' it appears at the top of the completions list. Typically you’d need to type 'cu' to get '<< custom >>' to appear.

const completions = [
  {label: "console"},
  {label: "const"},
  {label: "<< custom >>", boost: 99},
]

I was considering adding a custom apply function but I would still like to display the full label '<< custom >>' which is what the completions sort from

Here is a link to an example

label should hold the actual text that is to be matched against the input (so that the matcher can style the actual characters that were matched in the representation of the option). The only way to sidestep the matcher and provide your own ordering is the filter: false option.

Thanks! I’m filtering the completions manually and was wondering if you would be open to making the FuzzyMatcher class exported directly from codemirror/autocomplete. I would like to keep the existing logic in that class and just hand-roll my own filterMethod (I think other users may find this useful).

For this usecase the CompletionResult could then look something like:


const filterCompletionOptions = (options: Completion[], str: string) => {
  const matcher = new FuzzyMatcher(str)

  const matches: Completion[] = []
  options.forEach((option) => {
    let label = ''
    if (option.label.startsWith('<< ') && option.label.endsWith(' >>')) {
      label = option.label.replace('<< ', '').replace(' >>', '')
    } else {
      label = option.label
    }

    if (matcher.match(label)) matches.push({ ...option })
  })

  return matches
}

const allOptions = // ...
// ...

completionResult = {
    from,
    filter: false,
    options: filterCompletionOptions(allOptions),
}

That doesn’t seem like a great approach (you’re ignoring all ranking and not giving the user feedback on what was actually matched).

What are these << >> wrapper for, in your editor?