mirror of
https://codeberg.org/Mo8it/dotfiles.git
synced 2025-01-07 15:59:19 +00:00
154 lines
3.7 KiB
Lua
154 lines
3.7 KiB
Lua
-- 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 formatting_augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
local function format_on_save(client, bufnr)
|
|
if client.supports_method("textDocument/formatting") then
|
|
vim.api.nvim_clear_autocmds({
|
|
group = formatting_augroup,
|
|
buffer = bufnr,
|
|
})
|
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
group = formatting_augroup,
|
|
buffer = bufnr,
|
|
callback = function()
|
|
-- NOTE: On 0.8, use vim.lsp.buf.format({ bufnr = bufnr }) instead
|
|
vim.lsp.buf.formatting_sync(nil, 60000)
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
|
|
local lsp_signature = require("lsp_signature")
|
|
lsp_signature_config = {
|
|
bind = true,
|
|
doc_lines = 0,
|
|
hint_prefix = "💡 ",
|
|
handler_opts = {
|
|
border = "single",
|
|
},
|
|
transparency = 10,
|
|
}
|
|
|
|
lspconfig["pylsp"].setup({
|
|
capabilities = capabilities,
|
|
on_attach = function(client, bufnr)
|
|
lsp_signature.on_attach(lsp_signature_config)
|
|
|
|
-- Disable formatting
|
|
client.resolved_capabilities.document_formatting = false
|
|
client.resolved_capabilities.document_range_formatting = false
|
|
end,
|
|
})
|
|
|
|
local function on_attach_with_formatting(client, bufnr)
|
|
lsp_signature.on_attach(lsp_signature_config)
|
|
format_on_save(client, bufnr)
|
|
end
|
|
|
|
lspconfig["julials"].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach_with_formatting,
|
|
})
|
|
|
|
lspconfig["clangd"].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach_with_formatting,
|
|
})
|
|
|
|
-- null-ls
|
|
local null_ls = require("null-ls")
|
|
|
|
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.fish_indent,
|
|
null_ls.builtins.formatting.shellharden,
|
|
null_ls.builtins.formatting.shfmt,
|
|
null_ls.builtins.formatting.taplo,
|
|
null_ls.builtins.formatting.sqlfluff.with({
|
|
extra_args = {
|
|
"--dialect",
|
|
"sqlite",
|
|
"--exclude-rules",
|
|
"L004,L013,L014,L016,L020,L021,L029,L031,L032,L033,L042,L059",
|
|
},
|
|
}),
|
|
},
|
|
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" },
|
|
},
|
|
})
|