Конфиги nvim
This commit is contained in:
parent
17951e8c06
commit
d348344938
12 changed files with 577 additions and 2 deletions
65
nvim/lua/lsp.lua
Normal file
65
nvim/lua/lsp.lua
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
local cmp = require('cmp')
|
||||
|
||||
local source_mapping = {
|
||||
buffer = '[Buffer]',
|
||||
nvim_lsp = '[LSP]',
|
||||
nvim_lua = '[Lua]',
|
||||
cmp_tabnine = '[TN]',
|
||||
path = '[Path]',
|
||||
}
|
||||
|
||||
cmp.setup({
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-u>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
}),
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
local menu = source_mapping[entry.source.name]
|
||||
vim_item.menu = menu
|
||||
return vim_item
|
||||
end
|
||||
},
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' },
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
})
|
||||
|
||||
-- инициализация LSP для различных ЯП
|
||||
local lspconfig = require('lspconfig')
|
||||
local util = require('lspconfig/util')
|
||||
|
||||
local function config(_config)
|
||||
return vim.tbl_deep_extend('force', {
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
}, _config or {})
|
||||
end
|
||||
|
||||
-- иницализация gopls LSP для Go
|
||||
-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-install
|
||||
lspconfig.gopls.setup(config({
|
||||
on_attach = on_attach,
|
||||
cmd = { 'gopls', 'serve' },
|
||||
filetypes = { 'go', 'go.mod' },
|
||||
root_dir = util.root_pattern('go.work', 'go.mod', '.git'),
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
shadow = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
}
|
||||
}
|
||||
}))
|
Loading…
Add table
Add a link
Reference in a new issue