-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/cmd/gopls: file is not part of package #33011
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
Comments
Are you able to reproduce this if the package name is not |
IIRC yes - I actually found it on a non-main package and recreated it with main. |
I got this error too. This error has gone when I reopen vscode, but it will come out at an other new open file. |
@llbox: What version of |
Even after |
I am also having this issue. Compiles fine but get an error that won't go away unless VS Code is restarted. from VS Code gopls log;
|
version v0.1.3-cmd.gopls, built in $GOPATH mode. |
When I check it manually, not via IDE: /my/path $ gopls check myfile.go
2019/07/11 15:28:58 Error:unable to check package for file:///my/path/myfile.go: loadParseTypecheck: no metadata found for /my/path/myfile.go
2019/07/11 15:28:58 Error:unable to check package for file:///my/path/myfile.go: loadParseTypecheck: no metadata found for /my/path/myfile.go
/my/path/myfile.go: file:///my/path/myfile.go is not part of a package |
I am also having this issue. Sometimes restarting the language server will resolve the issue, but then it will come back seemingly at random. The only thing that seems to permanently resolve the issue for a newly created file is to reload VS Code. This is using modules. |
@mthie, @jamiebarnett, @linguohua, @malexdev - could you share a full |
Well, I thought, I already posted the full log ;)
|
Thanks for sharing all of it, I didn't realize you were using |
I created a test project in my Downloads folder (running on Windows).
Project tree:
Contents of main.go: package main
func main() {
} Contents of go.mod: module test
go 1.12 Contents of sub/sub.go: package sub Contents of gopls log:
From this project and others it appears that the issue is when this line appears:
Edit: The Go relevant values of my VS Code settings are as follows: "go.lintFlags": [],
"go.addTags": {
"tags": "json",
"options": "",
"promptForTags": true,
"transform": "snakecase"
},
"go.buildTags": "debug",
"go.coverageOptions": "showBothCoveredAndUncoveredCode",
"go.autocompleteUnimportedPackages": false,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"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", The error doesn't always appear when creating new files; I have had some success replicating this by having another dirty file in the package with syntax errors at the time I create the new file. But then, sometimes (as in this case), no such hacks are required. So I'm wondering if this is possibly that something inside gopls gets hung up on the syntax errors in a dirty file and something gets corrupted... Please let me know if there is any more assistance I can provide! I hope this was helpful. |
@jadekler Does it work if you initialize a go.mod file first in the directory? |
@malexdev your issue seems to be different. I think it should be fixed by https://go-review.googlesource.com/c/tools/+/185839 if you want to try out that patch. |
same problem, here. gopls version I'm using visual studio 1.36.1 on windows 10 pro x64 Tree of the project : content of go.mod :
gopls output
|
@stamblerre @muirrn Thank you. I try the latest commit tody, update to commit ID:9a621aea19f8341c01da59e0d42dd97700f677d0, and test the same project on windows and linux, 'the not part of a package' problem seems to be fixed. |
@malexdev: Because you're getting the error in
to your settings? What is the output of |
Also, can you update to the latest version of |
@ravayak: In your log, it looks like "go.toolsEnvVars": {
"GO111MODULE": "on",
} to your VSCode settings? |
@stamblerre: I apologize, I didn't realize that the I added the settings specified below to my test project: "go.toolsEnvVars": {
"GO111MODULE": "on",
}, I then removed my New
The output of I also ran {
"Dir": "C:\\Users\\martinal\\Downloads\\test",
"ImportPath": "test",
"Name": "main",
"Target": "C:\\Users\\martinal\\go\\bin\\test.exe",
"Module": {
"Path": "test",
"Main": true,
"Dir": "C:\\Users\\martinal\\Downloads\\test",
"GoMod": "C:\\Users\\martinal\\Downloads\\test\\go.mod",
"GoVersion": "1.12"
},
"Match": [
"."
],
"Stale": true,
"StaleReason": "build ID mismatch",
"GoFiles": [
"main.go"
],
"CompiledGoFiles": [
"main.go"
],
"Deps": [
"internal/bytealg",
"internal/cpu",
"runtime",
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"unsafe"
]
} |
Can you try the following: ~ $ go get golang.org/x/tools/go/packages/gopackages
~ $ gopackages -mode=imports /c:/Users/martinal/Downloads/test/sub/sub.go` What directory are you opening VSCode with? |
Received output:
I am navigating to the folder ( Additionally, this may be a related issue: I'm also having some instances where functions in other files of a package fail to be recognized. If it's related and helps shed light on what's going on great, if not I will not worry about this other issue for right now - I don't want to complicate matters. |
That actually sounds a lot like #33018. Can you try the same command but with the |
Also, I assume the Edit: Earlier I mentioned "some instances" of that other error - turns out it's actually every instance where a symbol is referenced from another file in the same package. They all say |
Yeah, that is a ~ $ tree c:/Users/martinal/Downloads/test Would you be willing to share the contents of |
I am not using build tags. Output of tree (I had to use
Content of package sub
// Test is a function that tests things
func Test() {
// Do nothing
} Zipped project: And to clarify:
|
Oh, that's so strange. Can you add |
Yes, I'm really scratching my head over here too. Thanks for your patience and help! I performed the following steps:
Trace enabled log:
|
What happens if you reload the VSCode window without deleting the directories? |
Reloading the window without removing the directories resolves the issue until another directory is added. |
With the latest gopls build, another thing is, when there are some files opened in vscode, then type restart language server in the vscode's command popup to restart gopls, then some file will got the 'not part of package' error. But if only one file opened, or no file opened, then everything is ok. as malexdev log output, the problem relative to the log string: 'has an invalid position'.
I think, if there are error occur when try to parse a go file, then next vscode request, gopls should discard anything of this file, and reload the file to parse again. |
@stamblerre I tryed the latest commit and added
and still got errors :
|
@stamblerre Ok, i've just moved my project to another directory (it was in GOPATH/src originally) and then have updated my imports. It seems to solve the issue. My i didn't know that module support is enabled only when the current directory is outside |
If you have |
@stamblerre Yes, it is |
Glad to hear it. I'm going to close this issue for now. If anyone on this thread is still experiencing problems, please open a new issue, and I can help you debug. |
Reproduces with
gopls@master
andgopls@latest
:and
Steps to reproduce:
This compiles and runs fine, but in vscode with gopls I get a red squiggly over
package
with the error:The text was updated successfully, but these errors were encountered: