Closes#33106
Instead of directly using `filter_text` in `StringMatchCandidate`, which
yields better results for fuzzy matching but messes up with highlighting
letters in bold, as `positions` list generated by fuzzy crate are now of
`filter_text` and not `label` shown to the user.
This PR fixes it by keeping use of `filter_range` in
`StringMatchCandidate`, which is range w.r.t to `label` shown to user.
And actually generating this `filter_range` at source by using
`filter_range` if exists.
- [x] Tests
Release Notes:
- Fixed issue where incorrect letters are marked as bold in completions.
This PR makes it a lot cleaner to write code completion tests. It
doesn't contain any logical changes, just refactoring.
Before, we used to depend on hard-coded values of fuzzy score and its
positions for tests. Now we don't need them, as fuzzy crate will handle
that for us. This is possible because fuzzy match score isn't dependent
on relative candidates or the number of candidates; rather, it's just a
one-to-one mapping for each candidate and its score.
This also makes it test robust for future purposes if there are changes
in fuzzy score logic.
Before:
```rs
SortableMatch {
string_match: StringMatch { // -> whole struct provided by fuzzy crate
candidate_id: 1115,
score: 1.0,
positions: vec![],
string: "Item".to_string(),
},
is_snippet: false, // -> changed to snippet kind
sort_text: Some("16"),
sort_kind: 3, // -> changed to function, constant, variable kind
sort_label: "Item",
},
```
After:
```rs
CompletionBuilder::function("Item", "16")
```
Release Notes:
- N/A
Closes#29725
Adds 3 more tests for Rust `into` and `await` cases, and Python
`__init__` case. Tweaks sort logic to accommodate them.
Release Notes:
- Improved code completion sort order, handling more cases with Rust and
Python.
Added `snippet_sort_order`, which determines how snippets are sorted
relative to other completion items. It can have the values `top`,
`bottom`, or `inline`, with `inline` being the default.
This mimics VS Code’s setting:
https://code.visualstudio.com/docs/editing/intellisense#_snippets-in-suggestions
Release Notes:
- Added support for `snippet_sort_order` to control snippet sorting
behavior in code completion menus.
Closes#27994, #29050, #27352, #27616
This PR implements new logic for code completions, which improve cases
where local variables, etc LSP based hints are not shown on top of code
completion menu. The new logic is explained in comment of code.
This new sort is similar to VSCode's completions sort where order of
sort is like:
Fuzzy > Snippet > LSP sort_key > LSP sort_text
whenever two items have same value, it proceeds to use next one as tie
breaker. Changing fuzzy score from float to int based makes it possible
for two items two have same fuzzy int score, making them get sorted by
next criteria.
Release Notes:
- Improved code completions to prioritize LSP hints, such as local
variables, so they appear at the top of the list.