updaate
This commit is contained in:
parent
2776a987ba
commit
d6a59bd20f
1 changed files with 21 additions and 0 deletions
21
init.lua
21
init.lua
|
|
@ -617,6 +617,27 @@ vim.api.nvim_create_autocmd('BufEnter', {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
-- Golang
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
pattern = "*.go",
|
||||||
|
callback = 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)
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Markdown
|
-- Markdown
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue