106 lines
2.8 KiB
Lua
106 lines
2.8 KiB
Lua
-- Setup nvim-cmp.
|
|
local cmp = require 'cmp'
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
require('luasnip').lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = {
|
|
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
|
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
|
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}),
|
|
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}),
|
|
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
|
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
|
['<C-e>'] = cmp.mapping({
|
|
i = cmp.mapping.abort(),
|
|
c = cmp.mapping.close(),
|
|
}),
|
|
-- Accept currently selected item. If none selected, `select` first item.
|
|
-- Set `select` to `false` to only confirm explicitly selected items.
|
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
|
},
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
}, {
|
|
{ name = 'buffer' },
|
|
})
|
|
})
|
|
|
|
-- Use buffer source for `vimwiki`
|
|
cmp.setup.cmdline('vimwiki', {
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
cmp.setup.cmdline('md', {
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
cmp.setup.cmdline('tex', {
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
-- Use buffer source for `/`
|
|
cmp.setup.cmdline('/', {
|
|
sources = {
|
|
{ name = 'buffer' }
|
|
}
|
|
})
|
|
|
|
-- Use cmdline & path source for ':'
|
|
cmp.setup.cmdline(':', {
|
|
sources = cmp.config.sources({
|
|
{ name = 'path' }
|
|
}, {
|
|
{ name = 'cmdline' }
|
|
})
|
|
})
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local function buf_set_keymap(...)
|
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
end
|
|
|
|
local opts = { noremap = true, silent = true }
|
|
buf_set_keymap("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
|
buf_set_keymap("n", "gD", "<cmd>Telescope lsp_implementations<CR>", opts)
|
|
-- buf_set_keymap("n", "gr", "<cmd>Telescope lsp_references<CR>", opts)
|
|
vim.keymap.set("n", "gf",vim.lsp.buf.formatting)
|
|
vim.keymap.set("n", "gh", vim.lsp.buf.hover)
|
|
vim.keymap.set("n", "ge", vim.diagnostic.open_float)
|
|
vim.keymap.set("n", "gs", vim.lsp.buf.signature_help)
|
|
vim.keymap.set("n", "gR", vim.lsp.buf.rename)
|
|
vim.keymap.set("n", "gH", vim.lsp.buf.code_action)
|
|
end
|
|
|
|
local lsp_installer = require 'nvim-lsp-installer'
|
|
lsp_installer.on_server_ready(function(server)
|
|
local opts = {}
|
|
opts.on_attach = on_attach
|
|
opts.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
|
|
server:setup(opts)
|
|
vim.cmd [[ do User LspAttachBuffers ]]
|
|
end)
|
|
|
|
require "lsp_signature".setup {
|
|
handler_opts = {
|
|
border = "rounded"
|
|
},
|
|
toggle_key = "<M-r>",
|
|
}
|