nvim/lua/plugs/nvim-lspconfig.lua
2023-11-25 23:42:01 +08:00

166 lines
4.5 KiB
Lua

local kind_icons = {
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 = "󰅲",
}
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
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
return {
{
-- lsp的config
"neovim/nvim-lspconfig",
config = function ()
require'lspconfig'.lua_ls.setup(require('lsp.lua'))
require'lspconfig'.clangd.setup(require('lsp.c'))
require'lspconfig'.bash_ls.setup(require('lsp.bash'))
require'lspconfig'.pyright.setup(require('lsp.pyright'))
end
},
{
-- lsp 下载器
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
end
},
{
-- lsp补全
'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' }
'hrsh7th/cmp-buffer', -- { name = 'buffer' },
'hrsh7th/cmp-path', -- { name = 'path' }
'hrsh7th/cmp-cmdline', -- { name = 'cmdline' }
'hrsh7th/vim-vsnip',
'hrsh7th/cmp-vsnip',
'onsails/lspkind-nvim',
{
"hrsh7th/nvim-cmp",
config = function()
local cmp = require('cmp')
local lspkind = require('lspkind')
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
sources = cmp.config.sources({
{ name = 'vnsip'},
{ name = 'nvim_lsp' },
{ name = 'buffer' },
-- { name = 'path' },
-- { name = 'cmdline' },
}),
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<c-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<n-p>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
}),
window = {
},
fomatting = {
format = lspkind.cmp_format({
with_text = true,
maxwidth = 50,
mode = 'symbol',
before = function (entry, vim_item)
vim_item.kind = kind_icons[vim_item.kind]
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
})[entry.source.name]
return vim_item
end,
})
},
}
cmp.setup.cmdline('/', {
view = {
entries = {name = 'wildmenu', separator = '|' }
},
})
end,
},
{
-- 语法高亮 --
'nvim-treesitter/nvim-treesitter',
config = function()
require'nvim-treesitter.configs'.setup{
ensure_installed = {},
indent = { enable = true },
sync_install = false,
auto_install = true,
highlight = {
enable = true,
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
additional_vim_regex_highlighting = false,
},
parsers = {
html = {
install_info = {
url = "https://github.com/ikatyang/tree-sitter-vue",
files = {"src/parser.c"},
branch = "main"
}
}
}
}
end
},
}
}