Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting a completion logs a weird message to statusline #3272

Closed
daturkel opened this issue Aug 6, 2021 · 13 comments
Closed

Accepting a completion logs a weird message to statusline #3272

daturkel opened this issue Aug 6, 2021 · 13 comments

Comments

@daturkel
Copy link

daturkel commented Aug 6, 2021

What did you do? (required: The issue will be closed when not provided)

In a go file, trigger a completion and then accept it. For example:

package main

import "time"

func main () {
    time.S
}

Hitting tab after the time.S will pop up a suggestion for time.Sleep, and selecting it with enter inserts it.

What did you expect to happen?

I expect the completion to be inserted and the statusline to remain unchanged.

What happened instead?

The completion is inserted but an odd message gets written to the statusline:

vim-go: {"cid":1628215692,"source":"languageserver.golang","index":0}

Is there a way to disable this message?

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce:

vimrc

Vim version (first three lines from :version):

NVIM v0.5.0
Build type: Release
LuaJIT 2.1.0-beta3

Go version (go version):

go version go1.16.6 darwin/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/danturkel/Library/Caches/go-build"
GOENV="/Users/danturkel/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/danturkel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/danturkel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mp/y42rb3dx093cj65yb930b28m0000gp/T/go-build584612645=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.7.0
    golang.org/x/tools/[email protected] h1:JQBHW81Gsyim6iDjUwGoPeSpXrSqwen3isPJLfDfaYU=

vim-go configuration:

vim-go configuration
g:go_def_mode = 'gopls'
g:go_auto_type_info = 1
g:go_jump_to_error = 1
g:go_highlight_methods = 1
g:go_info_mode = 'gopls'
g:go_doc_popup_window = 1
g:go_highlight_structs = 1
g:go_loaded_gosnippets = 1
g:go_highlight_functions = 1
g:go_highlight_operators = 1
g:go_loaded_install = 1
g:go_highlight_build_constraints = 1
g:go_highlight_interfaces = 1
g:go_def_mapping_enabled = 0

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:ON
@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

I'm not able to duplicate what you're describing. When I try the same thing I don't see any such message output either on the statusline or on the last line of the screen (I think that when you say statusline, you mean the last line of the screen, which is distinct from the statusline - can you confirm?).

@daturkel
Copy link
Author

daturkel commented Aug 6, 2021

Thanks for the quick response.

I do mean the last line. I've attached a screenshot to clarify. It starts with vim-go: which makes me think it's coming from vim-go extension.

I should note I'm also using neoclide/coc for completion, though the folks in the coc gitter.im channel didn't seem to think it was coc-related.

Screen Shot 2021-08-06 at 10 13 47 AM

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

I agree that it's coming from vim-go, but I'm not sure how or why, and I can't duplicate what you're describing.

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

It might be useful to see the messages from the gopls log window. Can you execute :let g:go_debug=['lsp'] before doing the completion, and then provide me with the contents of the gopls log window after you see the message?

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

I'm not sure why there would be a vim-go message for this, but it's highly suspicious that you're using coc for completion. Can you duplicate this using vim-go's completion without coc?

What's does set omnifunc? output for you?

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

After looking at the coc code, I'm virtually certain that this is happening because of the coc code that tries to extend the completion time.

You can disable this entirely by using let g:go_echo_go_info=0. Note, though, that you also won't see identifier information in that area when coc hasn't extended the completion time.

@daturkel
Copy link
Author

daturkel commented Aug 6, 2021

With coc still on:
set omnifunc returns: omnifunc=go#complete#Complete

Enabling the lsp log before doing the completion gives me this rather large log:

===== sent =====
Content-Length: 265

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\t\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 6}}}
===== sent =====
Content-Length: 267

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tfm\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 8}}}
===== received =====
Content-Length: 445

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/danturkel/Desktop/ain.go","version":8,"diagnostics":[{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":3}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredName"},"source":"compiler","message":"undeclared name: fm","tags":[1]}]}}
===== sent =====
Content-Length: 268

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tfmt\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 9}}}
===== received =====
Content-Length: 447

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/danturkel/Desktop/main.go","version":9,"diagnostics":[{"range":{"start":{"line":6,"character":1},"end":{"line":6,"character":4}},"severity":1,"code":"InvalidPkgUse","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#InvalidPkgUse"},"source":"compiler","message":"use of package fmt not in selector"}]}}
===== sent =====
Content-Length: 271

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tfmt.P\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 13}}}
===== sent =====
Content-Length: 185

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 4, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 6, "line": 6}}}
===== received =====
Content-Length: 100

{"jsonrpc":"2.0","error":{"code":0,"message":"no object found for ident P: no object found"},"id":4}
===== received =====
Content-Length: 461

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/danturkel/Desktop/main.go","version":13,"diagnostics":[{"range":{"start":{"line":6,"character":5},"end":{"line":6,"character":6}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredImportedName"},"source":"compiler","message":"P not declared by package fmt"}]}}
===== sent =====
Content-Length: 273

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tfmt.Pri\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 25}}}
===== sent =====
Content-Length: 185

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 5, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 8, "line": 6}}}
===== received =====
Content-Length: 102

{"jsonrpc":"2.0","error":{"code":0,"message":"no object found for ident Pri: no object found"},"id":5}
===== received =====
Content-Length: 463

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/danturkel/Desktop/main.go","version":25,"diagnostics":[{"range":{"start":{"line":6,"character":5},"end":{"line":6,"character":8}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredImportedName"},"source":"compiler","message":"Pri not declared by package fmt"}]}}
===== sent =====
Content-Length: 185

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 6, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 8, "line": 6}}}
===== received =====
Content-Length: 102

{"jsonrpc":"2.0","error":{"code":0,"message":"no object found for ident Pri: no object found"},"id":6}
===== sent =====
Content-Length: 185

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 7, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 8, "line": 6}}}
===== received =====
Content-Length: 102

{"jsonrpc":"2.0","error":{"code":0,"message":"no object found for ident Pri: no object found"},"id":7}
===== sent =====
Content-Length: 279

{"method": "textDocument/didChange", "jsonrpc": "2.0", "params": {"contentChanges": [{"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"vim-go\")\n\tfmt.Println()\n}\n"}], "textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go", "version": 36}}}
===== received =====
Content-Length: 149

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/danturkel/Desktop/main.go","version":36,"diagnostics":[]}}
===== sent =====
Content-Length: 186

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 8, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 12, "line": 6}}}
===== received =====
Content-Length: 184

{"jsonrpc":"2.0","result":[{"uri":"file:///usr/local/Cellar/go/1.16.6/libexec/src/fmt/print.go","range":{"start":{"line":272,"character":5},"end":{"line":272,"character":12}}}],"id":8}
===== sent =====
Content-Length: 202

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 9, "params": {"textDocument": {"uri": "file:///usr/local/Cellar/go/1.16.6/libexec/src/fmt/print.go"}, "position": {"character": 5, "line": 272}}}
===== received =====
Content-Length: 713

{"jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"{\"signature\":\"func Println(a ...interface{}) (n int, err error)\",\"singleLine\":\"func Println(a ...interface{}) (n int, err error)\",\"synopsis\":\"Println formats using the default formats for its operands and writes to standard output.\",\"fullDocumentation\":\"Println formats using the default formats for its operands and writes to standard output.\\nSpaces are always added between operands and a newline is appended.\\nIt returns the number of bytes written and any write error encountered.\\n\",\"linkPath\":\"fmt\",\"linkAnchor\":\"Println\"}"},"range":{"start":{"line":272,"character":5},"end":{"line":272,"character":12}}},"id":9}
===== sent =====
Content-Length: 187

{"method": "textDocument/definition", "jsonrpc": "2.0", "id": 10, "params": {"textDocument": {"uri": "file:///Users/danturkel/Desktop/main.go"}, "position": {"character": 12, "line": 6}}}
===== received =====
Content-Length: 185

{"jsonrpc":"2.0","result":[{"uri":"file:///usr/local/Cellar/go/1.16.6/libexec/src/fmt/print.go","range":{"start":{"line":272,"character":5},"end":{"line":272,"character":12}}}],"id":10}
===== sent =====
Content-Length: 203

{"method": "textDocument/hover", "jsonrpc": "2.0", "id": 11, "params": {"textDocument": {"uri": "file:///usr/local/Cellar/go/1.16.6/libexec/src/fmt/print.go"}, "position": {"character": 5, "line": 272}}}
===== received =====
Content-Length: 714

{"jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"{\"signature\":\"func Println(a ...interface{}) (n int, err error)\",\"singleLine\":\"func Println(a ...interface{}) (n int, err error)\",\"synopsis\":\"Println formats using the default formats for its operands and writes to standard output.\",\"fullDocumentation\":\"Println formats using the default formats for its operands and writes to standard output.\\nSpaces are always added between operands and a newline is appended.\\nIt returns the number of bytes written and any write error encountered.\\n\",\"linkPath\":\"fmt\",\"linkAnchor\":\"Println\"}"},"range":{"start":{"line":272,"character":5},"end":{"line":272,"character":12}}},"id":11}
m

If I disable coc, completion doesn't function at all (either with tab or with <C-X><C-O>


Setting let g:go_echo_go_info=0 seems to give an acceptable result. Identifiers don't show up on the line during completion, but neither does the annoying message.

Do you have any tips on what I might ask the coc community about how to disable the coc behavior that's causing this? Even just a link to the relevant area in the code would be helpful. Thanks!

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 6, 2021

If I disable coc, completion doesn't function at all (either with tab or with

That's quite odd. It's hard to know why that might be, but I suspect you have your coc configuration setup to hook into vim-go's go#comlete#Complete function and without coc you need to set omnifunc yourself (e.g. set omnifunc=go#complete#Complete).

Do you have any tips on what I might ask the coc community about how to disable the coc behavior that's causing this? Even just a link to the relevant area in the code would be helpful. Thanks!

It's around here: https://github.com/neoclide/coc.nvim/blob/c49acf35d8c32c16e1f14ab056a15308e0751688/src/completion/complete.ts#L245 and how that interacts with vim-go when g:go_echo_go_info is set: https://github.com/fatih/vim-go/blob/master/autoload/go/auto.vim#L50-L69.

@daturkel
Copy link
Author

daturkel commented Aug 7, 2021

I realized my broken omnifunc was due to a clash with a completely unrelated shortcut that was intercepting <C-X> commands. Disabling that and disabling coc, omnifunc works as expected, including when selecting an suggestion. Thus this is not a bug with vim-go (per se), so I'll close the issue and reach out to the coc folks with the info you've provided.

Thanks!

@daturkel daturkel closed this as completed Aug 7, 2021
@daturkel
Copy link
Author

daturkel commented Aug 9, 2021

Just a follow-up on this, CoC author @chemzqm said:

[the message] must exists to identify complete item, vim-go should not echo that
vim-go should only echo user_data from itself.

I think this is ultimately just a case of an unfortunate interaction between the two plugins

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 9, 2021

That seems like an odd answer given that the CompleteDone event identifies the completed item in v:completed_item 🤷

I can add a workaround to vim-go for this.

bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 9, 2021
Return early from the CompleteDone handler when omnifunc is not set to
go#complete#Complete.

This should help interactions with other plugins like coc.nvim that some
users leverage to do completion.

Relates to fatih#3272
@bhcleek
Copy link
Collaborator

bhcleek commented Aug 9, 2021

I've put up #3274 to try to workaround this for you. It's arguably the right thing to do, but I'm a little worried it won't actually work for you, because it's not clear to me how coc.nvim actually works; it seems to use neither omnifunc nor completefunc to hook into to trigger completions and if it's not, then I'm not sure how or why it would be sending CompletedDone events (and it shouldn't in that case either!). But the maintainer's suggestion that the user_data shouldn't be used by vim-go when it's not set by vim-go seems to conflict with Vim's expectations if coc.nvim isn't using completefunc or omnifunc.

@daturkel
Copy link
Author

daturkel commented Aug 9, 2021

I appreciate the quick fix, it seems to work! Truthfully I don't know much about Vim plugin implementation so I can't comment as to how Coc is behaving or what's "right" here, but I do appreciate your help on this! If this change causes issues for other uses of course it can always be rolled back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants