parent
8791fafd4e
commit
80c99fed33
|
@ -13,6 +13,26 @@ require("plugins.configs.others").lsp_handlers()
|
|||
local win = require "lspconfig.ui.windows"
|
||||
local _default_opts = win.default_opts
|
||||
|
||||
-- Organize import for GOLang
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = { "*.go" },
|
||||
callback = function()
|
||||
local params = vim.lsp.util.make_range_params(nil, vim.lsp.util._get_offset_encoding())
|
||||
params.context = { only = { "source.organizeImports" } }
|
||||
|
||||
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
|
||||
for _, res in pairs(result or {}) do
|
||||
for _, r in pairs(res.result or {}) do
|
||||
if r.edit then
|
||||
vim.lsp.util.apply_workspace_edit(r.edit, vim.lsp.util._get_offset_encoding())
|
||||
else
|
||||
vim.lsp.buf.execute_command(r.command)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
win.default_opts = function(options)
|
||||
local opts = _default_opts(options)
|
||||
opts.border = "single"
|
||||
|
|
Loading…
Reference in New Issue