Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Antoine Cotten uploaded patch set #3 to this change.
gopls: Improve auto-imports example for NeoVim LSP
Follow Lua Style Guide for function names.
Query the client's offset encoding, with a fallback to utf-8.
Omit handling of r.command since the source.organizeImports code action
doesn't return any.
Omit passing a value for wait_ms. It is optional and defaults to 1000
(see NeoVim help for vim.lsp.buf_request_sync).
Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
---
M gopls/doc/vim.md
1 file changed, 24 insertions(+), 6 deletions(-)
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Antoine Cotten uploaded patch set #2 to this change.
gopls: Improve auto-imports example for NeoVim LSP
Follow Lua Style Guide for function names.
Query the client's offset encoding, with a fallback to utf-8.
Omit handling of r.command since the source.organizeImports code action
doesn't return any.
Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
---
M gopls/doc/vim.md
1 file changed, 20 insertions(+), 5 deletions(-)
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Antoine Cotten has uploaded this change for review.
gopls: Improve auto-imports example for NeoVim LSP
Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
---
M gopls/doc/vim.md
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/gopls/doc/vim.md b/gopls/doc/vim.md
index d9b33ac..bd8944e 100644
--- a/gopls/doc/vim.md
+++ b/gopls/doc/vim.md
@@ -175,16 +175,15 @@
lua <<EOF
-- …
- function OrgImports(wait_ms)
+ function go_org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
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 cid, 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, "UTF-8")
- else
- vim.lsp.buf.execute_command(r.command)
+ local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
+ vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
1 comment:
File gopls/doc/vim.md:
Patch Set #3, Line 185: (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
Huh, I'm not actually sure whether this is correct.
The default offset encoding is utf-16, and many servers (gopls included!) don't support the new general.positionEncodings capability:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments
If this is doing what I think it's doing, has this always been using the wrong encoding?
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
Antoine Cotten uploaded patch set #4 to this change.
gopls: Improve auto-imports example for NeoVim LSP
Follow Lua Style Guide for function names.
Query the client's offset encoding, with a fallback to utf-16.
Omit handling of r.command since the source.organizeImports code action
doesn't return any.
Omit passing a value for wait_ms. It is optional and defaults to 1000
(see NeoVim help for vim.lsp.buf_request_sync).
Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
---
M gopls/doc/vim.md
1 file changed, 24 insertions(+), 6 deletions(-)
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim, Robert Findley.
1 comment:
File gopls/doc/vim.md:
Patch Set #3, Line 185: (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
Huh, I'm not actually sure whether this is correct. […]
Great point, I ignored that utf-16 was the default.
My main goal on this line was actually to guard against `get_client_by_id()` potentially returning `nil`, which would raise the following error:
E5108: Error executing lua [...] attempt to index global 'client' (a nil value)
I just fixed the default encoding.
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
1 comment:
File gopls/doc/vim.md:
Patch Set #3, Line 185: (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
Great point, I ignored that utf-16 was the default. […]
Thanks!
Since we're looking at it, do you think you could confirm that the previous setting was broken? For example, can you try organizing imports in the following file?
```
package main
import (
"mod.test/a𐐀b"
"fmt"
)
func main() {
fmt.Println("foo")
}
```
Does the previous setting result in corrupted state? (a𐐀b has length 6 on utf-16 and 8 on utf-8).
That would make me feel more confident that we're doing the right thing here, since I'm not familiar with the lua client.
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim, Robert Findley.
1 comment:
File gopls/doc/vim.md:
Patch Set #3, Line 185: (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
Thanks! […]
This is going to be very disappointing but no, reverting the code then executing the function manually inside the buffer yields a perfectly valid file.
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
Patch set 4:Code-Review +2
1 comment:
File gopls/doc/vim.md:
Patch Set #3, Line 185: (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-8"
This is going to be very disappointing but no, reverting the code then executing the function manual […]
Hmm... well I suppose let's merge this, as it seems more correct.
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
Patch set 4:Code-Review +1
Attention is currently required from: Antoine Cotten, Hyang-Ah Hana Kim.
Patch set 4:Code-Review +1
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.
Robert Findley submitted this change.
gopls: Improve auto-imports example for NeoVim LSP
Follow Lua Style Guide for function names.
Query the client's offset encoding, with a fallback to utf-16.
Omit handling of r.command since the source.organizeImports code action
doesn't return any.
Omit passing a value for wait_ms. It is optional and defaults to 1000
(see NeoVim help for vim.lsp.buf_request_sync).
Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421295
Reviewed-by: Dylan Le <dungt...@google.com>
Reviewed-by: Robert Findley <rfin...@google.com>
Reviewed-by: Jamal Carvalho <ja...@golang.org>
---
M gopls/doc/vim.md
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/gopls/doc/vim.md b/gopls/doc/vim.md
index d9b33ac..af54a7e 100644
--- a/gopls/doc/vim.md
+++ b/gopls/doc/vim.md
@@ -175,23 +175,22 @@
lua <<EOF
-- …
- function OrgImports(wait_ms)
+ function go_org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
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 cid, 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, "UTF-8")
- else
- vim.lsp.buf.execute_command(r.command)
+ 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
end
EOF
-autocmd BufWritePre *.go lua OrgImports(1000)
+autocmd BufWritePre *.go lua go_org_imports()
```
(Taken from the [discussion][nvim-lspconfig-imports] on Neovim issue tracker.)
To view, visit change 421295. To unsubscribe, or for help writing mail filters, visit settings.