dotfiles/neovim/after/plugin/lsp.lua

119 lines
2.8 KiB
Lua
Raw Normal View History

2022-07-25 04:23:26 +02:00
local nnoremap = require('rf.binds').nnoremap
local inoremap = require('rf.binds').inoremap
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
-- cmp
local cmp = require('cmp')
local source_mapping = {
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
nvim_lua = '[Lua]',
cmp_tabnine = '[TN]',
path = '[Path]',
}
local lspkind = require('lspkind')
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
2022-07-26 16:01:17 +02:00
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<cr>'] = cmp.mapping.confirm({ select = true }),
2022-07-25 04:23:26 +02:00
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
2022-07-26 16:01:17 +02:00
['<C-Space>'] = cmp.mapping.complete(),
2022-07-25 04:23:26 +02:00
}),
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
local menu = source_mapping[entry.source.name]
if entry.source.name == "cmp_tabnine" then
if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then
menu = entry.completion_item.data.detail .. " " .. menu
end
vim_item.kind = ""
end
vim_item.menu = menu
return vim_item
end,
},
sources = {
{ name = "cmp_tabnine" },
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
},
})
local function config(conf)
return vim.tbl_deep_extend('force', {
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
on_attch = function()
inoremap('<C-h>', function() vim.lsp.buf.signature_help() end)
end,
}, conf or {})
end
-- LSP configurations
2022-08-01 15:58:06 +02:00
local simple_language_servers = { 'tsserver', 'solargraph', 'ocamllsp' }
2022-07-25 04:23:26 +02:00
for _, v in ipairs(simple_language_servers) do
require('lspconfig')[v].setup(config())
end
require('lspconfig').gopls.setup(config({
cmd = { 'gopls', 'serve' },
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
}));
-- Lua snip
local snippets_paths = function()
local plugs = { 'friendly-snippets' }
local paths = {}
local path
local root_path = vim.env.HOME .. '/.vim/plugged/'
for _, plug in ipairs(plugs) do
path = root_path .. plug
if vim.fn.isdirectory(path) ~= 0 then
table.insert(paths, path)
end
end
return paths
end
require('luasnip.loaders.from_vscode').lazy_load({
paths = snippets_paths(),
include = nil,
exclude = {},
})
2022-07-26 16:01:17 +02:00
-- Auto complete
vim.cmd([[
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect
" Avoid showing message extra message when using completion
set shortmess+=c
]])