Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit e4dddd8

Browse files
committed
fix: respect isIncomplete flag when perform caching
fix
1 parent 49a2335 commit e4dddd8

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

lua/completion/complete.lua

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local api = vim.api
33
local util = require 'completion.util'
44
local ins = require 'completion.source.ins_complete'
55
local match = require'completion.matching'
6+
local lsp = require'completion.source.lsp'
67

78
local M = {}
89

@@ -28,6 +29,7 @@ end
2829

2930
M.clearCache = function()
3031
cache_complete_items = {}
32+
lsp.isIncomplete = true
3133
end
3234

3335
-- perform completion
@@ -38,23 +40,29 @@ M.performComplete = function(complete_source, complete_items_map, manager, opt)
3840
-- ins-complete source
3941
ins.triggerCompletion(manager, complete_source.mode)
4042
elseif vim.fn.has_key(complete_source, "complete_items") > 0 then
41-
if #cache_complete_items == 0 then
42-
-- use callback_array to handle async behavior
43-
local callback_array = {}
44-
local items_array = {}
45-
-- collect getCompleteItems function of current completion source
46-
for _, item in ipairs(complete_source.complete_items) do
47-
local complete_items = complete_items_map[item]
48-
if complete_items ~= nil then
49-
if complete_items.callback == nil then
50-
table.insert(callback_array, true)
51-
else
52-
table.insert(callback_array, complete_items.callback)
53-
complete_items.trigger(manager, opt)
54-
end
55-
table.insert(items_array, complete_items.item)
43+
local callback_array = {}
44+
local items_array = {}
45+
-- collect getCompleteItems function of current completion source
46+
for _, item in ipairs(complete_source.complete_items) do
47+
-- check isIncomplete for lsp
48+
if item == 'lsp' then
49+
if lsp.isIncomplete then
50+
cache_complete_items = {}
51+
end
52+
end
53+
local complete_items = complete_items_map[item]
54+
if complete_items ~= nil then
55+
if complete_items.callback == nil then
56+
table.insert(callback_array, true)
57+
else
58+
table.insert(callback_array, complete_items.callback)
59+
complete_items.trigger(manager, opt)
5660
end
61+
table.insert(items_array, complete_items.item)
5762
end
63+
end
64+
if #cache_complete_items == 0 then
65+
-- use callback_array to handle async behavior
5866

5967
local timer = vim.loop.new_timer()
6068
timer:start(20, 50, vim.schedule_wrap(function()

lua/completion/source/lsp.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local M = {}
66

77
M.callback = false
88

9+
M.isIncomplete = true
10+
911
M.getCompletionItems = function(_, _)
1012
return M.items
1113
end
@@ -128,6 +130,7 @@ M.triggerFunction = function(manager, opt)
128130
end
129131
local matches = text_document_completion_list_to_complete_items(result, opt)
130132
M.items = matches
133+
M.isIncomplete = result.isIncomplete
131134
M.callback = true
132135
end)
133136
end

0 commit comments

Comments
 (0)