Gerrit Bot has uploaded this change for review.
gopls: update neovim documentation for imitating goimports
The existing example is no longer recommended as it can have unintended
consequences; for example, if it is run while the cursor is in an
incomplete struct, it will fill in all struct fields.
This is described more at https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-866632451
Change-Id: I3640ddb747a69c864675c0483032037a5e777d59
GitHub-Last-Rev: 2335f017eb967785da28ddb1bc48fb820d59a07e
GitHub-Pull-Request: golang/tools#371
---
M gopls/doc/vim.md
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/gopls/doc/vim.md b/gopls/doc/vim.md
index 7417d36..887a246 100644
--- a/gopls/doc/vim.md
+++ b/gopls/doc/vim.md
@@ -175,38 +175,23 @@
lua <<EOF
-- …
- function goimports(timeout_ms)
- local context = { only = { "source.organizeImports" } }
- vim.validate { context = { context, "t", true } }
-
+ function OrgImports(wait_ms)
local params = vim.lsp.util.make_range_params()
- params.context = context
-
- -- 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]
-
- -- 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)
+ params.context = {only = {"source.organizeImports"}}
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms)
+ 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)
+ else
+ vim.lsp.buf.execute_command(r.command)
+ end
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
-autocmd BufWritePre *.go lua goimports(1000)
+autocmd BufWritePre *.go lua OrgImports(1000)
```
(Taken from the [discussion][nvim-lspconfig-imports] on Neovim issue tracker.)
To view, visit change 389194. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim.
Patch set 1:Run-TryBot +1Code-Review +2Trust +1
Patch set 1:Trust +1
Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/70bd2f4b-da71-485c-826f-989e8fb29d79
Patch set 1:gopls-CI +1
Robert Findley submitted this change.
gopls: update neovim documentation for imitating goimports
The existing example is no longer recommended as it can have unintended
consequences; for example, if it is run while the cursor is in an
incomplete struct, it will fill in all struct fields.
This is described more at https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-866632451
Change-Id: I3640ddb747a69c864675c0483032037a5e777d59
GitHub-Last-Rev: 2335f017eb967785da28ddb1bc48fb820d59a07e
GitHub-Pull-Request: golang/tools#371
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389194
Reviewed-by: Robert Findley <rfin...@google.com>
Trust: Robert Findley <rfin...@google.com>
Run-TryBot: Robert Findley <rfin...@google.com>
Trust: Hyang-Ah Hana Kim <hya...@gmail.com>
gopls-CI: kokoro <noreply...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
---
M gopls/doc/vim.md
1 file changed, 35 insertions(+), 26 deletions(-)
To view, visit change 389194. To unsubscribe, or for help writing mail filters, visit settings.