fix: always add index to entry (#2442)

59497d6 introduced `sorters.fuzzy_with_index_bias`, which gives a
scoring boost to earlier entries.

However, this sorter relies on an `index` key existing for the entry, which is
only populated by the static finder currently. We should set it from the
other finders, too.

This will allow us to use said sorter everywhere. It will also let us
replicate the behaviour of `fzf --tiebreak=index`:

```
  return pickers.new(opts, {
    finder = finders.new_oneshot_job(...)
    sorter = telescope.extensions.fzf.native_fzf_sorter(),
    tiebreak = function(current_entry, existing_entry, _)
      return current_entry.index < existing_entry.index
    end
  }):find()
```

This gives me better results for my "recently opened files" picker.
Other builtin pickers might benefit from this, too.

(cherry picked from commit 0b891ec934)
This commit is contained in:
Stef
2023-05-24 17:07:23 +02:00
committed by Simon Hauser
parent 6857cee4ea
commit a0208d8d60
3 changed files with 29 additions and 9 deletions
@@ -70,9 +70,10 @@ return function(opts)
async.util.scheduler()
end
local v = entry_maker(line)
results[num_results] = v
process_result(v)
local entry = entry_maker(line)
entry.index = num_results
results[num_results] = entry
process_result(entry)
end
process_complete()