nvim/lua/plugs/nvim-lspconfig.lua

326 lines
10 KiB
Lua
Raw Normal View History

2023-11-22 12:59:44 +08:00
return {
{
2023-11-23 18:39:37 +08:00
-- lsp的config
2023-11-22 12:59:44 +08:00
"neovim/nvim-lspconfig",
2024-01-03 14:50:03 +08:00
dependencies = {
"folke/neodev.nvim",
},
2023-11-27 18:33:57 +08:00
config = function()
2024-01-03 14:50:03 +08:00
require 'neodev'.setup {}
2023-11-27 18:33:57 +08:00
require 'lspconfig'.lua_ls.setup(require('lsp.lua'))
require 'lspconfig'.clangd.setup(require('lsp.c'))
2023-12-18 23:46:48 +08:00
require 'lspconfig'.bashls.setup(require('lsp.bash'))
2023-11-27 18:33:57 +08:00
require 'lspconfig'.pyright.setup(require('lsp.pyright'))
2023-12-19 12:08:06 +08:00
require 'lspconfig'.yamlls.setup(require('lsp.yaml'))
2024-01-06 18:44:41 +08:00
require 'lspconfig'.gopls.setup(require('lsp.go'))
2024-01-10 23:21:52 +08:00
require 'lspconfig'.jsonls.setup(require('lsp.json'))
2023-12-19 12:08:06 +08:00
2024-01-03 14:50:03 +08:00
2023-11-27 18:19:55 +08:00
G.map({
2023-12-19 07:13:58 +08:00
2023-11-27 18:33:57 +08:00
{ 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>' },
2023-11-27 18:19:55 +08:00
2023-11-27 18:33:57 +08:00
{ '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>' },
2023-12-15 12:15:39 +08:00
{ 'n', '<cs-i>', '<cmd>lua vim.lsp.buf.format()<CR>' },
2023-11-27 18:19:55 +08:00
})
2023-11-22 12:59:44 +08:00
end
2023-11-27 18:19:55 +08:00
2023-11-22 12:59:44 +08:00
},
2023-12-19 07:13:58 +08:00
{
-- lsp
"williamboman/mason-lspconfig.nvim",
2024-01-06 10:53:27 +08:00
dependencies = {
"williamboman/mason.nvim", -- lsp 下载器
},
2023-12-19 07:13:58 +08:00
config = function()
2024-01-06 10:53:27 +08:00
require "mason".setup {}
2023-12-19 07:13:58 +08:00
require("mason-lspconfig").setup({
ensure_installed = {
"clangd",
"bashls",
"pyright",
2023-12-19 12:02:11 +08:00
"lua_ls",
"jsonls",
2024-01-01 15:58:59 +08:00
"yamlls",
2024-01-06 18:44:41 +08:00
"gopls"
2023-12-19 07:13:58 +08:00
}
})
end
},
2023-11-27 18:33:57 +08:00
{ --
'simrat39/symbols-outline.nvim',
config = function()
local opts = {
2023-11-27 18:19:55 +08:00
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
2023-11-28 07:46:34 +08:00
close = { "<Esc>", "q" },
goto_location = "<Cr>",
focus_location = "h",
hover_symbol = "<C-space>",
2023-11-27 18:19:55 +08:00
toggle_preview = "K",
2023-11-28 07:46:34 +08:00
rename_symbol = "r",
code_actions = "a",
fold = "o",
unfold = "l",
fold_all = "W",
unfold_all = "E",
fold_reset = "R",
2023-11-27 18:19:55 +08:00
},
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" },
2023-11-27 18:33:57 +08:00
},
}
require("symbols-outline").setup(opts)
G.map({
2023-12-25 13:03:32 +08:00
{ "n", "<cs-o>", "<cmd>SymbolsOutline<cr>", { noremap = true } },
2023-11-27 18:33:57 +08:00
})
end
2023-11-27 18:19:55 +08:00
},
2023-11-22 12:59:44 +08:00
{
2023-11-23 18:39:37 +08:00
-- lsp补全
2023-11-22 12:59:44 +08:00
{
"hrsh7th/nvim-cmp",
2024-01-03 14:50:03 +08:00
dependencies = {
'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' }
2024-01-10 23:12:51 +08:00
'hrsh7th/cmp-buffer', -- { name = 'buffer' },
'hrsh7th/cmp-path', -- { name = 'path' }
'hrsh7th/cmp-cmdline', -- { name = 'cmdline' }
2024-01-14 19:23:34 +08:00
{
'hrsh7th/vim-vsnip',
config = function()
2024-01-14 23:16:07 +08:00
G.g.vsnip_snippet_dir = G.fn.stdpath("config") .. "/snippets"
2024-01-14 19:23:34 +08:00
end
},
2024-01-03 14:50:03 +08:00
'hrsh7th/cmp-vsnip',
'onsails/lspkind-nvim',
},
2023-11-23 13:19:07 +08:00
config = function()
2024-01-03 14:50:03 +08:00
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
2023-12-19 07:13:58 +08:00
local cmp = require('cmp')
2024-01-06 10:53:27 +08:00
local cmp_opt = {
2023-11-23 18:39:37 +08:00
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
2023-11-22 12:59:44 +08:00
sources = cmp.config.sources({
2024-01-06 10:53:27 +08:00
{ name = 'nvim_lsp' },
2024-01-14 19:23:34 +08:00
{ name = 'vsnip' },
2024-01-06 10:53:27 +08:00
},
2023-11-22 12:59:44 +08:00
{ name = 'buffer' },
2024-01-06 10:53:27 +08:00
{ name = 'path' }
),
2023-11-23 13:19:07 +08:00
mapping = cmp.mapping.preset.insert({
2023-12-19 07:16:27 +08:00
2023-12-19 07:13:58 +08:00
["<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)
2023-11-23 18:39:37 +08:00
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()
2023-11-23 13:19:07 +08:00
end
2023-11-23 18:39:37 +08:00
end, { "i", "s" }),
2023-11-22 12:59:44 +08:00
2023-12-19 07:13:58 +08:00
["<S-Tab>"] = cmp.mapping(function()
2023-11-23 18:39:37 +08:00
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
2023-11-23 13:19:07 +08:00
end
2023-11-23 18:39:37 +08:00
end, { "i", "s" }),
2023-12-19 07:13:58 +08:00
2023-11-23 13:19:07 +08:00
}),
2024-01-06 10:53:27 +08:00
2023-11-23 13:19:07 +08:00
window = {
2023-12-18 23:31:37 +08:00
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
col_offset = -3,
side_padding = 0,
border = "rounded",
2023-12-19 07:13:58 +08:00
scrollbar = false,
2023-12-18 23:31:37 +08:00
},
documentation = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
border = "rounded",
2023-12-19 07:13:58 +08:00
scrollbar = false,
2023-12-18 23:31:37 +08:00
},
2023-11-23 13:19:07 +08:00
},
2023-12-18 23:42:55 +08:00
2024-01-06 10:53:27 +08:00
formatting = {
2023-12-18 23:31:37 +08:00
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
2024-01-06 11:19:15 +08:00
local kind = require("lspkind").cmp_format({ mode = "symbol_text", maxwidth = 50, })(entry, vim_item)
2023-12-18 23:31:37 +08:00
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = " " .. (strings[1] or "") .. " "
kind.menu = " (" .. (strings[2] or "") .. ")"
return kind
end,
2023-11-23 13:19:07 +08:00
},
2023-11-22 12:59:44 +08:00
}
2024-01-06 10:53:27 +08:00
require('cmp').setup(cmp_opt)
2023-11-22 12:59:44 +08:00
end,
2023-11-27 18:33:57 +08:00
},
2023-11-27 18:19:55 +08:00
2023-11-27 18:33:57 +08:00
{
-- 语法高亮 --
'nvim-treesitter/nvim-treesitter',
config = function()
2024-01-06 10:53:27 +08:00
local treesitter_opt = {
2024-01-27 12:31:15 +08:00
ensure_installed = {
"c",
"cpp",
"python",
"java",
"lua",
"bash",
"vimdoc",
},
2023-11-27 18:33:57 +08:00
indent = { enable = true },
2024-01-20 00:48:15 +08:00
ignore_install = {
2024-01-27 12:31:15 +08:00
"txt",
"go"
2024-01-20 00:48:15 +08:00
},
2023-11-27 18:33:57 +08:00
sync_install = false,
auto_install = true,
highlight = {
enable = true,
2024-01-06 10:53:27 +08:00
disable = function(_, buf)
2023-11-27 18:33:57 +08:00
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
2023-11-23 18:39:37 +08:00
return true
2023-11-27 18:33:57 +08:00
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"
}
}
2023-11-23 18:39:37 +08:00
}
2024-01-06 10:53:27 +08:00
2023-11-23 18:39:37 +08:00
}
2024-01-06 10:53:27 +08:00
require 'nvim-treesitter.configs'.setup(treesitter_opt)
2024-01-27 12:31:15 +08:00
require 'nvim-treesitter.install'.prefer_git = true
2023-11-27 18:33:57 +08:00
end
},
2023-11-27 18:19:55 +08:00
},
{
2023-12-16 12:07:36 +08:00
'fgheng/winbar.nvim',
config = function()
require('winbar').setup({
2023-12-18 23:31:37 +08:00
enabled = true, -- 是否启动winbar
2023-12-16 12:07:36 +08:00
-- show_file_path = true, -- 是否显示文件路径
show_symbols = true, -- 是否显示函数标签
-- 颜色配置,为空,将使用默认配色
colors = {
2023-12-18 23:31:37 +08:00
path = '#aaffff', -- 路径的颜色,比如#ababab
2023-12-16 12:07:36 +08:00
file_name = '#bbbbff', -- 文件名称的颜色,比如#acacac
2024-01-03 14:50:03 +08:00
symbols = '#aaffaa', -- 函数颜色
2023-12-16 12:07:36 +08:00
},
-- 图标配置
icons = {
seperator = '>', -- 路径分割符号
editor_state = '',
lock_icon = '',
},
-- 关闭winbar的窗口
exclude_filetype = {
'help',
'startify',
'dashboard',
'packer',
'neogitstatus',
'NvimTree',
'Trouble',
'alpha',
'lir',
'Outline',
'spectre_panel',
'toggleterm',
'qf',
}
})
end
2023-11-27 18:19:55 +08:00
},
2023-11-22 12:59:44 +08:00
}