Pim Kunis
e42a6ceacf
Add fish abbreviation for git commit --amend Don't autoformat when writing commit message in neovim
65 lines
1.9 KiB
Lua
65 lines
1.9 KiB
Lua
require("lsp-format").setup({})
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local bufmap = function(keys, func)
|
|
vim.keymap.set("n", keys, func, { buffer = bufnr })
|
|
end
|
|
|
|
bufmap("<leader>r", vim.lsp.buf.rename)
|
|
bufmap("<leader>a", vim.lsp.buf.code_action)
|
|
|
|
bufmap("gd", vim.lsp.buf.definition)
|
|
bufmap("gD", vim.lsp.buf.declaration)
|
|
bufmap("gI", vim.lsp.buf.implementation)
|
|
bufmap("<leader>D", vim.lsp.buf.type_definition)
|
|
|
|
bufmap("gr", require("telescope.builtin").lsp_references)
|
|
bufmap("<leader>s", require("telescope.builtin").lsp_document_symbols)
|
|
bufmap("<leader>S", require("telescope.builtin").lsp_dynamic_workspace_symbols)
|
|
|
|
bufmap("K", vim.lsp.buf.hover)
|
|
|
|
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
|
|
vim.lsp.buf.format()
|
|
end, {})
|
|
end
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
|
|
|
require("neodev").setup()
|
|
require("lspconfig").nil_ls.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
require("lspconfig").pyright.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
require("lspconfig").gopls.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
require("lspconfig").terraformls.setup({
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
local function has_treefmt()
|
|
local git_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
|
if vim.v.shell_error ~= 0 then
|
|
return false
|
|
end
|
|
local treefmt_path = git_root .. "/treefmt.nix"
|
|
return vim.fn.filereadable(treefmt_path) == 1
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd("BufWritePost", {
|
|
pattern = "*",
|
|
callback = function()
|
|
if vim.fn.expand("%:p") ~= vim.fn.getcwd() .. "/.git/COMMIT_EDITMSG" and has_treefmt() then
|
|
vim.cmd("silent !treefmt > /dev/null 2>&1")
|
|
end
|
|
end,
|
|
group = vim.api.nvim_create_augroup("TreefmtAutoformat", { clear = true }),
|
|
})
|