2022-03-20 04:22:56 +00:00
|
|
|
-- Add additional capabilities supported by nvim-cmp
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
|
|
|
|
|
|
|
|
local lspconfig = require("lspconfig")
|
|
|
|
|
|
|
|
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
|
|
|
|
|
|
|
local function format_on_save(client)
|
|
|
|
if client.resolved_capabilities.document_formatting then
|
|
|
|
vim.cmd([[
|
|
|
|
augroup LspFormatting
|
|
|
|
autocmd! * <buffer>
|
2022-04-06 19:17:03 +00:00
|
|
|
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 60000)
|
2022-03-20 04:22:56 +00:00
|
|
|
augroup END
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-28 02:01:30 +00:00
|
|
|
local lsp_signature = require("lsp_signature")
|
|
|
|
|
2022-03-20 04:22:56 +00:00
|
|
|
lspconfig["pylsp"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = function(client, bufnr)
|
2022-04-28 02:01:30 +00:00
|
|
|
lsp_signature.on_attach()
|
2022-03-20 04:22:56 +00:00
|
|
|
|
|
|
|
-- Disable formatting
|
|
|
|
client.resolved_capabilities.document_formatting = false
|
|
|
|
client.resolved_capabilities.document_range_formatting = false
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2022-04-28 02:01:30 +00:00
|
|
|
local function on_attach_with_formatting(client, bufnr)
|
|
|
|
lsp_signature.on_attach()
|
|
|
|
format_on_save(client)
|
|
|
|
end
|
|
|
|
|
2022-03-20 04:22:56 +00:00
|
|
|
lspconfig["julials"].setup({
|
|
|
|
capabilities = capabilities,
|
2022-04-28 02:01:30 +00:00
|
|
|
on_attach = on_attach_with_formatting,
|
|
|
|
})
|
|
|
|
|
|
|
|
lspconfig["clangd"].setup({
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = on_attach_with_formatting,
|
2022-03-20 04:22:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
-- null-ls
|
2022-04-28 02:01:30 +00:00
|
|
|
local null_ls = require("null-ls")
|
2022-03-20 04:22:56 +00:00
|
|
|
|
|
|
|
null_ls.setup({
|
|
|
|
sources = {
|
|
|
|
null_ls.builtins.formatting.black,
|
|
|
|
null_ls.builtins.formatting.isort,
|
|
|
|
null_ls.builtins.formatting.djhtml,
|
|
|
|
null_ls.builtins.formatting.prettierd,
|
|
|
|
null_ls.builtins.formatting.stylua,
|
|
|
|
null_ls.builtins.formatting.shellharden,
|
|
|
|
null_ls.builtins.formatting.shfmt,
|
|
|
|
null_ls.builtins.formatting.taplo,
|
|
|
|
},
|
|
|
|
on_attach = format_on_save,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- luasnip setup
|
|
|
|
local luasnip = require("luasnip")
|
|
|
|
|
|
|
|
-- nvim-cmp setup
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
vim.opt.completeopt = "menuone,noselect,preview"
|
|
|
|
|
|
|
|
local cmp = require("cmp")
|
|
|
|
cmp.setup({
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
require("luasnip").lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = {
|
|
|
|
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
elseif luasnip.expand_or_jumpable() then
|
|
|
|
luasnip.expand_or_jump()
|
|
|
|
elseif has_words_before() then
|
|
|
|
cmp.complete()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "c", "s" }),
|
|
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
|
|
|
elseif luasnip.jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "c", "s" }),
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = "nvim_lsp" },
|
|
|
|
{ name = "luasnip" },
|
|
|
|
{ name = "buffer" },
|
|
|
|
{ name = "path" },
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Use buffer source for "/"
|
|
|
|
cmp.setup.cmdline("/", {
|
|
|
|
sources = {
|
|
|
|
{ name = "buffer" },
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Use cmdline & path source for ":"
|
|
|
|
cmp.setup.cmdline(":", {
|
|
|
|
sources = {
|
|
|
|
{ name = "path" },
|
|
|
|
{ name = "cmdline" },
|
|
|
|
},
|
|
|
|
})
|