replace compe with cmp
This commit is contained in:
parent
59ec5a5fed
commit
475a4c5f38
|
@ -8,7 +8,6 @@ local options = require("core.utils").load_config().options
|
||||||
|
|
||||||
opt.clipboard = options.clipboard
|
opt.clipboard = options.clipboard
|
||||||
opt.cmdheight = options.cmdheight
|
opt.cmdheight = options.cmdheight
|
||||||
opt.completeopt = { "menuone", "noselect" }
|
|
||||||
opt.cul = true -- cursor line
|
opt.cul = true -- cursor line
|
||||||
|
|
||||||
-- Indentline
|
-- Indentline
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
local present1, autopairs = pcall(require, "nvim-autopairs")
|
|
||||||
local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.compe")
|
|
||||||
|
|
||||||
if not (present1 or present2) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
autopairs.setup()
|
|
||||||
autopairs_completion.setup {
|
|
||||||
map_complete = true, -- insert () func completion
|
|
||||||
map_cr = true,
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
-- autosave.nvim plugin disabled by default
|
|
||||||
local present, autosave = pcall(require, "autosave")
|
|
||||||
if not present then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
autosave.setup {
|
|
||||||
enabled = vim.g.auto_save or false, -- takes boolean value from init.lua
|
|
||||||
execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S",
|
|
||||||
events = { "InsertLeave", "TextChanged" },
|
|
||||||
conditions = {
|
|
||||||
exists = true,
|
|
||||||
filetype_is_not = {},
|
|
||||||
modifiable = true,
|
|
||||||
},
|
|
||||||
clean_command_line_interval = 2500,
|
|
||||||
on_off_commands = true,
|
|
||||||
write_all_buffers = false,
|
|
||||||
}
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
vim.opt.completeopt = "menuone,noselect"
|
||||||
|
|
||||||
|
local lspkind = require "lspkind"
|
||||||
|
local luasnip = require "luasnip"
|
||||||
|
|
||||||
|
-- nvim-cmp setup
|
||||||
|
local cmp = require "cmp"
|
||||||
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
require("luasnip").lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
formatting = {
|
||||||
|
format = function(entry, vim_item)
|
||||||
|
vim_item.kind = lspkind.presets.default[vim_item.kind] .. " " .. vim_item.kind
|
||||||
|
|
||||||
|
vim_item.menu = ({
|
||||||
|
nvim_lsp = "[LSP]",
|
||||||
|
nvim_lua = "[Lua]",
|
||||||
|
buffer = "[BUF]",
|
||||||
|
})[entry.source.name]
|
||||||
|
|
||||||
|
return vim_item
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = {
|
||||||
|
["<C-p>"] = cmp.mapping.select_prev_item(),
|
||||||
|
["<C-n>"] = cmp.mapping.select_next_item(),
|
||||||
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||||
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
|
["<C-e>"] = cmp.mapping.close(),
|
||||||
|
["<CR>"] = cmp.mapping.confirm {
|
||||||
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
|
select = true,
|
||||||
|
},
|
||||||
|
["<Tab>"] = function(fallback)
|
||||||
|
if vim.fn.pumvisible() == 1 then
|
||||||
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-n>", true, true, true), "n")
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["<S-Tab>"] = function(fallback)
|
||||||
|
if vim.fn.pumvisible() == 1 then
|
||||||
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-p>", true, true, true), "n")
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
sources = {
|
||||||
|
{ name = "nvim_lsp" },
|
||||||
|
{ name = "luasnip" },
|
||||||
|
{ name = "buffer" },
|
||||||
|
{ name = "nvim_lua" },
|
||||||
|
},
|
||||||
|
}
|
|
@ -1,26 +0,0 @@
|
||||||
local present, compe = pcall(require, "compe")
|
|
||||||
if not present then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
compe.setup {
|
|
||||||
enabled = true,
|
|
||||||
|
|
||||||
autocomplete = true,
|
|
||||||
debug = false,
|
|
||||||
documentation = true,
|
|
||||||
incomplete_delay = 400,
|
|
||||||
max_abbr_width = 100,
|
|
||||||
max_kind_width = 100,
|
|
||||||
max_menu_width = 100,
|
|
||||||
min_length = 1,
|
|
||||||
preselect = "enable",
|
|
||||||
source_timeout = 200,
|
|
||||||
source = {
|
|
||||||
buffer = { kind = "", true },
|
|
||||||
luasnip = { kind = "", true },
|
|
||||||
nvim_lsp = true,
|
|
||||||
nvim_lua = true,
|
|
||||||
},
|
|
||||||
throttle_time = 80,
|
|
||||||
}
|
|
|
@ -41,7 +41,21 @@ local function on_attach(_, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
capabilities.textDocument.completion.completionItem.documentationFormat = { "markdown", "plaintext" }
|
||||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.preselectSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
|
||||||
|
capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
|
||||||
|
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||||
|
properties = {
|
||||||
|
"documentation",
|
||||||
|
"detail",
|
||||||
|
"additionalTextEdits",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
-- lspInstall + lspconfig stuff
|
-- lspInstall + lspconfig stuff
|
||||||
|
|
||||||
|
|
|
@ -3,64 +3,9 @@ if not present then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local t = function(str)
|
|
||||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
local check_back_space = function()
|
|
||||||
local col = vim.fn.col "." - 1
|
|
||||||
if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
_G.tab_complete = function()
|
|
||||||
if vim.fn.pumvisible() == 1 then
|
|
||||||
return t "<C-n>"
|
|
||||||
elseif luasnip and luasnip.expand_or_jumpable() then
|
|
||||||
return t "<Plug>luasnip-expand-or-jump"
|
|
||||||
elseif check_back_space() then
|
|
||||||
return t "<Tab>"
|
|
||||||
else
|
|
||||||
return vim.fn["compe#complete"]()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
_G.s_tab_complete = function()
|
|
||||||
if vim.fn.pumvisible() == 1 then
|
|
||||||
return t "<C-p>"
|
|
||||||
elseif luasnip and luasnip.jumpable(-1) then
|
|
||||||
return t "<Plug>luasnip-jump-prev"
|
|
||||||
else
|
|
||||||
return t "<S-Tab>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
_G.completions = function()
|
|
||||||
local npairs
|
|
||||||
if not pcall(function()
|
|
||||||
npairs = require "nvim-autopairs"
|
|
||||||
end) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if vim.fn.pumvisible() == 1 then
|
|
||||||
if vim.fn.complete_info()["selected"] ~= -1 then
|
|
||||||
return vim.fn["compe#confirm"] "<CR>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return npairs.check_break_line_char()
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_set_keymap("i", "<CR>", "v:lua.completions()", { expr = true })
|
|
||||||
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
|
|
||||||
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
|
|
||||||
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true })
|
|
||||||
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true })
|
|
||||||
|
|
||||||
luasnip.config.set_config {
|
luasnip.config.set_config {
|
||||||
history = true,
|
history = true,
|
||||||
updateevents = "TextChanged,TextChangedI",
|
updateevents = "TextChanged,TextChangedI",
|
||||||
}
|
}
|
||||||
|
|
||||||
require("luasnip/loaders/from_vscode").load()
|
require("luasnip/loaders/from_vscode").load()
|
||||||
|
|
|
@ -1,5 +1,42 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
M.autopairs = function()
|
||||||
|
local present1, autopairs = pcall(require, "nvim-autopairs")
|
||||||
|
local present2, autopairs_completion = pcall(require, "nvim-autopairs.completion.cmp")
|
||||||
|
|
||||||
|
if not (present1 or present2) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
autopairs.setup()
|
||||||
|
autopairs_completion.setup {
|
||||||
|
map_complete = true, -- insert () func completion
|
||||||
|
map_cr = true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
M.autosave = function()
|
||||||
|
-- autosave.nvim plugin is disabled by default
|
||||||
|
local present, autosave = pcall(require, "autosave")
|
||||||
|
if not present then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
autosave.setup {
|
||||||
|
enabled = vim.g.auto_save or false, -- takes boolean value from init.lua
|
||||||
|
execution_message = "autosaved at : " .. vim.fn.strftime "%H:%M:%S",
|
||||||
|
events = { "InsertLeave", "TextChanged" },
|
||||||
|
conditions = {
|
||||||
|
exists = true,
|
||||||
|
filetype_is_not = {},
|
||||||
|
modifiable = true,
|
||||||
|
},
|
||||||
|
clean_command_line_interval = 2500,
|
||||||
|
on_off_commands = true,
|
||||||
|
write_all_buffers = false,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
M.better_escape = function()
|
M.better_escape = function()
|
||||||
local config = require("core.utils").load_config()
|
local config = require("core.utils").load_config()
|
||||||
vim.g.better_escape_interval = config.options.plugin.esc_insertmode_timeout or 300
|
vim.g.better_escape_interval = config.options.plugin.esc_insertmode_timeout or 300
|
||||||
|
|
|
@ -154,7 +154,7 @@ return packer.startup(function()
|
||||||
disable = not plugin_status.autosave,
|
disable = not plugin_status.autosave,
|
||||||
"Pocco81/AutoSave.nvim",
|
"Pocco81/AutoSave.nvim",
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.autosave"
|
require("plugins.configs.others").autosave()
|
||||||
end,
|
end,
|
||||||
cond = function()
|
cond = function()
|
||||||
return require("core.utils").load_config().options.plugin.autosave == true
|
return require("core.utils").load_config().options.plugin.autosave == true
|
||||||
|
@ -164,7 +164,7 @@ return packer.startup(function()
|
||||||
use {
|
use {
|
||||||
"onsails/lspkind-nvim",
|
"onsails/lspkind-nvim",
|
||||||
disable = not plugin_status.lspkind,
|
disable = not plugin_status.lspkind,
|
||||||
event = "InsertEnter",
|
after = "LuaSnip",
|
||||||
config = function()
|
config = function()
|
||||||
require("plugins.configs.others").lspkind()
|
require("plugins.configs.others").lspkind()
|
||||||
end,
|
end,
|
||||||
|
@ -182,36 +182,56 @@ return packer.startup(function()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- load compe in insert mode only
|
-- load luasnips + cmp related in insert mode only
|
||||||
|
|
||||||
use {
|
use {
|
||||||
"hrsh7th/nvim-compe",
|
|
||||||
event = "InsertEnter",
|
|
||||||
config = function()
|
|
||||||
require "plugins.configs.compe"
|
|
||||||
end,
|
|
||||||
wants = "LuaSnip",
|
|
||||||
requires = {
|
|
||||||
{
|
|
||||||
"L3MON4D3/LuaSnip",
|
"L3MON4D3/LuaSnip",
|
||||||
|
event = "InsertEnter",
|
||||||
wants = "friendly-snippets",
|
wants = "friendly-snippets",
|
||||||
event = "InsertCharPre",
|
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.luasnip"
|
require "plugins.configs.luasnip"
|
||||||
end,
|
end,
|
||||||
},
|
}
|
||||||
{
|
|
||||||
|
use {
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
config = function()
|
||||||
|
require "plugins.configs.cmp"
|
||||||
|
end,
|
||||||
|
after = "lspkind-nvim",
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
"saadparwaiz1/cmp_luasnip",
|
||||||
|
after = "nvim-cmp",
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
"hrsh7th/cmp-nvim-lua",
|
||||||
|
after = "cmp_luasnip",
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
|
after = "cmp-nvim-lua",
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
|
"hrsh7th/cmp-buffer",
|
||||||
|
after = "cmp-nvim-lsp",
|
||||||
|
}
|
||||||
|
|
||||||
|
use {
|
||||||
"rafamadriz/friendly-snippets",
|
"rafamadriz/friendly-snippets",
|
||||||
event = "InsertCharPre",
|
after = "cmp-buffer",
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- misc plugins
|
-- misc plugins
|
||||||
use {
|
use {
|
||||||
"windwp/nvim-autopairs",
|
"windwp/nvim-autopairs",
|
||||||
after = "nvim-compe",
|
after = "nvim-cmp",
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.autopairs"
|
require("plugins.configs.others").autopairs()
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue