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: Diagnostics: incorrect end column on errors containing "-" (wrong cutset in TypeErrorEndPos) #69505

Open
oversoul opened this issue Sep 17, 2024 · 2 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@oversoul
Copy link

Go version

go1.23.1

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ae/.cache/go-build'
GOENV='/home/ae/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ae/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ae/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go/'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ae/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/mnt/ddrive/Codes/golang/memo/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4126319014=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Take this example

import (
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
)

type (
	Token struct {
		Id     primitive.ObjectID `bson:"_id,omitempty"`
		Name   string             `bson:"name"`
		Token  string             `bson:"token"`
		UserId primitive.ObjectID `bson:"user_id"`
	}
        // ...
)

What did you see happen?

On editor (sublime, neovim), because of the unused import "go.mongodb.org/mongo-driver/bson"
it highlights only until the -.
Using gopls command
gopls check api/auth/models.go
the output is:

api/auth/models.go:4:2-23: "go.mongodb.org/mongo-driver/bson" imported and not used

23 here is wrong. should be 36.

What did you expect to see?

api/auth/models.go:4:2-36: "go.mongodb.org/mongo-driver/bson" imported and not used

After some research, The issue is in TypeErrorEndPos

tools/gopls/internal/analysisinternal/analysis.go Line 29

if width := bytes.IndexAny(src[offset:], " \n,():;[]+-*"); width > 0 {

after removing the hyphen, it works as expected. I did run the tests after the change but no tests seems to break.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Sep 17, 2024
@adonovan
Copy link
Member

Thanks for the thorough investigation.

The inclusion of -+* in TypeErrorEndPos logic was added in https://go.dev/cl/222237; neither the CL description nor any of the test cases reveal why. It would be interesting to instrument go/types to record whenever it produces an error containing one of these symbols, and run its tests (and run it over the standard library) to see what comes up.

@adonovan adonovan changed the title gopls: unused import end is incorrect gopls: Diagnostics: incorrect end column on errors containing "-" (wrong cutset in TypeErrorEndPos) Sep 17, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@adonovan adonovan changed the title gopls: Diagnostics: incorrect end column on errors containing "-" (wrong cutset in TypeErrorEndPos) x/tools/gopls: Diagnostics: incorrect end column on errors containing "-" (wrong cutset in TypeErrorEndPos) Sep 17, 2024
@adonovan adonovan added this to the gopls/v0.17.0 milestone Sep 17, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants