Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

On 'peek definition' and 'go to definition' godef-gomod doesn't work in sub modules #2180

Closed
kidlj opened this issue Dec 7, 2018 · 12 comments
Labels
go-modules Related to Go modules

Comments

@kidlj
Copy link

kidlj commented Dec 7, 2018

When go docsTool setting to godoc(the default), it recommends installing godef-gomod, but it doesn't work at all on 'go to definition' or 'peek definition'.

Version: 1.29.1 (user setup)
Commit: bc24f98b5f70467bc689abf41cc5550ca637088e
Date: 2018-11-15T19:13:36.375Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Go extension version 0.7.0

@ramya-rao-a
Copy link
Contributor

Can you try the latest beta version of this extension? It has some fixes that can help.

@kidlj
Copy link
Author

kidlj commented Dec 9, 2018

I installed 0.7.1-beta.5, then every 'go to definition' trigger takes 10 seconds and shows 'No definition found for xxx'. Setting go docsTool to gogetdoc works though.

@ramya-rao-a
Copy link
Contributor

Can you help us figure out why it didn't work in the first place? The stable build doesn't show logs, but if you can download the VS Code Insiders and try the below, I would very much appreciate it.

  • Open the output channel: View -> Output
  • Select Log (Extension Host) from the drop down on the top right corner of the output panel
  • Clear any logs that already exist by either clicking on the button for clearing logs or by running the command View: Clear Output
  • In the code for which Go to definition didn't work, try to run Go to definition again

At this point, the output channel would show the command that was run to get the definition information and any error from it. Please share that

@kidlj
Copy link
Author

kidlj commented Dec 9, 2018

@ramya-rao-a Thanks for your kind support.

The Log(Extension Host) logs:

[2018-12-09 20:10:26.361] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:10:26.361] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\log\log.go -o 175
godef: There must be at least one package that contains the file

[2018-12-09 20:11:00.065] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:11:00.065] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\log\log.go -o 173
godef: There must be at least one package that contains the file

If I run this command manually, it hangs.

However, If without the -i (read file from stdin) option, the command works:

mellon@collie MINGW64 /d/Code/demo (master)
$ godef-gomod.exe -t -f log/log.go -o 175
C:\Users\mellon\go\pkg\mod\github.com\kidlj\log@v0.0.3\pkg.go:25:6
WithFields func(fields Fielder) *Entry

mellon@collie MINGW64 /d/Code/demo (master)
$ godef-gomod.exe -t -f log/log.go -o 173
C:\Users\mellon\go\pkg\mod\github.com\kidlj\log@v0.0.3\pkg.go:25:6
WithFields func(fields Fielder) *Entry

The testing code is here: https://github.com/kidlj/demo

@kidlj
Copy link
Author

kidlj commented Dec 9, 2018

Hower, I installed 0.7.1-beta.5 again, now it works both in vscode stable and insider versions.

0.7.0 still outputs errors:

[2018-12-09 20:27:27.412] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:27:27.412] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\log\log.go -o 185
godef: There must be at least one package that contains the file

[2018-12-09 20:27:33.701] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:27:33.701] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\log\log.go -o 185
godef: There must be at least one package that contains the file

You may close this issue, thanks.

@kidlj
Copy link
Author

kidlj commented Dec 9, 2018

Sorry, I don't know why, after experiencing the working extension for a while I quit the editors, and then reopened another project, it failed to work again.

[2018-12-09 20:39:15.658] [exthost] [info] eager extensions activated
[2018-12-09 20:39:42.141] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:39:42.141] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

[2018-12-09 20:39:45.409] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:39:45.409] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

[2018-12-09 20:39:51.949] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:39:51.949] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

[2018-12-09 20:40:07.231] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:40:07.231] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

Here is the full logs:

[2018-12-09 20:44:39.738] [exthost] [info] extension host started
[2018-12-09 20:44:39.775] [exthost] [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch {"startup":true,"activationEvent":"*"}
[2018-12-09 20:44:39.775] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\debug-auto-launch\dist\extension
[2018-12-09 20:44:39.781] [exthost] [info] ExtensionService#_doActivateExtension vscode.emmet {"startup":true,"activationEvent":"*"}
[2018-12-09 20:44:39.781] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\emmet\dist\extension
[2018-12-09 20:44:39.797] [exthost] [info] ExtensionService#_doActivateExtension vscode.git {"startup":true,"activationEvent":"*"}
[2018-12-09 20:44:39.797] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\git\dist\main
[2018-12-09 20:44:39.852] [exthost] [info] ExtensionService#_doActivateExtension vscode.merge-conflict {"startup":true,"activationEvent":"*"}
[2018-12-09 20:44:39.852] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\merge-conflict\dist\extension
[2018-12-09 20:44:39.857] [exthost] [info] ExtensionService#_doActivateExtension vscodevim.vim {"startup":true,"activationEvent":"*"}
[2018-12-09 20:44:39.857] [exthost] [info] ExtensionService#loadCommonJSModule C:\Users\mellon\.vscode-insiders\extensions\vscodevim.vim-0.16.13\out\extension
[2018-12-09 20:44:40.652] [exthost] [info] eager extensions activated
[2018-12-09 20:45:07.557] [exthost] [info] extension host started
[2018-12-09 20:45:07.590] [exthost] [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch {"startup":true,"activationEvent":"*"}
[2018-12-09 20:45:07.590] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\debug-auto-launch\dist\extension
[2018-12-09 20:45:07.602] [exthost] [info] ExtensionService#_doActivateExtension vscode.emmet {"startup":true,"activationEvent":"*"}
[2018-12-09 20:45:07.602] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\emmet\dist\extension
[2018-12-09 20:45:07.613] [exthost] [info] ExtensionService#_doActivateExtension vscode.git {"startup":true,"activationEvent":"*"}
[2018-12-09 20:45:07.613] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\git\dist\main
[2018-12-09 20:45:07.659] [exthost] [info] ExtensionService#_doActivateExtension vscode.merge-conflict {"startup":true,"activationEvent":"*"}
[2018-12-09 20:45:07.659] [exthost] [info] ExtensionService#loadCommonJSModule c:\Users\mellon\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\merge-conflict\dist\extension
[2018-12-09 20:45:07.669] [exthost] [info] ExtensionService#_doActivateExtension vscodevim.vim {"startup":true,"activationEvent":"*"}
[2018-12-09 20:45:07.669] [exthost] [info] ExtensionService#loadCommonJSModule C:\Users\mellon\.vscode-insiders\extensions\vscodevim.vim-0.16.13\out\extension
[2018-12-09 20:45:08.442] [exthost] [info] ExtensionService#_doActivateExtension ms-vscode.Go {"startup":false,"activationEvent":"onLanguage:go"}
[2018-12-09 20:45:08.442] [exthost] [info] ExtensionService#loadCommonJSModule C:\Users\mellon\.vscode-insiders\extensions\ms-vscode.go-0.7.1-beta.5\out\src\goMain
[2018-12-09 20:45:08.728] [exthost] [info] eager extensions activated
[2018-12-09 20:45:21.580] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:45:21.580] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

[2018-12-09 20:45:38.454] [exthost] [error] [ms-vscode.Go] provider FAILED
[2018-12-09 20:45:38.454] [exthost] [error] Command failed: C:\Users\mellon\go\bin\godef-gomod.exe -t -i -f d:\Code\demo\gin\main.go -o 112
godef: There must be at least one package that contains the file

@kidlj
Copy link
Author

kidlj commented Dec 9, 2018

I think I found the reason.

Here's my testing project directory structure:

D:\CODE\DEMO
│  .gitignore
│  go.mod
│  go.sum
│
├─evaluator
│      main.go
│
├─gin
│      gin.exe
│      go.mod
│      go.sum
│      main.go
│
├─goroutine_closure
│      main.go
│
├─log
│      log.go
│
├─mod
│      go.mod
│      go.sum
│      main.go
│
└─pg
    ├─has_many
    │      main.go
    │
    ├─has_many_self
    │      main.go
    │
    ├─has_one
    │      main.go
    │
    ├─many_to_many
    │      main.go
    │
    └─many_to_many_self
            main.go

You can see that in the uppermost demo directory there is a go.mod, and in gin and mod sub directory, there is another go.mod. With 0.7.1-beta.5, when triggering 'go to definition' in files which use the upper most go.mod file, it works; but if the file resides in a directory which contains its own go.mod, it fails.

0.7.0 fails in both scenarios though.

The testing project is here: https://github.com/kidlj/demo

@ramya-rao-a ramya-rao-a changed the title On 'peek definition' and 'go to definition' godef-gomod doesn't work at all On 'peek definition' and 'go to definition' godef-gomod doesn't in sub modules Dec 9, 2018
@ramya-rao-a
Copy link
Contributor

Thanks @kidlj!

0.7.0 failing is expected as it wasn't running godef-gomod from the right directory.
0.7.1-beta.5 runs it from the folder opened in VS Code (which in your case I believe is the uppermost demo directory). So this looks like an issue of godef not working on sub modules when run from the directory of the main module.

@ianthehat Can we expect godef to work on a file which is in a sub module when it is run from the directory of the main module?

@ramya-rao-a ramya-rao-a added bug go-modules Related to Go modules and removed needs more info labels Dec 9, 2018
@ianthehat
Copy link
Contributor

Nope.
This is a general problem with sub-modules, they are essentially unrelated (in either direction) with the parent module, they might as well be in a separate repository.
Essentially the file is not one that is reachable from the outer module. Even if the outer module depends on the sub-module, it will depend on a copy in the module cache, not the one you see in a sub-directory (unless you have a replace directory).
It is really hard for a tool to guess the users intent here. This is something we are going to have to work on and talk about, maybe in the tools meeting tomorrow. In general there are lots of questions about sub-modules, I would think of them as even more experimental than normal modules and avoid them without a really strong reason to need them right now.

@ramya-rao-a ramya-rao-a changed the title On 'peek definition' and 'go to definition' godef-gomod doesn't in sub modules On 'peek definition' and 'go to definition' godef-gomod doesn't work in sub modules Dec 10, 2018
@meteorice
Copy link

@ramya-rao-a
I found (ctrl+right mouse-click) doesn't work, when i execute 'go mod init test' command.
When i delete the go.mod, (ctrl+right mouse-click) come back

├─── go.mod
├── intf
│     └── intf.go
└── main.go

@ramya-rao-a
Copy link
Contributor

This should be fixed in the latest beta version of this extension

@ramya-rao-a
Copy link
Contributor

The fix for this is now out in the latest update (0.9.0) to the Go extension

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
go-modules Related to Go modules
Projects
None yet
Development

No branches or pull requests

4 participants