Skip to content

Commit 0386120

Browse files
committed
feat: use sort_text over label for sorting
Closes #365
1 parent 33f7d8d commit 0386120

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lua/blink/cmp/fuzzy/fuzzy.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ pub fn fuzzy(
121121
}
122122
"label" => {
123123
matches.sort_by(|a, b| {
124-
let label_a = &haystack[a.index_in_haystack].label;
125-
let label_b = &haystack[b.index_in_haystack].label;
124+
let label_a = haystack[a.index_in_haystack]
125+
.sort_text
126+
.as_ref()
127+
.unwrap_or(&haystack[a.index_in_haystack].label);
128+
let label_b = haystack[b.index_in_haystack]
129+
.sort_text
130+
.as_ref()
131+
.unwrap_or(&haystack[b.index_in_haystack].label);
126132

127133
// Put anything with an underscore at the end
128134
match (label_a.starts_with('_'), label_b.starts_with('_')) {

lua/blink/cmp/fuzzy/init.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ end
6565
function fuzzy.get_query()
6666
local line = vim.api.nvim_get_current_line()
6767
local keyword = config.completion.keyword
68-
local range =
69-
require('blink.cmp.lib.utils').get_regex_around_cursor(keyword.range, keyword.regex, keyword.exclude_from_prefix_regex)
68+
local range = require('blink.cmp.lib.utils').get_regex_around_cursor(
69+
keyword.range,
70+
keyword.regex,
71+
keyword.exclude_from_prefix_regex
72+
)
7073
return string.sub(line, range.start_col, range.start_col + range.length - 1)
7174
end
7275

lua/blink/cmp/fuzzy/lsp_item.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use mlua::prelude::*;
44
pub struct LspItem {
55
pub label: String,
66
pub filter_text: Option<String>,
7+
pub sort_text: Option<String>,
78
pub kind: u32,
89
pub score_offset: i32,
910
pub source_id: String,
@@ -14,13 +15,15 @@ impl FromLua for LspItem {
1415
if let Some(tab) = value.as_table() {
1516
let label = tab.get("label").unwrap_or_default();
1617
let filter_text = tab.get("filterText").ok();
18+
let sort_text = tab.get("sortText").ok();
1719
let kind = tab.get("kind").unwrap_or_default();
1820
let score_offset = tab.get("score_offset").unwrap_or(0);
1921
let source_id = tab.get("source_id").unwrap_or_default();
2022

2123
Ok(LspItem {
2224
label,
2325
filter_text,
26+
sort_text,
2427
kind,
2528
score_offset,
2629
source_id,

0 commit comments

Comments
 (0)