Skip to content

Commit

Permalink
Enable to use with wildoptions fuzzy
Browse files Browse the repository at this point in the history
  • Loading branch information
notomo committed Jul 26, 2024
1 parent 1ee1e39 commit 24933fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/cmdbuf/handler/lua/variable/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function M.histories(self)

local prefix_length = #"b:" + 1
local keys = vim.api.nvim_buf_call(self._bufnr, function()
return vim.fn.getcompletion("b:*", "var")
return require("cmdbuf.lib.completion").get("b:*", "var")
end)
local vars = vim
.iter(keys)
Expand Down
2 changes: 1 addition & 1 deletion lua/cmdbuf/handler/lua/variable/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function M.histories(_)
end)

local prefix_length = #"g:" + 1
local keys = vim.fn.getcompletion("g:*", "var")
local keys = require("cmdbuf.lib.completion").get("g:*", "var")
local vars = vim
.iter(keys)
:map(function(key)
Expand Down
2 changes: 1 addition & 1 deletion lua/cmdbuf/handler/vim/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function M.new()
end

function M.histories()
local keys = vim.fn.getcompletion("*", "environment")
local keys = require("cmdbuf.lib.completion").get("*", "environment")
local lines = {}
for _, key in ipairs(keys) do
local value = vim.env[key]
Expand Down
20 changes: 20 additions & 0 deletions lua/cmdbuf/lib/completion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local M = {}

function M.get(pattern, typ)
local tmp = vim.opt.wildoptions
vim.opt.wildoptions:remove("fuzzy")
local restore = function()
vim.opt.wildoptions = tmp
end

local ok, result = pcall(vim.fn.getcompletion, pattern, typ)
if not ok then
restore()
error(result)
end

restore()
return result
end

return M

0 comments on commit 24933fa

Please sign in to comment.