Skip to content

Commit 6b09eaa

Browse files
committed
feat: smarter fuzzy, drop logging
1 parent d8a593d commit 6b09eaa

File tree

8 files changed

+46
-36
lines changed

8 files changed

+46
-36
lines changed

Cargo.lock

+26-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"c-marshalling-0.2.0" =
4949
"sha256-eL6nkZOtuLLQ0r31X7uroUUDYZsWOJ9KNXl4NCVNRuw=";
5050
"frizbee-0.1.0" =
51-
"sha256-FHyf5WqYCKVwbSZJ/Qg4aP+FHWsEORvPndRo5wHv+rU=";
51+
"sha256-ksiB8R97z+heM6Ynh3D9Rf+pMhEPqncomgTXT2n5byQ=";
5252
};
5353
};
5454
};

lua/blink/cmp/fuzzy/fuzzy.rs

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ pub fn fuzzy(
6767
})
6868
.collect::<Vec<_>>();
6969

70+
// Find the highest score and filter out matches that are unreasonably lower than it
71+
let max_score = matches.iter().map(|mtch| mtch.score).max().unwrap_or(0);
72+
let secondary_min_score = max_score.max(4) - 4;
73+
matches = matches
74+
.into_iter()
75+
.filter(|mtch| mtch.score >= secondary_min_score)
76+
.collect::<Vec<_>>();
77+
7078
// Sort matches by sort criteria
7179
for sort in opts.sorts.iter() {
7280
match sort.as_str() {

lua/blink/cmp/fuzzy/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function fuzzy.filter_items(needle, items)
4545
-- each matching char is worth 4 points and it receives a bonus for capitalization, delimiter and prefix
4646
-- so this should generally be good
4747
-- TODO: make this configurable
48-
min_score = 4 * needle:len(),
48+
min_score = 6 * needle:len(),
4949
max_items = config.max_items,
5050
use_frecency = config.use_frecency,
5151
use_proximity = config.use_proximity,

lua/blink/cmp/sources/lib/context.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ function sources_context:get_completions(context)
2626
assert(context.id == self.id, 'Requested completions on a sources context with a different context ID')
2727

2828
if self.active_request ~= nil and self.active_request.status == async.STATUS.RUNNING then
29-
vim.print(tostring(context.id) .. ': queued request | col: ' .. context.bounds.end_col)
29+
-- vim.print(tostring(context.id) .. ': queued request | col: ' .. context.bounds.end_col)
3030
self.queued_request_context = context
3131
return
3232
end
33-
vim.print(tostring(context.id) .. ': running request | col: ' .. context.bounds.end_col)
33+
-- vim.print(tostring(context.id) .. ': running request | col: ' .. context.bounds.end_col)
3434

3535
-- Create a task to get the completions for the first sources group,
3636
-- falling back to the next sources group iteratively if there are no items
@@ -50,6 +50,9 @@ function sources_context:get_completions(context)
5050
self.last_successful_completions = items
5151
self.on_completions_callback(context, items)
5252

53+
-- todo: when the queued request results in 100% cached content, we end up
54+
-- calling the on_completions_callback with the same data, which triggers
55+
-- unnecessary fuzzy + render updates
5356
if self.queued_request_context ~= nil then
5457
local queued_context = self.queued_request_context
5558
self.queued_request_context = nil
@@ -99,7 +102,7 @@ function sources_context:get_completions_for_group(sources_group, context)
99102
return items
100103
end)
101104
:catch(function(err)
102-
vim.print('failed to get completions with error: ' .. err)
105+
vim.print('failed to get completions for group with error: ' .. err)
103106
return { is_incomplete_forward = false, is_incomplete_backward = false, items = {} }
104107
end)
105108
end

lua/blink/cmp/sources/lib/source.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ function source:get_completions(context)
2929
-- and the data doesn't need to be updated
3030
if self.last_response ~= nil and self.last_response.context.id == context.id then
3131
if utils.should_run_request(context, self.last_response) == false then
32-
vim.print(self.name .. ': returning cached completions')
32+
-- vim.print(self.name .. ': returning cached completions')
3333
return async.task.new(function(resolve) resolve(self.last_response) end)
3434
end
3535
end
36-
vim.print(self.name .. ': running completions request')
36+
-- vim.print(self.name .. ': running completions request')
3737

3838
return async.task
3939
.new(function(resolve) return self.module:get_completions(context, resolve) end)

lua/blink/cmp/sources/snippets/init.lua

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ function snippets:get_completions(context, callback)
3333
for _, snippet in pairs(snips) do
3434
table.insert(self.cache[filetype], self.registry:snippet_to_completion_item(snippet))
3535
end
36-
vim.print(self.cache[filetype])
3736
end
3837

3938
callback({

lua/blink/cmp/sources/snippets/registry.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
---@class blink.cmp.Snippet
66
---@field prefix string
7-
---@field body string[]
7+
---@field body string[] | string
88
---@field description? string
99

1010
local registry = {
@@ -111,7 +111,7 @@ function registry:snippet_to_completion_item(snippet)
111111
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
112112
label = snippet.prefix,
113113
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
114-
insertText = table.concat(snippet.body, '\n'),
114+
insertText = type(snippet.body) == 'string' and snippet.body or table.concat(snippet.body, '\n'),
115115
description = snippet.description,
116116
}
117117
end

0 commit comments

Comments
 (0)