chore(nvim): code action organize imports on demand

main
sudo pacman -Syu 2023-10-02 14:30:35 +07:00
parent cee8aa959e
commit 5dcc72af1a
1 changed files with 4 additions and 13 deletions

View File

@ -578,19 +578,10 @@ require("lazy").setup({
local opts = { buffer = ev.buf } local opts = { buffer = ev.buf }
vim.keymap.set("n", "<Space>k", vim.lsp.buf.hover, opts) vim.keymap.set("n", "<Space>k", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts) vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<Space>ca", vim.lsp.buf.code_action, opts) vim.keymap.set("n", "<Space>ca", vim.lsp.buf.code_action, opts)
end, vim.keymap.set("n", "<Space>ci", function()
}) vim.lsp.buf.code_action({ context = { only = { "source.organizeImports" } }, apply = true })
end, opts)
-- Custom
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
pattern = "*.go",
callback = function()
-- Format without async then code action
-- https://github.com/neovim/neovim/issues/24168
vim.lsp.buf.format()
vim.lsp.buf.code_action({ context = { only = { "source.organizeImports" } }, apply = true })
end, end,
}) })
end, end,