fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
15.9k stars 1.45k forks source link

:GoTest sometimes on error opens file that not exists, with only one line: "package <my-package-name>" #3575

Closed vitaly-zdanevich closed 10 months ago

vitaly-zdanevich commented 10 months ago

Package name is where the error occurs.

The screenshot:

image

All my Vim configs https://gitlab.com/vitaly-zdanevich-configs/vim

vim-go version:

Vim version (first three lines from :version):

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 17 2023 20:50:44) Included patches: 1-1503 Modified by Gentoo-9.0.1503

Go version (go version):

go version go1.20.7 linux/amd64

Go environment

go env Output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vitaly/.cache/go-build"
GOENV="/home/vitaly/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-tags=unit_tests,integ_tests"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vitaly/go/pkg/mod"
GONOPROXY="github.com/River-Island/*"
GONOSUMDB="github.com/River-Island/*"
GOOS="linux"
GOPATH="/home/vitaly/go"
GOPRIVATE="github.com/River-Island/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="x86_64-pc-linux-gnu-gcc"
CXX="x86_64-pc-linux-gnu-g++"
CGO_ENABLED="1"
GOMOD="/home/vitaly/p/ri/svi/serv/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 -fdebug-prefix-map=/tmp/go-build2047110666=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:

golang.org/x/tools/gopls v0.8.4
    golang.org/x/tools/gopls@v0.8.4 h1:zGZsAXAb0LLws/Z+2BCWR17dkPHhIO2GYwYSSkeXX5c=

vim-go configuration:

vim-go configuration
g:go_loaded_gosnippets = 1
g:go_gopls_local = 'github.com/River-Island'
g:go_jump_to_error = 1
g:go_loaded_install = 1

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:OFF
vitaly-zdanevich commented 10 months ago

Looks like I found the root cause: my file name was interfaces.go but vim-go was opening interface.go - renaming of the file looks like fix it, but better to open not an interface file but test file on concrete line...

bhcleek commented 10 months ago

Vim-go gets the filename to put in the quickfix (and therefore the file to location to jump to) from the test failure. What's the output of go test in this case?

vitaly-zdanevich commented 10 months ago

With interfaces.go filename, I got this (cut related places):

        --- PASS: TestSuite_GraphService/TestProcessUpdateUsersRequest/OK:_If_CUSTOMER_ADMIN_user_is_present_both_in_Crave_and_Graph_but_the_store_is_not_enabled,_that_user_should_
NOT_be_deleted_from_Crave (0.00s)
        interface.go:74: Unexpected call to *client.MockClient.DeleteUser([context.TODO {1}]) at /home/vitaly/p/ri/svi/serv/service/crave/users.go:199 because: there are no expecte
d calls of the method "DeleteUser" for that receiver
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0001fc900, {0x89d480?, 0xc0001f2bb0}, {0x8d6214, 0xa}, {0xc0002204c0, 0x2, 0x2})
        /home/vitaly/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x334
github.com/golang/mock/gomock.(*Controller).Call(0xc0001fc900, {0x89d480, 0xc0001f2bb0}, {0x8d6214, 0xa}, {0xc0002204c0, 0x2, 0x2})
        /home/vitaly/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xad
github.com/River-Island/svi-services/pkg/crave/client/mocks.(*MockClient).DeleteUser(0xc0001f2bb0, {0x97d238?, 0xc000120018}, {0x8?})
        /home/vitaly/p/ri/svi/serv/pkg/crave/client/mocks/interface.go:74 +0xee
github.com/River-Island/svi-services/service/crave.(*ProcessorService).deleteRetiredUsers(0xc0001fc960, {0x97d238, 0xc000120018}, 0x8?, 0x8bc8a0?, {0xc00015c6c0, 0x2, 0x0?})
        /home/vitaly/p/ri/svi/serv/service/crave/users.go:199 +0x4a3
bhcleek commented 10 months ago

That go test output indicates that the filename is interface.go and that the error is on line 74.

vitaly-zdanevich commented 10 months ago

Yes, interesting... Looks like we need to rename a few of our files - drop s at the end...

bhcleek commented 10 months ago

I don't think you need to rename anything. I think the problem is in gomock, but I'm not quite sure what it is. The interface.go file that go test is referring to is /home/vitaly/p/ri/svi/serv/pkg/crave/client/mocks/interface.go. It's just a coincidence that you also have a file named interfaces.go.