mirror of
https://github.com/pnx/dotfiles
synced 2026-06-16 19:30:01 +02:00
nvim: lsp: make gopls fix those damn unused imports when iam saving the files
This commit is contained in:
parent
906bcdef24
commit
325b0856e8
1 changed files with 23 additions and 1 deletions
|
|
@ -24,7 +24,21 @@ return {
|
|||
}
|
||||
},
|
||||
gopls = {
|
||||
format_on_save = true,
|
||||
-- format_on_save = true,
|
||||
on_save = function ()
|
||||
local params = vim.lsp.util.make_range_params()
|
||||
params.context = {only = {"source.organizeImports"}}
|
||||
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 1000)
|
||||
for cid, res in pairs(result or {}) do
|
||||
for _, r in pairs(res.result or {}) do
|
||||
if r.edit then
|
||||
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
|
||||
vim.lsp.util.apply_workspace_edit(r.edit, enc)
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.lsp.buf.format({async = false})
|
||||
end,
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
|
|
@ -92,6 +106,14 @@ return {
|
|||
})
|
||||
end
|
||||
|
||||
if server_opt.on_save then
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = server_opt.on_save,
|
||||
})
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("CursorHold", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue