2023-11-24 12:59:48 +08:00
|
|
|
|
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
|
2023-11-23 18:39:37 +08:00
|
|
|
|
|
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",
|
2023-11-27 18:33:57 +08:00
|
|
|
|
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'))
|
2023-11-27 18:19:55 +08:00
|
|
|
|
G.map({
|
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-11-28 13:05:29 +08:00
|
|
|
|
{ 'n', '<leader>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-11-23 18:39:37 +08:00
|
|
|
|
-- lsp 下载器
|
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
|
|
|
|
|
},
|
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-11-28 13:05:29 +08:00
|
|
|
|
{ "n", "<leader>o", "<cmd>SymbolsOutline<cr>" },
|
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/cmp-nvim-lsp', -- { name = 'nvim_lua' }
|
|
|
|
|
'hrsh7th/cmp-buffer', -- { name = 'buffer' },
|
|
|
|
|
'hrsh7th/cmp-path', -- { name = 'path' }
|
|
|
|
|
'hrsh7th/cmp-cmdline', -- { name = 'cmdline' }
|
2023-11-23 18:39:37 +08:00
|
|
|
|
'hrsh7th/vim-vsnip',
|
2023-11-23 13:19:07 +08:00
|
|
|
|
'hrsh7th/cmp-vsnip',
|
2023-11-24 12:59:48 +08:00
|
|
|
|
'onsails/lspkind-nvim',
|
2023-11-22 12:59:44 +08:00
|
|
|
|
{
|
|
|
|
|
"hrsh7th/nvim-cmp",
|
2023-11-23 13:19:07 +08:00
|
|
|
|
config = function()
|
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 {
|
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({
|
2023-11-27 18:33:57 +08:00
|
|
|
|
{ name = 'vnsip' },
|
2023-11-22 12:59:44 +08:00
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
|
{ name = 'buffer' },
|
2023-11-26 00:19:51 +08:00
|
|
|
|
{ name = 'path' },
|
2023-11-26 18:09:36 +08:00
|
|
|
|
{ name = 'cmdline' },
|
2023-11-22 12:59:44 +08:00
|
|
|
|
}),
|
2023-11-23 13:19:07 +08:00
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
2023-11-24 12:59:48 +08:00
|
|
|
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
|
|
|
|
["<c-n>"] = 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-11-24 12:59:48 +08:00
|
|
|
|
["<n-p>"] = 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-11-23 13:19:07 +08:00
|
|
|
|
}),
|
|
|
|
|
window = {
|
|
|
|
|
},
|
|
|
|
|
fomatting = {
|
|
|
|
|
format = lspkind.cmp_format({
|
2023-11-24 12:59:48 +08:00
|
|
|
|
with_text = true,
|
2023-11-23 18:39:37 +08:00
|
|
|
|
maxwidth = 50,
|
2023-11-24 12:59:48 +08:00
|
|
|
|
mode = 'symbol',
|
2023-11-27 18:33:57 +08:00
|
|
|
|
before = function(entry, vim_item)
|
2023-11-24 12:59:48 +08:00
|
|
|
|
vim_item.kind = kind_icons[vim_item.kind]
|
|
|
|
|
vim_item.menu = ({
|
|
|
|
|
buffer = "[Buffer]",
|
|
|
|
|
nvim_lsp = "[LSP]",
|
|
|
|
|
})[entry.source.name]
|
2023-11-23 13:19:07 +08:00
|
|
|
|
return vim_item
|
2023-11-24 12:59:48 +08:00
|
|
|
|
end,
|
2023-11-23 13:19:07 +08:00
|
|
|
|
})
|
|
|
|
|
},
|
2023-11-22 12:59:44 +08:00
|
|
|
|
}
|
2023-11-24 12:59:48 +08:00
|
|
|
|
cmp.setup.cmdline('/', {
|
|
|
|
|
view = {
|
2023-11-27 18:33:57 +08:00
|
|
|
|
entries = { name = 'wildmenu', separator = '|' }
|
2023-11-24 12:59:48 +08:00
|
|
|
|
},
|
|
|
|
|
})
|
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()
|
|
|
|
|
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
|
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
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
}
|