feat: replace coq.nvim with nvim-cmp and luasnip

This commit is contained in:
mandlm 2022-04-04 17:30:26 +02:00
parent 299c65cd0a
commit 6f1535f83f
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
3 changed files with 88 additions and 27 deletions

View File

@ -39,6 +39,9 @@ vim.opt.smartcase = true
-- preview commands -- preview commands
vim.opt.inccommand = "split" vim.opt.inccommand = "split"
-- completion
vim.opt.completeopt = "menu,menuone,noselect"
-- set cursorline in active window -- set cursorline in active window
vim.cmd([[ vim.cmd([[
augroup CursorLine augroup CursorLine
@ -57,10 +60,3 @@ vim.cmd([[
augroup END augroup END
]]) ]])
-- coq.nvim
vim.g.coq_settings = {
auto_start = "shut-up",
keymap = {
jump_to_mark = "<c-s>" -- prevent <C-h> remapping
}
}

View File

@ -44,10 +44,7 @@ return require('packer').startup(function(use)
config = function() config = function()
require'tabline'.setup { require'tabline'.setup {
enable = true, enable = true,
options = { options = {show_bufnr = true, show_filename_only = true}
show_bufnr = true,
show_filename_only = true,
}
} }
end, end,
requires = { requires = {
@ -87,9 +84,78 @@ return require('packer').startup(function(use)
-- autocompletion -- autocompletion
use({ use({
"ms-jpq/coq_nvim", "L3MON4D3/LuaSnip",
branch = "coq", requires = {"rafamadriz/friendly-snippets"},
requires = {{'ms-jpq/coq.artifacts', branch = 'artifacts'}} config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end
})
use({
"hrsh7th/nvim-cmp",
requires = {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline", "hrsh7th/cmp-git", "hrsh7th/cmp-nvim-lua",
"saadparwaiz1/cmp_luasnip"
},
config = function()
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(
col, col):match("%s") == nil
end
local cmp = require('cmp')
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end
},
sources = require("cmp").config.sources({
{name = "nvim_lsp"}, {name = "luasnip"}, {name = "path"},
{name = "buffer"}, {name = "git"}
}),
mapping = {
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(),
{'i', 'c'}),
['<CR>'] = cmp.mapping.confirm({select = true}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {"i", "s"})
}
})
-- `/` cmdline setup.
cmp.setup.cmdline('/', {sources = {{name = 'buffer'}}})
-- `:` cmdline setup.
cmp.setup.cmdline(':', {
sources = cmp.config
.sources({{name = 'path'}}, {{name = 'cmdline'}})
})
end
}) })
-- highlight current symbol -- highlight current symbol

View File

@ -1,4 +1,3 @@
local coq = require("coq")
local lsp_installer = require("nvim-lsp-installer") local lsp_installer = require("nvim-lsp-installer")
local nvim_runtime_path = vim.split(package.path, ';') local nvim_runtime_path = vim.split(package.path, ';')
@ -6,9 +5,9 @@ table.insert(nvim_runtime_path, "lua/?.lua")
table.insert(nvim_runtime_path, "lua/?/init.lua") table.insert(nvim_runtime_path, "lua/?/init.lua")
local language_servers = { local language_servers = {
"ansiblels", "bashls", "clangd", "dockerls", "efm", "eslint", "html", "jsonls", "ansiblels", "bashls", "clangd", "dockerls", "efm", "eslint", "html",
"pyright", "rust_analyzer", "sumneko_lua", "svelte", "taplo", "terraformls", "jsonls", "pyright", "rust_analyzer", "sumneko_lua", "svelte", "taplo",
"tflint", "tsserver", "volar" "terraformls", "tflint", "tsserver", "volar"
} }
for _, server_name in pairs(language_servers) do for _, server_name in pairs(language_servers) do
@ -22,7 +21,8 @@ end
local extra_server_opts = { local extra_server_opts = {
["efm"] = function(opts) ["efm"] = function(opts)
opts.filetypes = { opts.filetypes = {
"lua", "html", "javascript", "markdown", "typescript", "typescriptreact" "lua", "html", "javascript", "markdown", "typescript",
"typescriptreact"
} }
opts.init_options = {documentFormatting = true} opts.init_options = {documentFormatting = true}
opts.settings = { opts.settings = {
@ -67,11 +67,7 @@ local extra_server_opts = {
end, end,
["rust_analyzer"] = function(opts) ["rust_analyzer"] = function(opts)
opts.settings = { opts.settings = {
["rust-analyzer"] = { ["rust-analyzer"] = {checkOnSave = {command = "clippy"}}
checkOnSave = {
command = "clippy"
}
}
} }
end, end,
["sumneko_lua"] = function(opts) ["sumneko_lua"] = function(opts)
@ -134,10 +130,13 @@ local function custom_on_attach(client, buffer_nr)
end end
lsp_installer.on_server_ready(function(server) lsp_installer.on_server_ready(function(server)
local opts = coq.lsp_ensure_capabilities({ local cmp = require("cmp_nvim_lsp")
local opts = {
on_attach = custom_on_attach, on_attach = custom_on_attach,
capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = cmp.update_capabilities(vim.lsp.protocol
}) .make_client_capabilities())
}
if extra_server_opts[server.name] then if extra_server_opts[server.name] then
extra_server_opts[server.name](opts) extra_server_opts[server.name](opts)