nvim/lua/plugs/nvim-lspconfig.lua

131 lines
3.8 KiB
Lua
Raw Normal View History

2023-11-22 12:59:44 +08:00
return {
{
"neovim/nvim-lspconfig",
config = function ()
2023-11-23 13:19:07 +08:00
require'lspconfig'.lua_ls.setup(require('lsp.lua'))
2023-11-22 12:59:44 +08:00
end
},
{
2023-11-23 13:19:07 +08:00
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
2023-11-22 12:59:44 +08:00
end
},
{
'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' }
'hrsh7th/cmp-buffer', -- { name = 'buffer' },
'hrsh7th/cmp-path', -- { name = 'path' }
'hrsh7th/cmp-cmdline', -- { name = 'cmdline' }
2023-11-23 13:19:07 +08:00
'hrsh7th/cmp-vsnip',
{
'onsails/lspkind-nvim',
config = function()
require('lspkind').init({
mode = 'symbol_text',
preset = 'codicons',
symbol_map = {
Text = "󰉿",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "󰜢",
Variable = "󰀫",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "󰑭",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "󰈇",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "󰙅",
Event = "",
Operator = "󰆕",
TypeParameter = "",
},
})
end
},
2023-11-22 12:59:44 +08:00
{
"hrsh7th/nvim-cmp",
2023-11-23 13:19:07 +08:00
config = function()
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(G.api.nvim_win_get_cursor(0))
return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
end
2023-11-22 12:59:44 +08:00
local cmp = require('cmp')
2023-11-23 13:19:07 +08:00
local lspkind = require('lspkind')
2023-11-22 12:59:44 +08:00
cmp.setup {
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'cmdline' },
2023-11-23 13:19:07 +08:00
{name = 'vnsip'},
2023-11-22 12:59:44 +08:00
}),
2023-11-23 13:19:07 +08:00
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<Tab>'] = function(fallback)
if not cmp.select_next_item() then
if vim.bo.buftype ~= 'prompt' and has_words_before() then
cmp.complete()
else
fallback()
end
end
end,
2023-11-22 12:59:44 +08:00
2023-11-23 13:19:07 +08:00
['<S-Tab>'] = function(fallback)
if not cmp.select_prev_item() then
if vim.bo.buftype ~= 'prompt' and has_words_before() then
cmp.complete()
else
fallback()
end
end
end,
}),
window = {
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
col_offset = -3,
side_padding = 0,
},
},
fomatting = {
format = lspkind.cmp_format({
mode = 'symbol', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
before = function (_, vim_item)
return vim_item
end
})
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
2023-11-22 12:59:44 +08:00
}
end,
}
}
}
2023-11-23 13:19:07 +08:00