mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
19 lines
652 B
Lua
19 lines
652 B
Lua
---@class lazyvim.util.cmp
|
|
local M = {}
|
|
|
|
---@param entry cmp.Entry
|
|
function M.auto_brackets(entry)
|
|
local cmp = require("cmp")
|
|
local Kind = cmp.lsp.CompletionItemKind
|
|
local item = entry:get_completion_item()
|
|
if vim.tbl_contains({ Kind.Function, Kind.Method }, item.kind) then
|
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
|
local prev_char = vim.api.nvim_buf_get_text(0, cursor[1] - 1, cursor[2], cursor[1] - 1, cursor[2] + 1, {})[1]
|
|
if prev_char ~= "(" and prev_char ~= ")" then
|
|
local keys = vim.api.nvim_replace_termcodes("()<left>", false, false, true)
|
|
vim.api.nvim_feedkeys(keys, "i", true)
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|