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

x/tools/gopls: new buffer does not receive diagnostics when opened #42468

Closed
zapling opened this issue Nov 9, 2020 · 4 comments
Closed

x/tools/gopls: new buffer does not receive diagnostics when opened #42468

zapling opened this issue Nov 9, 2020 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@zapling
Copy link

zapling commented Nov 9, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/andreas/.cache/go-build"
GOENV="/home/andreas/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/andreas/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/andreas/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build316798925=/tmp/go-build -gno-record-gcc-switches"

What did you do?

So I'm using gopls together with Neovim and CoC and I'm having a bit of trouble getting diagnostics to work as expected. When I open a file directly there is no issue and and can see in the logs that the client receives the diagnostics request. The problem is when I have first opened a file that have no errors and then open a new buffer in a vertical split, with a file that does have syntax errors. Here I doesn't get any diagnostics. I have to make an adjustment before I receive the diagnostics request from the language server.

This is my settings for the language server in CoC.

{
    "languageserver": {
        "golang": {
            "command": "gopls",
            "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
            "trace.server": "verbose",
            "filetypes": ["go"],
            "initializationOptions": {
                "usePlaceholders": true
            }
        }
    }
}

Here is a sample project that would replicate the issue.

go.mod
a.go
b/
b/c.go

a.go

package main

import (
	"fmt"

	"github.com/zapling/gopls_test/b"
)

func main() {
    test := b.Abc()
    fmt.Println(test)
}

c.go

package b

func Abc(s string) string {
    return "" + s
}

So the flow looks like this.

  • I start vim
  • I open c.go
  • I open a.go in a new vertical split

What did you expect to see?

I expect to get diagnostics when opening a new buffer, but there is nothing. Only when I edit something does the diagnostics come. I can see that the only thing sent is textDocument/didOpen.

This is how it looks when opening the vertical split.
Screenshot_2020-11-09_19-41-24

After doing some small change (adding a line etc), now diagnostics come.
Screenshot_2020-11-09_19-42-09

What did you see instead?

No diagnostics :(

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 9, 2020
@gopherbot gopherbot added this to the Unreleased milestone Nov 9, 2020
@stamblerre
Copy link
Contributor

stamblerre commented Nov 10, 2020

gopls always sends diagnostics (if there are any) after a textDocument/didOpen, so my guess is that this is an issue with Neovim and CoC. What is the output of gopls version? (The latest version is v0.5.2).

Also, do you have a gopls log for the session?

/cc @findleyr for more advice about Neovim and CoC

@findleyr
Copy link
Contributor

findleyr commented Nov 10, 2020

The diagnostic is there: you should be able to see it via :CocList diagnostics, or as a floating diagnostic by navigating to the line containing the error. My assumption is that coc.nvim doesn't render the error gutter UI unless the diagnostic arrives after the buffer is already open.

gopls sends the diagnostic on workspace load, and doesn't re-send it after the didOpen. @stamblerre that matches your expectation, right?

@stamblerre
Copy link
Contributor

gopls sends the diagnostic on workspace load, and doesn't re-send it after the didOpen. @stamblerre that matches your expectation, right?

Yeah, sorry, I just meant that gopls tries to send any diagnostics after every change event. If the diagnostics have already been sent, gopls will not resend them.

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 10, 2020
@zapling
Copy link
Author

zapling commented Nov 10, 2020

gopls sends the diagnostic on workspace load, and doesn't re-send it after the didOpen. @stamblerre that matches your expectation, right?

Yeah, sorry, I just meant that gopls tries to send any diagnostics after every change event. If the diagnostics have already been sent, gopls will not resend them.

Oh okay, I can see that the diagnostic are being sent when gopls is instantiated when I open c.go in the CoC logs. So I think you are correct @findleyr , CoC doesn't draw the error gutter if the diagnostics was received previously and the buffer was opened after that.

I can confirm that :CocList diagnostics show the correct diagnostic, but it does not show when navigating to the line.

Nothing wrong with gopls then, so thats good 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants