Skip to content

Commit

Permalink
Merge pull request #44 from lukas-reineke/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke authored Sep 5, 2022
2 parents 7cf6ddc + 6b11e67 commit 1cad8eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
},
},
}
```

Expand Down
12 changes: 8 additions & 4 deletions doc/cmp-rg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Author: Lukas Reineke <lukas.reineke@protonmail.com>
Version: 1.3.7
Version: 1.3.8

==============================================================================
CONTENTS *cmp-rg*
Expand Down Expand Up @@ -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
},
},
}
==============================================================================
Expand Down
17 changes: 15 additions & 2 deletions lua/cmp-rg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1cad8eb

Please sign in to comment.