Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.12.7 linux/amd64
Does this issue reproduce with the latest release?
This is the latest release.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/lumi/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/lumi/go" GOPROXY="" GORACE="" GOROOT="/var/home/lumi/bin/_go" GOTMPDIR="" GOTOOLDIR="/var/home/lumi/bin/_go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" 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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build286957175=/tmp/go-build -gno-record-gcc-switches"
What did you do?
- go mod init $packagename
- create main.go:
package main
func main(){
someFunc()
}
- create something.go:
package main
import ("fmt")
func someFunc(){
fmt.Println("Hello")
}
- configure vscode as recommended at https://github.com/golang/go/wiki/gopls:
"go.useLanguageServer": true,
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"gopls": {
"usePlaceholders": true // add parameter placeholders when completing a function
},
"files.eol": "\n", // formatting only supports LF line endings
- look at vscode problems list, after restarting vscode and opening both files.
What did you expect to see?
Nothing. This code compiles without issues.
What did you see instead?
undeclared name: someFunc
Additional info
$ gopls version
version v0.1.3-cmd.gopls, built in $GOPATH mode
The issue occurs with variables, constants, functions and types. So basically everything.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]x/tools/gopls: Undeclared name when accessing stuff from other files[/-][+]x/tools/gopls: undeclared name when accessing stuff from other files[/+][-]x/tools/gopls: undeclared name when accessing stuff from other files[/-][+]x/tools/gopls: undeclared name when accessing symbols from other files[/+]stamblerre commentedon Jul 14, 2019
Does the problem persist after you re-load the VSCode window?
jess-sch commentedon Jul 14, 2019
peterfraedrich commentedon Jul 17, 2019
Removinggo.mod
andgo.sum
and re-runninggo mod init
in my project folder works for me, however this issue does need to be resolved.Removing since it only works temporarily and in some situations.
chodyo commentedon Jul 18, 2019
I tried what you listed @peterfraedrich, but that didn't seem to work for me.
stamblerre commentedon Jul 18, 2019
This shouldn't be necessary - are either of you able to share your
gopls
logs? They can be found by going to "View: Debug Console" -> "Output" -> "Tasks" -> "gopls". Can you also try runninggopls -rpc.trace -v check /path/to/file.go
?chodyo commentedon Jul 18, 2019
Here's some recent logs for gopls in VSCode (there's a lot, can provide more if you need it)
And the trace
gogochan commentedon Jul 18, 2019
having the same issue here too.
stamblerre commentedon Jul 18, 2019
@chodyo: Looks like the
gopls check
command is working fine, but when you open your file it's being treated like an ad-hoc package - notice that the package path is listed as "command line arguments". How are you opening VSCode? Can you provide a log that starts from the beginning so that I can see thego env
thatgopls
sees? What are your VSCode settings?@ckim0419: Please provide logs so that I can help you debug.
chodyo commentedon Jul 18, 2019
Thanks @stamblerre, that sounds consistent with what I've observed while using gopls.
I think I've found the root of the problem. I have a folder/workspace open in VSCode that isn't the root of my project. My workspace is something like
~/code/a/b/myProject
. I just opened another instance of VSCode where I opened the folder directly, and gopls was able to discover the previously broken tokens.stamblerre commentedon Jul 18, 2019
@chodyo: Yes, that would be the issue - glad you were able to resolve it. We're working on improving this experience and adding error reporting - see #32394.
20 remaining items