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: completion stops working when using labels #46650

Open
arp242 opened this issue Jun 8, 2021 · 5 comments
Open

x/tools/gopls: completion stops working when using labels #46650

arp242 opened this issue Jun 8, 2021 · 5 comments
Labels
gopls/parsing Issues related to parsing / poor parser recovery. 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.

Comments

@arp242
Copy link

arp242 commented Jun 8, 2021

In this (slightly contrived for demonstration purposes, but real-world) example gopls completion breaks:

func main() {
	value := 42
	v := reflect.ValueOf(&value)

sw:
	switch v.Kind() {
	case reflect.Ptr:
		v = v.Elem()
		goto sw

	case reflect.Int:
		fmt.Println("int")
	}
}

Trying to get completion on v at any point before the sw: results in a list of all completions as if completion had been initiated without typing anything (i.e. a list of packages, types, builtins, variables in scope, etc.)

It does work at any point after the label though: before, inside, and after the switch.

At first I thought it might be related to the overriding of the v variable, but it seems not; here is an even smaller (and more contrived) example:

func main() {
	t := time.Now()
show:
	fmt.Println(t)
	goto show
}

Completion doesn't work if you try to add something after the assignment to t, but does work after the label.

First observed with gopls v0.6.3, I updated to v0.6.11 and this didn't fix it, I tried the latest master (commit 4e58f8f) and this didn't fix it either. I seem to recall this worked before (0.4 or 0.2) as I use this pattern more often, but I could be 100% misremembering this and didn't verify, so don't put too much stock in that.

I normally use Vim with vim-lsc; I installed VSCode just to be sure it's not a vim-lsc problem and the behaviour there is identical, so it seems a gopls issue. The project and test case are properly set up (i.e. it has a go.mod) and everything else works fine.

Version details, screenshot, sent and received messages

screenshot_2021-06-09-00-48-45_border
screenshot_2021-06-09-00-49-00_border

$ go version
go version go1.16.4 linux/amd64

$ gopls version
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/martin/.local/gobin"
GOCACHE="/tmp/go/build"
GOENV="/home/martin/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/martin/.cache/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/martin/.cache/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR="/tmp/go/tmp"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/home/martin/go.mod"
CGO_CFLAGS="-O0 -I/usr/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-O0 -L/usr/lib"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go/tmp/go-build2465087724=/tmp/go-build -gno-record-gcc-switches"

$ cat main.go
package main

import (
        "fmt"
        "time"
)

func main() {
        t := time.Now()
start:
        fmt.Println(t)
        goto start
}

# Note: logs are from vim-lsc, not VSCode

$ cat in.log

{"method":"initialize","jsonrpc":"2.0","id":1,"params":{"rootUri":"file:///tmp/tgo_20210609_m17Wb5PU","capabilities":{"workspace":{"configuration":true,"applyEdit":true},"textDocument":{"completion":{"completionItem":{"snippetSupport":false,"tagSupport":{"valueSet":[1]},"deprecatedSupport":true}},"synchronization":{"willSaveWaitUntil":false,"willSave":false,"didSave":false},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["quickfix","refactor","source"]}}},"signatureHelp":{"dynamicRegistration":false},"hover":{"contentFormat":["plaintext","markdown"]},"definition":{"dynamicRegistration":false}}},"clientInfo":{"name":"vim-lsc"},"processId":23152,"trace":"off"}}

{"method":"initialized","jsonrpc":"2.0","params":{}}

{"method":"textDocument/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main.go","version":1,"languageId":"go","text":"package main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tt := time.Now()\nstart:\n\tfmt.Println(t)\n\tgoto start\n}\n"}}}

{"id":1,"result":[null],"jsonrpc":"2.0"}

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"range":{"end":{"character":0,"line":9},"start":{"character":0,"line":9}},"text":"\tt.\n","rangeLength":0}],"textDocument":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main.go","version":2}}}

{"method":"textDocument/completion","jsonrpc":"2.0","id":2,"params":{"textDocument":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main.go"},"position":{"character":3,"line":9}}}

{"method":"textDocument/didChange","jsonrpc":"2.0","params":{"contentChanges":[{"range":{"end":{"character":1,"line":13},"start":{"character":1,"line":13}},"text":"","rangeLength":0}],"textDocument":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main.go","version":3}}}

{"method":"shutdown","jsonrpc":"2.0","id":3}

{"method":"exit","jsonrpc":"2.0"}

$ cat out.log

{"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."],"completionItem":{}},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor.extract","refactor.rewrite","source.fixAll","source.organizeImports"]},"codeLensProvider":{},"documentLinkProvider":{},"workspaceSymbolProvider":true,"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]},"callHierarchyProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":"gopls","version":"{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.6.11\",\"sum\":\"h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.5\",\"sum\":\"h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.4.2\",\"sum\":\"h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20210220032951-036812b2e83c\",\"sum\":\"h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=\"},{\"path\":\"golang.org/x/sys\",\"version\":\"v0.0.0-20210403161142-5e06dd20ab57\",\"sum\":\"h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.1.1-0.20210504170620-03ebc2c9fca8\",\"sum\":\"h1:rTLms91GhM16y4sUcNGLdel0jJ8jXdQeXuN+7evgYiQ=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.1.3\",\"sum\":\"h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.1.1\",\"sum\":\"h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.2.0\",\"sum\":\"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\"}]}"}},"id":1}

{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":4,"message":"Loading packages..."}}

{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///tmp/tgo_20210609_m17Wb5PU","section":"gopls"}]},"id":1}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/06/09 00:36:36 go env for /tmp/tgo_20210609_m17Wb5PU\n(root /tmp/tgo_20210609_m17Wb5PU)\n(go version go version go1.16.4 linux/amd64)\n(valid build configuration = true)\n(build flags: [])\nGOMODCACHE=/home/martin/.cache/go/pkg/mod\nGOPATH=/home/martin/.cache/go\nGOROOT=/usr/lib/go\nGO111MODULE=\nGOMOD=/tmp/tgo_20210609_m17Wb5PU/go.mod\nGOINSECURE=\nGOPRIVATE=\nGOPROXY=https://proxy.golang.org,direct\nGOSUMDB=sum.golang.org\nGONOPROXY=\nGONOSUMDB=\nGOCACHE=/tmp/go/build\nGOFLAGS=\n\n"}}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/06/09 00:36:36 go/packages.Load\n\tsnapshot=0\n\tdirectory=/tmp/tgo_20210609_m17Wb5PU\n\tquery=[builtin tgo_20210609_m17Wb5PU/...]\n\tpackages=4\n"}}

{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":3,"message":"Finished loading packages."}}

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main_test.go","diagnostics":[{"range":{"start":{"line":2,"character":17},"end":{"line":2,"character":24}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredName"},"source":"compiler","message":"undeclared name: testing"},{"range":{"start":{"line":6,"character":22},"end":{"line":6,"character":29}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source=gopls#UndeclaredName"},"source":"compiler","message":"undeclared name: testing"}]}}

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///tmp/tgo_20210609_m17Wb5PU/main.go","version":2,"diagnostics":[{"range":{"start":{"line":10,"character":5},"end":{"line":10,"character":5}},"severity":1,"source":"syntax","message":"illegal label declaration"}]}}

{"jsonrpc":"2.0","result":{"isIncomplete":true,"items":[{"label":"t","labelDetails":{},"kind":6,"detail":"time.Time","preselect":true,"sortText":"00000","filterText":"t","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"t"}},{"label":"fmt","labelDetails":{},"kind":9,"detail":"\"fmt\"","sortText":"00001","filterText":"fmt","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"fmt"}},{"label":"time","labelDetails":{},"kind":9,"detail":"\"time\"","sortText":"00002","filterText":"time","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"time"}},{"label":"main","labelDetails":{},"kind":3,"detail":"func()","sortText":"00003","filterText":"main","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"main"}},{"label":"append","labelDetails":{},"kind":3,"detail":"func(slice []Type, elems ...Type) []Type","sortText":"00004","filterText":"append","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"append"}},{"label":"bool","labelDetails":{},"kind":7,"sortText":"00005","filterText":"bool","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"bool"}},{"label":"byte","labelDetails":{},"kind":7,"sortText":"00006","filterText":"byte","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"byte"}},{"label":"cap","labelDetails":{},"kind":3,"detail":"func(v Type) int","sortText":"00007","filterText":"cap","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"cap"}},{"label":"close","labelDetails":{},"kind":3,"detail":"func(c chan\u003c- Type)","sortText":"00008","filterText":"close","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"close"}},{"label":"complex","labelDetails":{},"kind":3,"detail":"func(r float64, i float64) complex128","sortText":"00009","filterText":"complex","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"complex"}},{"label":"complex128","labelDetails":{},"kind":7,"sortText":"00010","filterText":"complex128","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"complex128"}},{"label":"complex64","labelDetails":{},"kind":7,"sortText":"00011","filterText":"complex64","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"complex64"}},{"label":"copy","labelDetails":{},"kind":3,"detail":"func(dst []Type, src []Type) int","sortText":"00012","filterText":"copy","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"copy"}},{"label":"delete","labelDetails":{},"kind":3,"detail":"func(m map[Type]Type1, key Type)","sortText":"00013","filterText":"delete","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"delete"}},{"label":"error","labelDetails":{},"kind":8,"sortText":"00014","filterText":"error","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"error"}},{"label":"false","labelDetails":{},"kind":21,"sortText":"00015","filterText":"false","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"false"}},{"label":"float32","labelDetails":{},"kind":7,"sortText":"00016","filterText":"float32","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"float32"}},{"label":"float64","labelDetails":{},"kind":7,"sortText":"00017","filterText":"float64","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"float64"}},{"label":"imag","labelDetails":{},"kind":3,"detail":"func(c complex128) float64","sortText":"00018","filterText":"imag","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"imag"}},{"label":"int","labelDetails":{},"kind":7,"sortText":"00019","filterText":"int","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"int"}},{"label":"int16","labelDetails":{},"kind":7,"sortText":"00020","filterText":"int16","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"int16"}},{"label":"int32","labelDetails":{},"kind":7,"sortText":"00021","filterText":"int32","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"int32"}},{"label":"int64","labelDetails":{},"kind":7,"sortText":"00022","filterText":"int64","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"int64"}},{"label":"int8","labelDetails":{},"kind":7,"sortText":"00023","filterText":"int8","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"int8"}},{"label":"len","labelDetails":{},"kind":3,"detail":"func(v Type) int","sortText":"00024","filterText":"len","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"len"}},{"label":"make","labelDetails":{},"kind":3,"detail":"func(t Type, size ...int) Type","sortText":"00025","filterText":"make","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"make"}},{"label":"new","labelDetails":{},"kind":3,"detail":"func(Type) *Type","sortText":"00026","filterText":"new","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"new"}},{"label":"panic","labelDetails":{},"kind":3,"detail":"func(v interface{})","sortText":"00027","filterText":"panic","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"panic"}},{"label":"print","labelDetails":{},"kind":3,"detail":"func(args ...Type)","sortText":"00028","filterText":"print","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"print"}},{"label":"println","labelDetails":{},"kind":3,"detail":"func(args ...Type)","sortText":"00029","filterText":"println","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"println"}},{"label":"real","labelDetails":{},"kind":3,"detail":"func(c complex128) float64","sortText":"00030","filterText":"real","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"real"}},{"label":"recover","labelDetails":{},"kind":3,"detail":"func() interface{}","sortText":"00031","filterText":"recover","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"recover"}},{"label":"rune","labelDetails":{},"kind":7,"sortText":"00032","filterText":"rune","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"rune"}},{"label":"string","labelDetails":{},"kind":7,"sortText":"00033","filterText":"string","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"string"}},{"label":"true","labelDetails":{},"kind":21,"sortText":"00034","filterText":"true","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"true"}},{"label":"uint","labelDetails":{},"kind":7,"sortText":"00035","filterText":"uint","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uint"}},{"label":"uint16","labelDetails":{},"kind":7,"sortText":"00036","filterText":"uint16","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uint16"}},{"label":"uint32","labelDetails":{},"kind":7,"sortText":"00037","filterText":"uint32","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uint32"}},{"label":"uint64","labelDetails":{},"kind":7,"sortText":"00038","filterText":"uint64","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uint64"}},{"label":"uint8","labelDetails":{},"kind":7,"sortText":"00039","filterText":"uint8","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uint8"}},{"label":"uintptr","labelDetails":{},"kind":7,"sortText":"00040","filterText":"uintptr","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"uintptr"}},{"label":"fmt.Errorf","labelDetails":{},"kind":3,"detail":"func(format string, a ...interface{}) error","documentation":"Errorf formats according to a format specifier and returns the string as a\nvalue that satisfies error.\n\nIf the format specifier includes a %w verb with an error operand,\nthe returned error will implement an Unwrap method returning the operand. It is\ninvalid to include more than one %w verb or to supply it with an operand\nthat does not implement the error interface. The %w verb is otherwise\na synonym for %v.\n","sortText":"00041","filterText":"fmt.Errorf","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"fmt.Errorf"}},{"label":"fmt.Formatter","labelDetails":{},"kind":8,"detail":"interface{...}","documentation":"Formatter is implemented by any value that has a Format method.\nThe implementation controls how State and rune are interpreted,\nand may call Sprint(f) or Fprint(f) etc. to generate its output.\n","sortText":"00042","filterText":"fmt.Formatter","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"fmt.Formatter"}},{"label":"fmt.Fprint","labelDetails":{},"kind":3,"detail":"func(w io.Writer, a ...interface{}) (n int, err error)","documentation":"Fprint formats using the default formats for its operands and writes to w.\nSpaces are added between operands when neither is a string.\nIt returns the number of bytes written and any write error encountered.\n","sortText":"00043","filterText":"fmt.Fprint","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"fmt.Fprint"}},{"label":"nil","labelDetails":{},"kind":6,"sortText":"00047","filterText":"nil","insertTextFormat":1,"textEdit":{"range":{"start":{"line":9,"character":3},"end":{"line":9,"character":3}},"newText":"nil"}}]},"id":2}

{"jsonrpc":"2.0","result":null,"id":3}

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2021/06/09 00:36:40 Shutdown session\n\tshutdown_session=1\n"}}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 8, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jun 8, 2021
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 8, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.7.1 Jun 8, 2021
@findleyr
Copy link
Contributor

findleyr commented Jun 8, 2021

Thanks very much for the report and investigation, I can reproduce this at tip gopls.

I'll investigate what's going on.

CC @muirdm @stamblerre

@arp242
Copy link
Author

arp242 commented Jun 8, 2021

Cheers, no hurries. It's a little-used language feature and this bug can be worked around fairly easy by typing the code below the switch and moving it up.

@muirdm
Copy link

muirdm commented Jun 8, 2021

I'm guessing it looks like a selector and ends up as a BadStmt.

// looks like t.show selector
t.
show:

@arp242
Copy link
Author

arp242 commented Jun 8, 2021

Ah yeah, it does work with this:

func main() {
	t := time.Now()

	// Works here

	fmt.Println(1)

	// But not here (before or after this comment).

show:
	fmt.Println(t)
	goto show
}

It's just when it's directly before the label that it breaks. I didn't think of trying that 😅

@findleyr
Copy link
Contributor

findleyr commented Jun 8, 2021

You're ahead of me :).

Yes, confirmed this is related to parser error recovery. I'll add it to the list...

@stamblerre stamblerre modified the milestones: gopls/v0.7.1, gopls/v0.7.2 Jul 26, 2021
@stamblerre stamblerre modified the milestones: gopls/v0.7.2, gopls/on-deck Sep 9, 2021
@findleyr findleyr added the gopls/parsing Issues related to parsing / poor parser recovery. label Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/parsing Issues related to parsing / poor parser recovery. 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