dotfiles/.config/nvim/after/plugin/lsp.lua

59 lines
1.5 KiB
Lua
Raw Normal View History

2023-04-10 07:55:36 +08:00
local lsp = require('lsp-zero').preset({
manage_nvim_cmp = {
set_sources = 'recommended',
}
})
local cmp = require('cmp');
-- Set the lsp autocomplete to put text from selection into the buffer.
--
-- This setup_nvim_cmp function is deprecated, though this seems to be
-- the cleanest solution as of lsp-zero v2.x. A fallback solution is
-- commented out below.
lsp.setup_nvim_cmp({
select_behavior = cmp.SelectBehavior.Insert
})
vim.diagnostic.config({
virtual_text = true
})
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({buffer = bufnr})
2023-04-06 09:22:23 +08:00
-- Set tagfunc back to empty instead of vim.lsp.tagfunc(),
-- to use default tag jumping behaviour withouth going through the lsp.
-- - see https://neovim.io/doc/user/lsp.html
vim.opt.tagfunc = ""
end)
-- (Optional) Configure lua language server for neovim
require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls())
lsp.setup()
-- Below commented code is a fallback for when the setup_nvim_cmp()
-- is gone
--
-- This is adapted from the defaults provided by lsp-zero
-- - see https://github.com/VonHeikemen/lsp-zero.nvim/blob/v2.x/lua/lsp-zero/cmp.lua
--
--local select_opts = { behavior = cmp.SelectBehavior.Insert }
--cmp.setup({
-- mapping = {
-- ['<C-p>'] = cmp.mapping(function()
-- if cmp.visible() then
-- cmp.select_prev_item(select_opts)
-- else
-- cmp.complete()
-- end
-- end),
-- ['<C-n>'] = cmp.mapping(function()
-- if cmp.visible() then
-- cmp.select_next_item(select_opts)
-- else
-- cmp.complete()
-- end
-- end),
-- }
--})