nvim/lua/plugs/nvim-lspconfig.lua
2023-12-19 07:16:27 +08:00

413 lines
13 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'.bashls.setup(require('lsp.bash'))
require 'lspconfig'.pyright.setup(require('lsp.pyright'))
G.map({
{ 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>' },
{ 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>' },
{ 'n', 'gh', '<cmd>lua vim.lsp.buf.hover()<CR>' },
{ 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>' },
{ 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>' },
{ 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>' },
{ 'n', '<cs-i>', '<cmd>lua vim.lsp.buf.format()<CR>' },
})
end
},
{
-- lsp
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"clangd",
"bashls",
"pyright",
"lua_ls"
}
})
end
},
{
-- lsp 下载器
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
end
},
{ --
'simrat39/symbols-outline.nvim',
config = function()
local opts = {
highlight_hovered_item = true,
show_guides = true,
auto_preview = false,
position = 'right',
relative_width = true,
width = 25,
auto_close = false,
show_numbers = false,
show_relative_numbers = false,
show_symbol_details = true,
preview_bg_highlight = 'Pmenu',
autofold_depth = nil,
auto_unfold_hover = true,
fold_markers = { '', '' },
wrap = false,
keymaps = { -- These keymaps can be a string or a table for multiple keys
close = { "<Esc>", "q" },
goto_location = "<Cr>",
focus_location = "h",
hover_symbol = "<C-space>",
toggle_preview = "K",
rename_symbol = "r",
code_actions = "a",
fold = "o",
unfold = "l",
fold_all = "W",
unfold_all = "E",
fold_reset = "R",
},
lsp_blacklist = {},
symbol_blacklist = {},
symbols = {
File = { icon = "", hl = "@text.uri" },
Module = { icon = "", hl = "@namespace" },
Namespace = { icon = "", hl = "@namespace" },
Package = { icon = "", hl = "@namespace" },
Class = { icon = "𝓒", hl = "@type" },
Method = { icon = "ƒ", hl = "@method" },
Property = { icon = "", hl = "@method" },
Field = { icon = "", hl = "@field" },
Constructor = { icon = "", hl = "@constructor" },
Enum = { icon = "", hl = "@type" },
Interface = { icon = "", hl = "@type" },
Function = { icon = "", hl = "@function" },
Variable = { icon = "", hl = "@constant" },
Constant = { icon = "", hl = "@constant" },
String = { icon = "𝓐", hl = "@string" },
Number = { icon = "#", hl = "@number" },
Boolean = { icon = "", hl = "@boolean" },
Array = { icon = "", hl = "@constant" },
Object = { icon = "⦿", hl = "@type" },
Key = { icon = "🔐", hl = "@type" },
Null = { icon = "NULL", hl = "@type" },
EnumMember = { icon = "", hl = "@field" },
Struct = { icon = "𝓢", hl = "@type" },
Event = { icon = "🗲", hl = "@type" },
Operator = { icon = "+", hl = "@operator" },
TypeParameter = { icon = "𝙏", hl = "@parameter" },
Component = { icon = "", hl = "@function" },
Fragment = { icon = "", hl = "@constant" },
},
}
require("symbols-outline").setup(opts)
G.map({
{ "n", "<leader>o", "<cmd>SymbolsOutline<cr>", { noremap = true } },
})
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({
i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
c = function(fallback)
if cmp.visible() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
else
fallback()
end
end,
}),
["<Tab>"] = 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" }),
["<S-Tab>"] = 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 = {
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
col_offset = -3,
side_padding = 0,
border = "rounded",
scrollbar = false,
},
documentation = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
border = "rounded",
scrollbar = false,
},
},
fomatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = require("lspkind").cmp_format({
mode = "symbol_text",
maxwidth = 50,
-- 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,
})(entry, vim_item)
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = kind_icons[vim_item.kind]
kind.kind = " " .. (strings[1] or "") .. " "
kind.menu = " (" .. (strings[2] or "") .. ")"
return kind
end,
-- 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 = '|' }
},
sources = cmp.config.sources({
{ name = 'buffer' },
}),
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
["<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" }),
}),
})
cmp.setup.cmdline(':', {
view = {
entries = { name = 'wildmenu', separator = '|' }
},
sources = cmp.config.sources({
{ name = 'buffer' },
}),
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
["<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" }),
}),
})
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
},
},
{
'fgheng/winbar.nvim',
config = function()
require('winbar').setup({
enabled = true, -- 是否启动winbar
-- show_file_path = true, -- 是否显示文件路径
show_symbols = true, -- 是否显示函数标签
-- 颜色配置,为空,将使用默认配色
colors = {
path = '#aaffff', -- 路径的颜色,比如#ababab
file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac
symbols = '', -- 函数颜色
},
-- 图标配置
icons = {
seperator = '>', -- 路径分割符号
editor_state = '',
lock_icon = '',
},
-- 关闭winbar的窗口
exclude_filetype = {
'help',
'startify',
'dashboard',
'packer',
'neogitstatus',
'NvimTree',
'Trouble',
'alpha',
'lir',
'Outline',
'spectre_panel',
'toggleterm',
'qf',
}
})
end
},
}