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/cmd/gopls: textDocument/definition fails on error type variable #31465

Closed
myitcv opened this issue Apr 15, 2019 · 1 comment
Closed

x/tools/cmd/gopls: textDocument/definition fails on error type variable #31465

myitcv opened this issue Apr 15, 2019 · 1 comment

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Apr 15, 2019

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

$ go version
go version go1.12.3 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20190406165526-0d5674b3111a

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
GOARCH="amd64"
GOBIN="/home/myitcv/gostuff/src/github.com/myitcv/govim/cmd/govim/.bin"
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build854233279=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Consider the following govim testscript in which I attempt a jump to a couple of definitions from a main package.

# Test that GOVIMGoToDef works on flag.ErrHelp

# os.Exit
vim ex 'e main.go'
vim ex 'call cursor(12,6)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout 'src[/\\]os[/\\]proc.go"$'
! stderr .+

# flag.ErrHelp
vim ex 'e main.go'
vim ex 'call cursor(13,12)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout 'src[/\\]flag[/\\]flag.go"$'
! stderr .+

-- go.mod --
module mod.com

-- main.go --
package main

import (
	"flag"
	"os"
)

func main() {
	var err error
	switch err {
	case nil:
		os.Exit(0)
	case flag.ErrHelp:
		os.Exit(2)
	default:
		os.Exit(1)
	}
}

What did you expect to see?

The test to pass.

What did you see instead?

An error on the second "jump to definition": "invalid position for error"

# Test that GOVIMGoToDef works on flag.ErrHelp
# os.Exit (1.031s)
# flag.ErrHelp (0.049s)
> vim ex 'e main.go'
> vim ex 'call cursor(13,12)'
> vim ex 'GOVIMGoToDef'
[stderr]
unexpected command error: failed to ex(GOVIMGoToDef) in Vim: Caught 'got error whilst handling command:GOVIMGoToDef: failed to call gopls.Definition: invalid position for error
params were: &protocol.TextDocumentPositionParams{
    TextDocument: protocol.TextDocumentIdentifier{URI:"file://$WORK/main.go"},
    Position:     protocol.Position{Line:12, Character:11},
}' in function <SNR>2_define[38]..<SNR>2_callbackCommand, line 5
[exit status 255]
FAIL: testdata/go_to_def_error.txt:14: unexpected command failure

cc @stamblerre @ianthehat

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 15, 2019

Change https://golang.org/cl/172117 mentions this issue: internal/lsp: handle definitions for variables with error types

@golang golang locked and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.