This commit is contained in:
newbie 2023-11-23 13:19:07 +08:00
parent 186f3b37af
commit 31100c0bb4
4 changed files with 110 additions and 27 deletions

View File

@ -12,7 +12,7 @@ return {
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
globals = {'vim', 'G' },
},
workspace = {
-- Make the server aware of Neovim runtime files

View File

@ -6,8 +6,8 @@ return {
'lilydjwg/colorizer', -- 颜色识别
require('plugs.coc'), -- coc
-- require('plugs.nvim-lspconfig'), --
-- require('plugs.coc'), -- coc
require('plugs.nvim-lspconfig'), --
require('plugs.lualine'), -- lualine
require('plugs.nvimtree'), -- nvimtree
require('plugs.treesitter'), -- treesitter

View File

@ -2,30 +2,13 @@ return {
{
"neovim/nvim-lspconfig",
config = function ()
require'lspconfig'.lua_ls.setup(require('lsp.lua'))
end
},
{
'williamboman/nvim-lsp-installer',
config = function ()
local lsp_installer = require "nvim-lsp-installer"
-- 安装列表
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
-- { key: 语言 value: 配置文件 }
local servers = {
sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua
}
-- 自动安装 LanguageServers
for name, _ in pairs(servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
end
"williamboman/mason.nvim",
config = function()
require("mason").setup({})
end
},
{
@ -33,22 +16,115 @@ return {
'hrsh7th/cmp-buffer', -- { name = 'buffer' },
'hrsh7th/cmp-path', -- { name = 'path' }
'hrsh7th/cmp-cmdline', -- { name = 'cmdline' }
'onsails/lspkind-nvim',
'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
},
{
"hrsh7th/nvim-cmp",
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
local cmp = require('cmp')
-- local lspkind = require('lspkind')
local lspkind = require('lspkind')
cmp.setup {
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'cmdline' },
{name = 'vnsip'},
}),
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,
['<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,
},
}
end,
}
}
}

View File

@ -16,8 +16,15 @@ return {
api.config.mappings.default_on_attach(bufnr)
-- override a default
G.map({
{'n', 'v', api.node.open.vertical, {buffer = bufnr}},
{'n', 's', api.node.open.horizontal, {buffer = bufnr}},
})
G.delmap({
{'n', '<C-e>', { buffer = bufnr }},
{'n', '<C-v>', { buffer = bufnr }},
{'n', '<C-x>', { buffer = bufnr }},
})
end