97 lines
3.2 KiB
Lua
97 lines
3.2 KiB
Lua
return {
|
|
'VonHeikemen/lsp-zero.nvim',
|
|
branch = 'v3.x',
|
|
dependencies = {
|
|
-- LSP Support
|
|
{'neovim/nvim-lspconfig'}, -- Required
|
|
-- {'williamboman/mason.nvim'}, -- Optional
|
|
-- {'williamboman/mason-lspconfig.nvim'}, -- Optional
|
|
|
|
-- Autocompletion
|
|
{'hrsh7th/nvim-cmp'}, -- Required
|
|
{'hrsh7th/cmp-nvim-lsp'}, -- Required
|
|
{'L3MON4D3/LuaSnip'}, -- Required
|
|
{'saadparwaiz1/cmp_luasnip'},
|
|
{'onsails/lspkind.nvim'} -- Optional
|
|
},
|
|
config = function()
|
|
local lsp_zero = require('lsp-zero')
|
|
|
|
lsp_zero.on_attach(function(client, bufnr)
|
|
local opts = {buffer = bufnr, remap = false}
|
|
|
|
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
|
|
vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, opts)
|
|
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
|
|
vim.keymap.set("n", "<leader>ws", function() vim.lsp.buf.workspace_symbol() end, opts)
|
|
vim.keymap.set("n", "<leader>d", function() vim.diagnostic.open_float() end, opts)
|
|
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
|
|
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
|
|
vim.keymap.set("n", "<leader>ca", function() vim.lsp.buf.code_action() end, opts)
|
|
vim.keymap.set("n", "<leader>rn", function() vim.lsp.buf.rename() end, opts)
|
|
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
|
end)
|
|
|
|
-- Mason Config
|
|
-- require('mason').setup({})
|
|
-- require('mason-lspconfig').setup({
|
|
-- ensure_installed = {},
|
|
-- handlers = {
|
|
-- lsp_zero.default_setup,
|
|
-- }
|
|
-- })
|
|
|
|
-- cmp Config
|
|
|
|
local cmp = require('cmp')
|
|
local cmp_action = require('lsp-zero').cmp_action()
|
|
|
|
cmp.setup({
|
|
sources = {
|
|
{name = 'path'},
|
|
{name = 'nvim_lsp'},
|
|
{name = 'nvim_lua'},
|
|
{name = 'luasnip'},
|
|
{name = 'cmp_luasnip'},
|
|
{name = 'buffer'},
|
|
{name = 'neorg'}
|
|
},
|
|
window = {
|
|
completion = cmp.config.window.bordered(),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
formatting = {
|
|
fields = {'abbr', 'kind', 'menu'},
|
|
format = require('lspkind').cmp_format({
|
|
mode = 'symbol', -- show only symbol annotations
|
|
maxwidth = 50, -- prevent the popup from showing more than provided characters
|
|
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
|
|
})
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<CR>'] = cmp.mapping.confirm({select = false}),
|
|
-- scroll up and down the documentation window
|
|
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-d>'] = cmp.mapping.scroll_docs(4),
|
|
-- ['<Tab>'] = cmp_action.luasnip_supertab(),
|
|
-- ['<S-Tab>'] = cmp_action.luasnip_shift_supertab(),
|
|
}),
|
|
})
|
|
|
|
-- Server configs
|
|
|
|
-- vue
|
|
require('lspconfig').volar.setup({})
|
|
|
|
-- typescript / javascript
|
|
require'lspconfig'.tsserver.setup{
|
|
filetypes = {
|
|
"javascript",
|
|
"typescript",
|
|
"vue",
|
|
},
|
|
}
|
|
|
|
end,
|
|
}
|