Skip to content

Commit 83a8303

Browse files
committed
feat: cache resolve tasks
1 parent bd90e00 commit 83a8303

File tree

1 file changed

+18
-5
lines changed
  • lua/blink/cmp/sources/lib/provider

1 file changed

+18
-5
lines changed

lua/blink/cmp/sources/lib/provider/init.lua

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
--- @field config blink.cmp.SourceProviderConfigWrapper
66
--- @field module blink.cmp.Source
77
--- @field last_response blink.cmp.CompletionResponse | nil
8+
--- @field resolve_tasks table<blink.cmp.CompletionItem, blink.cmp.Task>
89
---
910
--- @field new fun(id: string, config: blink.cmp.SourceProviderConfig): blink.cmp.SourceProvider
1011
--- @field get_trigger_characters fun(self: blink.cmp.SourceProvider): string[]
@@ -35,6 +36,7 @@ function source.new(id, config)
3536
)
3637
self.config = require('blink.cmp.sources.lib.provider.config').new(config)
3738
self.last_response = nil
39+
self.resolve_tasks = {}
3840

3941
return self
4042
end
@@ -100,12 +102,23 @@ end
100102
--- @param item blink.cmp.CompletionItem
101103
--- @return blink.cmp.Task
102104
function source:resolve(item)
103-
return async.task.new(function(resolve)
104-
if self.module.resolve == nil then return resolve(nil) end
105-
return self.module:resolve(item, function(resolved_item)
106-
vim.schedule(function() resolve(resolved_item) end)
105+
local tasks = self.resolve_tasks
106+
if tasks[item] == nil or tasks[item].status == async.STATUS.CANCELLED then
107+
tasks[item] = async.task.new(function(resolve)
108+
if self.module.resolve == nil then return resolve(nil) end
109+
return self.module:resolve(item, function(resolved_item)
110+
-- use the item's existing documentation and detail if the LSP didn't return it
111+
-- TODO: do we need this? this would be for java but never checked if it's needed
112+
if resolved_item ~= nil and resolved_item.documentation == nil then
113+
resolved_item.documentation = item.documentation
114+
end
115+
if resolved_item ~= nil and resolved_item.detail == nil then resolved_item.detail = item.detail end
116+
117+
vim.schedule(function() resolve(resolved_item or item) end)
118+
end)
107119
end)
108-
end)
120+
end
121+
return tasks[item]
109122
end
110123

111124
--- Signature help ---

0 commit comments

Comments
 (0)