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
Comments
Can you consistently reproduce this error? Does the folder with spaces always show errors or only occasionally? |
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 |
Update: I also encountered it today on the same project under folder |
Thanks for sharing. We will investigate this issue. |
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 :-) |
It only happens to me when I am opening one of the files in the VSCode workspace.
When it's declared as:
In a tls.go file in the same folder. |
@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? |
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. |
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. |
@terender: Your comment sounds more related to #32394. You are correct, 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 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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 workaroundI fixed this issue by changing the folder
Visual Studio Code
that I put my projects under, toVSCode
(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.
The text was updated successfully, but these errors were encountered: