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

main
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
vim.opt.inccommand = "split"
-- completion
vim.opt.completeopt = "menu,menuone,noselect"
-- set cursorline in active window
vim.cmd([[
augroup CursorLine
@ -57,10 +60,3 @@ vim.cmd([[
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()
require'tabline'.setup {
enable = true,
options = {
show_bufnr = true,
show_filename_only = true,
}
options = {show_bufnr = true, show_filename_only = true}
}
end,
requires = {
@ -87,9 +84,78 @@ return require('packer').startup(function(use)
-- autocompletion
use({
"ms-jpq/coq_nvim",
branch = "coq",
requires = {{'ms-jpq/coq.artifacts', branch = 'artifacts'}}
"L3MON4D3/LuaSnip",
requires = {"rafamadriz/friendly-snippets"},
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

View File

@ -1,4 +1,3 @@
local coq = require("coq")
local lsp_installer = require("nvim-lsp-installer")
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")
local language_servers = {
"ansiblels", "bashls", "clangd", "dockerls", "efm", "eslint", "html", "jsonls",
"pyright", "rust_analyzer", "sumneko_lua", "svelte", "taplo", "terraformls",
"tflint", "tsserver", "volar"
"ansiblels", "bashls", "clangd", "dockerls", "efm", "eslint", "html",
"jsonls", "pyright", "rust_analyzer", "sumneko_lua", "svelte", "taplo",
"terraformls", "tflint", "tsserver", "volar"
}
for _, server_name in pairs(language_servers) do
@ -22,7 +21,8 @@ end
local extra_server_opts = {
["efm"] = function(opts)
opts.filetypes = {
"lua", "html", "javascript", "markdown", "typescript", "typescriptreact"
"lua", "html", "javascript", "markdown", "typescript",
"typescriptreact"
}
opts.init_options = {documentFormatting = true}
opts.settings = {
@ -67,11 +67,7 @@ local extra_server_opts = {
end,
["rust_analyzer"] = function(opts)
opts.settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
}
}
["rust-analyzer"] = {checkOnSave = {command = "clippy"}}
}
end,
["sumneko_lua"] = function(opts)
@ -134,10 +130,13 @@ local function custom_on_attach(client, buffer_nr)
end
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,
capabilities = vim.lsp.protocol.make_client_capabilities()
})
capabilities = cmp.update_capabilities(vim.lsp.protocol
.make_client_capabilities())
}
if extra_server_opts[server.name] then
extra_server_opts[server.name](opts)