diff --git a/README.md b/README.md index 8676fa8..5d7a27f 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,9 @@ Use your favourite plugin manager to install. ```lua -- init.lua -require("packer").startup( - function() - use "lukas-reineke/cmp-rg" - end -) +require("packer").startup(function() + use "lukas-reineke/cmp-rg" +end) ``` #### Example with Plug @@ -39,10 +37,14 @@ call plug#end() Add `rg` to your cmp sources ```lua -require'cmp'.setup { +require("cmp").setup { sources = { - { name = 'rg' } - } + { + name = "rg", + -- Try it when you feel cmp performance is poor + -- keyword_length = 3 + }, + }, } ``` diff --git a/doc/cmp-rg.txt b/doc/cmp-rg.txt index 6f45ad4..a38b994 100644 --- a/doc/cmp-rg.txt +++ b/doc/cmp-rg.txt @@ -2,7 +2,7 @@ Author: Lukas Reineke -Version: 1.3.7 +Version: 1.3.8 ============================================================================== CONTENTS *cmp-rg* @@ -104,10 +104,14 @@ debug *cmp-rg-debug* Add `rg` to your cmp sources > - require'cmp'.setup { + require("cmp").setup { sources = { - { name = 'rg' } - } + { + name = "rg", + -- Try it when you feel cmp performance is poor + -- keyword_length = 3 + }, + }, } ============================================================================== diff --git a/lua/cmp-rg/init.lua b/lua/cmp-rg/init.lua index 5f58c23..c2979d9 100644 --- a/lua/cmp-rg/init.lua +++ b/lua/cmp-rg/init.lua @@ -7,9 +7,18 @@ require "cmp-rg.types" local source = {} source.new = function() + local timer = vim.loop.new_timer() + vim.api.nvim_create_autocmd("VimLeavePre", { + callback = function() + if timer and not timer:is_closing() then + timer:stop() + timer:close() + end + end, + }) return setmetatable({ running_job_id = 0, - timer = vim.loop.new_timer(), + timer = timer, json_decode = vim.fn.has "nvim-0.6" == 1 and vim.json.decode or vim.fn.json_decode, }, { __index = source }) end @@ -26,6 +35,7 @@ source.complete = function(self, request, callback) end local seen = {} local items = {} + local chunk_size = 5 local function on_event(_, data, event) if event == "stdout" then @@ -111,7 +121,10 @@ source.complete = function(self, request, callback) end end end - callback { items = items, isIncomplete = true } + if #items - chunk_size >= chunk_size then + chunk_size = chunk_size * 2 + callback { items = items, isIncomplete = true } + end end if event == "stderr" and request.option.debug then