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: "full error below" in error message a bit misleading? #44735

Closed
myitcv opened this issue Mar 2, 2021 · 4 comments
Closed

x/tools/gopls: "full error below" in error message a bit misleading? #44735

myitcv opened this issue Mar 2, 2021 · 4 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Mar 2, 2021

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

$ go version
go version devel +f0be3cc547 Thu Feb 18 04:30:23 2021 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.1.1-0.20210219012152-f3748ed8ec89
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20210219012152-f3748ed8ec89

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +f0be3cc547 Thu Feb 18 04:30:23 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/go.mod"
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-build1732477030=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Start with the following scenario:

-- const.go --
package main

const hello = "hello"
-- go.mod --
module blah.com

go 1.16
-- main.go --
package main

import (
	"fmt"
)

func main() {
	fmt.Print(hello)
}
  • Open const.go in your editor
  • Then cp const.go b.go
  • Observe the diagnostics:
PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/const.go",
    Version:     1,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:0x2, Character:0x6},
                End:   protocol.Position{Line:0x2, Character:0xb},
            },
            Severity:           1,
            Code:               "DuplicateDecl",
            CodeDescription:    &protocol.CodeDescription{Href:"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#DuplicateDecl"},
            Source:             "compiler",
            Message:            "hello redeclared in this block",
            Tags:               nil,
            RelatedInformation: {
                {
                    Location: protocol.Location{
                        URI:   "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/b.go",
                        Range: protocol.Range{
                            Start: protocol.Position{Line:0x2, Character:0x6},
                            End:   protocol.Position{Line:0x2, Character:0xb},
                        },
                    },
                    Message: "other declaration of hello",
                },
            },
            Data: nil,
        },
    },
}
PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/b.go",
    Version:     0,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:0x2, Character:0x6},
                End:   protocol.Position{Line:0x2, Character:0xb},
            },
            Severity:           1,
            Code:               "DuplicateDecl",
            CodeDescription:    &protocol.CodeDescription{Href:"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#DuplicateDecl"},
            Source:             "compiler",
            Message:            "hello redeclared in this block (full error below)",
            Tags:               nil,
            RelatedInformation: {
                {
                    Location: protocol.Location{
                        URI:   "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/const.go",
                        Range: protocol.Range{
                            Start: protocol.Position{Line:0x2, Character:0x6},
                            End:   protocol.Position{Line:0x2, Character:0xb},
                        },
                    },
                    Message: "hello redeclared in this block",
                },
                {
                    Location: protocol.Location{
                        URI:   "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/b.go",
                        Range: protocol.Range{
                            Start: protocol.Position{Line:0x2, Character:0x6},
                            End:   protocol.Position{Line:0x2, Character:0xb},
                        },
                    },
                    Message: "other declaration of hello (this error)",
                },
            },
            Data: nil,
        },
    },
}

What did you expect to see?

Clear error messages for "both" duplicate declarations

What did you see instead?

hello redeclared in this block (full error below) for b.go.

It's unclear what "below" refers to here and seems rather specific to a particular presentation?

Log files:


cc @stamblerre

FYI @leitzler

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 2, 2021

Thanks for the report.

This is new functionality, and I think you're right that it depends on a particular presentation of the diagnostic related information. Perhaps we should just say something like (see related information).

CC @heschik

@heschi
Copy link
Contributor

@heschi heschi commented Mar 2, 2021

reading your diagnostics upside down.
presentation makes sense unless you like
Realistically, I don't think any other

If this is a problem for govim I would prefer to discuss what it looks like specifically, rather than having a theoretical discussion.

@myitcv
Copy link
Member Author

@myitcv myitcv commented Mar 2, 2021

It's not a problem for govim per se, I just don't know what "below" refers to. A diagnostic below? Or, as @findleyr suggested, the related information below? Because we don't show related information (yet), and if we did it wouldn't be guaranteed to be "below".

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 2, 2021

Change https://golang.org/cl/297875 mentions this issue: internal/lsp/cache: don't rely on related diagnostics if unsupported

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

Successfully merging a pull request may close this issue.

None yet
5 participants