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
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

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

@myitcv myitcv added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. labels Mar 2, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 2, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 2, 2021
@findleyr
Copy link
Contributor

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 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 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

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

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.6.7 Mar 3, 2021
@golang golang locked and limited conversation to collaborators Mar 3, 2022
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants