edited lspconfig
This commit is contained in:
parent
28580d400e
commit
cdf4426d51
1 changed files with 64 additions and 81 deletions
|
|
@ -1,88 +1,71 @@
|
||||||
return {
|
local config = function()
|
||||||
"neovim/nvim-lspconfig",
|
-- Add additional capabilities supported by nvim-cmp
|
||||||
dependencies = {
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
local lspconfig = require('lspconfig')
|
||||||
'hrsh7th/cmp-buffer',
|
|
||||||
'hrsh7th/cmp-path',
|
-- Enable some language servers with the additional
|
||||||
'hrsh7th/cmp-cmdline',
|
-- completion capabilities offered by nvim-cmp
|
||||||
'hrsh7th/nvim-cmp',
|
local servers = { 'gopls', 'erlangls' }
|
||||||
|
for _, lsp in ipairs(servers) do
|
||||||
|
lspconfig[lsp].setup {
|
||||||
|
-- on_attach = my_custom_on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local luasnip = require 'luasnip'
|
||||||
|
|
||||||
|
local cmp = require 'cmp'
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
mapping = cmp.mapping.preset.insert({
|
||||||
config = function()
|
|
||||||
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
|
||||||
local has_words_before = function()
|
|
||||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
||||||
return
|
|
||||||
col ~= 0 and
|
|
||||||
vim.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
|
|
||||||
local cmp = require('cmp')
|
|
||||||
cmp.setup({
|
|
||||||
mapping = {
|
|
||||||
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
|
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
|
||||||
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
|
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
|
||||||
|
-- C-b (back) C-f (forward) for snippet placeholder navigation.
|
||||||
['<C-Space>'] = cmp.mapping.complete(),
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
['<CR>'] = cmp.mapping.confirm {
|
['<CR>'] = cmp.mapping.confirm {
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
select = true,
|
select = true,
|
||||||
},
|
},
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
['<Tab>'] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_next_item()
|
cmp.select_next_item()
|
||||||
elseif has_words_before() then
|
elseif luasnip.expand_or_jumpable() then
|
||||||
cmp.complete()
|
luasnip.expand_or_jump()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { 'i', 's' }),
|
||||||
["<S-Tab>"] = cmp.mapping(function()
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { 'i', 's' }),
|
||||||
},
|
}),
|
||||||
sources = cmp.config.sources({
|
sources = {
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
}, {
|
{ name = 'luasnip' },
|
||||||
{ name = 'buffer' },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
||||||
local on_attach = function(client, bufnr)
|
|
||||||
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
||||||
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
||||||
|
|
||||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
||||||
end
|
|
||||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
|
||||||
for type, icon in pairs(signs) do
|
|
||||||
local hl = "DiagnosticSign" .. type
|
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
|
||||||
end
|
|
||||||
|
|
||||||
local nvim_lsp = require('lspconfig')
|
|
||||||
nvim_lsp.gopls.setup{
|
|
||||||
cmd = {'gopls'},
|
|
||||||
on_attach = on_attach,
|
|
||||||
capabilities = capabilities,
|
|
||||||
settings = {
|
|
||||||
gopls = {
|
|
||||||
experimentalPostfixCompletions = true,
|
|
||||||
analyses = {
|
|
||||||
unusedparams = true,
|
|
||||||
shadow = true,
|
|
||||||
},
|
},
|
||||||
staticcheck = true,
|
|
||||||
gofumpt = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
init_options = {
|
|
||||||
usePlaceholders = true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
dependencies = {
|
||||||
|
'hrsh7th/nvim-cmp',
|
||||||
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
|
'saadparwaiz1/cmp_luasnip',
|
||||||
|
'L3MON4D3/LuaSnip',
|
||||||
|
},
|
||||||
|
config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue