Fix call some methods more safely
This commit is contained in:
+28
-12
@@ -16,6 +16,8 @@
|
||||
|
||||
-- https://github.com/hrsh7th/nvim-cmp
|
||||
|
||||
local module_name = "plugins.config.cmp"
|
||||
|
||||
local has_words_before = function ()
|
||||
unpack = unpack or table.unpack
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
@@ -25,9 +27,14 @@ local has_words_before = function ()
|
||||
:match("%s") == nil
|
||||
end
|
||||
|
||||
local utils = require("utils")
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
local lspkind = require("lspkind")
|
||||
|
||||
local lspkind
|
||||
utils.try_require("lspkind", module_name, function (module)
|
||||
lspkind = module
|
||||
end)
|
||||
|
||||
cmp.setup({
|
||||
enabled = function ()
|
||||
@@ -49,13 +56,17 @@ cmp.setup({
|
||||
},
|
||||
formatting = {
|
||||
format = function (entry, vim_item)
|
||||
vim_item = lspkind.cmp_format({
|
||||
mode = "text",
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
})(entry, vim_item)
|
||||
|
||||
vim_item.dup = 0
|
||||
if lspkind then
|
||||
vim_item = lspkind.cmp_format({
|
||||
mode = "symbol",
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
before = function (_, item)
|
||||
item.dup = 0 -- remove duplicates, see nvim-cmp #511
|
||||
return item
|
||||
end,
|
||||
})(entry, vim_item)
|
||||
end
|
||||
|
||||
return vim_item
|
||||
end,
|
||||
@@ -153,8 +164,13 @@ cmp.setup.cmdline(
|
||||
}
|
||||
)
|
||||
|
||||
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
|
||||
cmp.event:on(
|
||||
"confirm_done",
|
||||
cmp_autopairs.on_confirm_done()
|
||||
utils.try_require(
|
||||
"nvim-autopairs.completion.cmp",
|
||||
module_name,
|
||||
function (cmp_autopairs)
|
||||
cmp.event:on(
|
||||
"confirm_done",
|
||||
cmp_autopairs.on_confirm_done()
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
@@ -16,15 +16,19 @@
|
||||
|
||||
-- https://github.com/rcarriga/nvim-notify
|
||||
|
||||
local telescope = require("telescope")
|
||||
local has_telescope, telescope = pcall(require, "telescope")
|
||||
|
||||
local notify = require("notify")
|
||||
notify.setup({
|
||||
render = "default",
|
||||
stages = "fade",
|
||||
})
|
||||
|
||||
vim.notify = notify
|
||||
telescope.load_extension("notify")
|
||||
vim.keymap.set(
|
||||
"n", "<leader>fn", function () telescope.extensions.notify.notify() end
|
||||
)
|
||||
|
||||
if has_telescope then
|
||||
telescope.load_extension("notify")
|
||||
vim.keymap.set(
|
||||
"n", "<leader>fn", function () telescope.extensions.notify.notify() end
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user