add comment and check action type neovim goimports

Change-Id: Icfb3463546a889339f96720eb3e7603361e07fc7
GitHub-Last-Rev: 5aa0708d57ee9051561d2693edcb15f054b2f9e4
GitHub-Pull-Request: golang/tools#276
Reviewed-on: https://go-review.googlesource.com/c/tools/+/294529
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
stephen 2021-02-23 06:23:38 +00:00 committed by Rebecca Stambler
parent b8d1a33f7a
commit f48e60bd82
1 changed files with 20 additions and 10 deletions

View File

@ -171,17 +171,27 @@ lua <<EOF
local params = vim.lsp.util.make_range_params()
params.context = context
local method = "textDocument/codeAction"
local resp = vim.lsp.buf_request_sync(0, method, params, timeoutms)
if resp and resp[1] then
local result = resp[1].result
if result and result[1] then
local edit = result[1].edit
vim.lsp.util.apply_workspace_edit(edit)
end
end
-- See the implementation of the textDocument/codeAction callback
-- (lua/vim/lsp/handler.lua) for how to do this properly.
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeout_ms)
if not result or next(result) == nil then return end
local actions = result[1].result
if not actions then return end
local action = actions[1]
vim.lsp.buf.formatting()
-- textDocument/codeAction can return either Command[] or CodeAction[]. If it
-- is a CodeAction, it can have either an edit, a command or both. Edits
-- should be executed first.
if action.edit or type(action.command) == "table" then
if action.edit then
vim.lsp.util.apply_workspace_edit(action.edit)
end
if type(action.command) == "table" then
vim.lsp.buf.execute_command(action.command)
end
else
vim.lsp.buf.execute_command(action)
end
end
EOF