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: file is not part of a package when found under a folder with spaces #33001

Closed
omrishtam opened this issue Jul 9, 2019 · 11 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@omrishtam
Copy link

omrishtam commented Jul 9, 2019

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?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/omri/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/omri/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build130351290=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I updated to the latest gopls version using vscode-go to update the tool, and also tried doing it with go get golang.org/x/tools/gopls@latest. I don't have the previous version that I used, but if I recall correctly, I haven't updated it for around 2-3 months. This issue also occurred while using go version 1.12(.0).

What did you expect to see?

I expected no errors to be shown, as it did before updating the tool.

What did you see instead?

I saw this error on a few package files I have, that are not main: file:///home/omri/Documents/Visual%20Studio%20Code/Go/api-gateway/server/server.go is not part of a package.

## Temporary workaround
I fixed this issue by changing the folder Visual Studio Code that I put my projects under, to VSCode (removed the spaces), and then it didn't show the error anymore and worked correctly.

Edit: Removed temporary workaround section as it doesn't necessarily work.

@gopherbot gopherbot added this to the Unreleased milestone Jul 9, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jul 9, 2019
@stamblerre
Copy link
Contributor

Can you consistently reproduce this error? Does the folder with spaces always show errors or only occasionally?

@omrishtam
Copy link
Author

Yes, I also made sure this reproduces on Windows 10 (I encountered it first on Ubuntu 19.04), and it always shows this error on any file that is not of package main when the project is found within a folder with spaces.

@omrishtam
Copy link
Author

Update: I also encountered it today on the same project under folder VSCode (the presumable temporary workaround), and the error showed again, until I restarted Visual Studio Code, after which it didn't show again.
I don't really understand the behavior of this error so I'll edit the issue to remove the Temporary workaround section.

@stamblerre
Copy link
Contributor

Thanks for sharing. We will investigate this issue.

@stamblerre stamblerre added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 11, 2019
@marco-m
Copy link

marco-m commented Jul 13, 2019

As an additional data point, I am seeing the same error. The difference is that I don't have any folder with spaces in it. I am seeing it when the file is part of a vscode workspace.

What I noticed is the following: the error is reported by gopls when I add a comment to to the first line of the file, and the file is part of a Go package split in multiple files. If I keep the comment and just restart vscode, the error goes away :-)

@elico
Copy link

elico commented Aug 5, 2019

It only happens to me when I am opening one of the files in the VSCode workspace.
When the directory is open VSCode is not reporting on any error in the problems pan.
The issue I am seeing was changed into:

{
	"resource": "/home/eliezer/Scripts/golang-http-proxy/config.go",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "undeclared name: CertificateCache",
	"source": "LSP",
	"startLineNumber": 60,
	"startColumn": 19,
	"endLineNumber": 60,
	"endColumn": 35
}

When it's declared as:

package main
....
type CertificateCache struct {
	lock        sync.RWMutex
	cache       map[certCacheKey]certCacheEntry
	TTL         time.Duration
	lastCleaned time.Time
}

In a tls.go file in the same folder.
I do not know what might even causing this issue.

@stamblerre
Copy link
Contributor

@marco-m, @elico: Can you please open new issues? It seems like the problems you are seeing are not related to the spaces in the path names, so it will be easier for me to help you troubleshoot on separate issues. Please include the information listed here.

@stamblerre
Copy link
Contributor

@omrishtam: Can you clarify your edit (the strikethrough on the workaround)? Do you still encounter errors when your code is in a folder with no spaces?

@stamblerre stamblerre added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 8, 2019
@stamblerre
Copy link
Contributor

To follow up, I tried reproducing the issue when using a folder with spaces and was unable to. It seems like something else is going on here.

@terender
Copy link

I think the vscode-go plugin should take the responsibility.

It seems vscode-go plugin assumes that there should be a go.mod file in the work-space (or the directory you chose at "Open Directory" in vscode) or it's parent directories.

If the go.mod file is in a child directory the vscode-go plugin can not find the right module that the .go file belongs to.

I've tested all the cases that I can imagine. The best practice is to place only one go.mod file in the "project path" that contains all the necessary files, then open that project path from inside vscode. In this case everything would be ok, no errors, no warinings.

@stamblerre
Copy link
Contributor

@terender: Your comment sounds more related to #32394. You are correct, gopls requires the user to open the workspace to the module root.

It seems like the majority of comments on this issue are not actually related to the folder having spaces, and as I was unable to reproduce that issue, I will mark this as closed. If others have different issues with gopls, please open new issues.

@golang golang locked and limited conversation to collaborators Aug 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants