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: change links in hover for replaced modules #39532

Open
DmitriyVTitov opened this issue Jun 11, 2020 · 20 comments
Open

x/tools/gopls: change links in hover for replaced modules #39532

DmitriyVTitov opened this issue Jun 11, 2020 · 20 comments
Labels
gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@DmitriyVTitov
Copy link

  • Run go version to get version of Go
    • go version go1.14.4 windows/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.45.1 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.14.4
  • Run go env to get the go development environment details
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dtsp\AppData\Local\go-build
set GOENV=C:\Users\dtsp\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dtsp\YandexDisk\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\GO
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\GO\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map

Share the Go related settings you have added/edited

    "go.testFlags": [
        "*.go": "go"
    "[go]": {},
    "go.formatTool": "goimports",
    "go.useLanguageServer": true,

Describe the bug

When I enable Go Language Server all my local Go modules become unavailable.
image

All these modules are local to project folder and are available using replace:

replace (
	transflow.ru/pkg/api v0.0.0 => ../api
	transflow.ru/pkg/assign v0.0.0 => ../assign
	transflow.ru/pkg/cache v0.0.0 => ../cache
	transflow.ru/pkg/consts v0.0.0 => ../consts
)

But even struct Server which is defined at the very same package is unavailable as you may see at screenshot.

@hyangah
Copy link
Contributor

hyangah commented Jun 11, 2020

@DmitriyVTitov Did you open the editor from the directory where the go.mod file with the replace statement exists? Can you please capture the language server log and share it with us for investigation? (cc @stamblerre)

Here is the instruction for log capturing. https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#vs-code

Thanks for the issue report.

@DmitriyVTitov
Copy link
Author

Did you open the editor from the directory where the go.mod file with the replace statement exists?

I'm not sure that I understood your question correctly. I have several folders in my VSCode workspace (Go, Flutter, JS). One of them (transflow.ru) uses local modules, which are located at: transflow.ru\pkg\*.
In the screenshot above I pictured transflow.ru\pkg\server module with part of it's go mod file.
When I start VSCode with language server enabled the folowing log appears in the output (I removed lines, related to my other non-Go folders).

Here is the log:

[Info  - 18:17:43] 2020/06/11 18:17:43 Build info
----------
golang.org/x/tools/gopls 0.4.1
    golang.org/x/tools/gopls@v0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
    golang.org/x/tools@v0.0.0-20200513154647-78b527d18275 h1:e7nYe9s94RHunFJ7b+mmPxiQMOKMVSqYASToWb1EcHs=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14.4 windows/amd64



[Info  - 18:17:44] 2020/06/11 18:17:44 go env for C:\Users\dtsp\YandexDisk\go\src\transflow.ru
(valid build configuration = true)
(build flags: [-modfile=C:\Users\dtsp\AppData\Local\Temp\go.transflow.ru.363357867.mod])
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dtsp\AppData\Local\go-build
set GOENV=C:\Users\dtsp\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dtsp\YandexDisk\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\GO
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\GO\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\dtsp\AppData\Local\Temp\go-build350374462=/tmp/go-build -gno-record-gcc-switches

[Info  - 18:17:54] 2020/06/11 18:17:54 go/packages.Load
	snapshot=0
	directory=C:\Users\dtsp\YandexDisk\go\src\transflow.ru
	query=[./... builtin]
	packages=29

[Info  - 18:17:56] 2020/06/11 18:17:56 go/packages.Load
	snapshot=2
	directory=C:\Users\dtsp\YandexDisk\go\src\transflow.ru
	query=[file=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\services.go]
	packages=1

[Info  - 18:17:56] 2020/06/11 18:17:56 go/packages.Load
	snapshot=2
	package_path="command-line-arguments"
	files=[C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\services.go]

[Error - 18:17:56] 2020/06/11 18:17:56 no dep handle: no metadata for transflow.ru/pkg/consts
	package="transflow.ru/pkg/consts"

[Error - 18:17:56] 2020/06/11 18:17:56 no dep handle: no metadata for transflow.ru/pkg/yandex
	package="transflow.ru/pkg/yandex"

[Error - 18:17:56] 2020/06/11 18:17:56 no dep handle: no metadata for transflow.ru/pkg/models
	package="transflow.ru/pkg/models"

	snapshot=2
	directory=C:\Users\dtsp\YandexDisk\go\src\transflow.ru
	query=[file=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\server.go]
	packages=1

[Info  - 18:18:00] 2020/06/11 18:18:00 go/packages.Load
	snapshot=2
	package_path="command-line-arguments"
	files=[C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\server.go]

go.mod for go\src\transflow.ru\pkg\server\server.go:

module transflow.ru/pkg/server

go 1.13

replace (
	transflow.ru/pkg/api v0.0.0 => ../api
	transflow.ru/pkg/assign v0.0.0 => ../assign
	transflow.ru/pkg/cache v0.0.0 => ../cache
	transflow.ru/pkg/consts v0.0.0 => ../consts
	transflow.ru/pkg/geom v0.0.0 => ../geom
	transflow.ru/pkg/geozone v0.0.0 => ../geozone
	transflow.ru/pkg/helpdesk v0.0.0 => ../helpdesk
	transflow.ru/pkg/helpdesk/imap v0.0.0 => ../helpdesk/imap
	transflow.ru/pkg/insight v0.0.0 => ../insight
	transflow.ru/pkg/logger v0.0.0 => ../logger
	transflow.ru/pkg/logger/dblog v0.0.0 => ../logger/dblog
	transflow.ru/pkg/logger/memlog v0.0.0 => ../logger/memlog
	transflow.ru/pkg/mailer v0.0.0 => ../mailer
	transflow.ru/pkg/misc v0.0.0 => ../misc
	transflow.ru/pkg/models v0.0.0 => ../models
	transflow.ru/pkg/notifications v0.0.0 => ../notifications
	transflow.ru/pkg/pacmon v0.0.0 => ../pacmon
	transflow.ru/pkg/proto v0.0.0 => ../proto
	transflow.ru/pkg/realtime v0.0.0 => ../realtime
	transflow.ru/pkg/reports v0.0.0 => ../reports
	transflow.ru/pkg/reports/excel v0.0.0 => ../reports/excel
	transflow.ru/pkg/stats v0.0.0 => ../stats
	transflow.ru/pkg/storage v0.0.0 => ../storage
	transflow.ru/pkg/storage/inmemory v0.0.0 => ../storage/inmemory
	transflow.ru/pkg/storage/pgsql v0.0.0 => ../storage/pgsql
	transflow.ru/pkg/trips v0.0.0 => ../trips
	transflow.ru/pkg/violations v0.0.0 => ../violations
	transflow.ru/pkg/yandex v0.0.0 => ../yandex
)

require (
	github.com/gorilla/mux v1.7.3
	github.com/gorilla/websocket v1.4.1
	github.com/smartystreets/goconvey v1.6.4 // indirect
	transflow.ru/pkg/api v0.0.0
	transflow.ru/pkg/assign v0.0.0
	transflow.ru/pkg/cache v0.0.0
	transflow.ru/pkg/consts v0.0.0
	transflow.ru/pkg/helpdesk v0.0.0
	transflow.ru/pkg/insight v0.0.0
	transflow.ru/pkg/logger v0.0.0
	transflow.ru/pkg/logger/dblog v0.0.0
	transflow.ru/pkg/mailer v0.0.0
	transflow.ru/pkg/models v0.0.0
	transflow.ru/pkg/notifications v0.0.0
	transflow.ru/pkg/pacmon v0.0.0
	transflow.ru/pkg/proto v0.0.0
	transflow.ru/pkg/realtime v0.0.0
	transflow.ru/pkg/stats v0.0.0
	transflow.ru/pkg/storage v0.0.0
	transflow.ru/pkg/storage/inmemory v0.0.0
	transflow.ru/pkg/storage/pgsql v0.0.0
	transflow.ru/pkg/trips v0.0.0
	transflow.ru/pkg/violations v0.0.0
	transflow.ru/pkg/yandex v0.0.0
)

@hyangah
Copy link
Contributor

hyangah commented Jun 11, 2020

@DmitriyVTitov Thanks for sharing more details. I think you were caught by #32394.

The VS Code workspace is C:\Users\dtsp\YandexDisk\go\src and the go.mod file used is GOMOD=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\go.mod, not the one in the transflow.ru\pkg\server folder.

Currently suggested workarounds is to open only the transflow.ru\pkg\server folder, or to manually add C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\ to the workspace (Workspaces: Add Folder to Workspace ....

@DmitriyVTitov
Copy link
Author

DmitriyVTitov commented Jun 11, 2020

Well I've deleted go.mod from the root of my project tree and VSCode no more highlights local packages as invalid. But Ctrl-Click (Go to code) is not working with local packages. But it works with standard library.
Also I'ts strange that VSCode offers me to open link to, for example,

https://pkg.go.dev/transflow.ru/pkg/yandex

despite it's local package specified with replace directive in go.mod.

I've already opened issue microsoft/vscode-go#3072 about Go to definition with Go 1.14. Maybe it's related.
@stamblerre helped me a lot with that issuue but it didn't worked well for me anyways.

@stamblerre
Copy link
Contributor

stamblerre commented Jun 11, 2020

@DmitriyVTitov: Can you please run gopls -rpc.trace -v check path/to/file.go from your module root and share that output here? It definitely sounds related to the replace directive.

As for the pkg.go.dev links, those don't check for replace directives either, so that's a separate bug.

Transferred this issue to the Go issue tracker, as this is definitely a gopls issue.

@stamblerre stamblerre transferred this issue from golang/vscode-go Jun 11, 2020
@stamblerre stamblerre changed the title Enabling language server breaks local modules x/tools/gopls: unexpected errors with replace directives Jun 11, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jun 11, 2020
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jun 11, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jun 11, 2020
@DmitriyVTitov
Copy link
Author

@DmitriyVTitov: Can you please run gopls -rpc.trace -v check path/to/file.go from your module root and share that output here? It definitely sounds related to the replace directive.

As for the pkg.go.dev links, those don't check for replace directives either, so that's a separate bug.

gopls.exe -rpc.trace -v .\server.go

got error:

flag provided but not defined: -rpc
The Go Language source tools.

Usage: gopls [flags] <command> [command-flags] [command-args]

@stamblerre
Copy link
Contributor

Make sure you provide the check subcommand, so gopls.exe -rpc.trace -v check .\server.go.

@DmitriyVTitov
Copy link
Author

Make sure you provide the check subcommand, so gopls.exe -rpc.trace -v check .\server.go.

PS C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server> C:\Users\dtsp\YandexDisk\go\bin\gopls.exe -rpc.trace -v check .\server.go
flag provided but not defined: -rpc
The Go Language source tools.

Usage: gopls [flags] <command> [command-flags] [command-args]

@stamblerre
Copy link
Contributor

This might be a PowerShell issue (https://stackoverflow.com/questions/26614969/how-can-i-pass-batch-arguments-with-dots-into-a-powershell-script). Looks like you may need to do something like gopls.exe --% -rpc.trace -v check path/to/file.go.

@DmitriyVTitov
Copy link
Author

You were right:

PS C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server> C:\Users\dtsp\YandexDisk\go\bin\gopls.exe --% -rpc.trace -v check .\server.go
2020/06/11 21:22:46 Info:2020/06/11 21:22:46 Build info
----------
golang.org/x/tools/gopls 0.4.1
    golang.org/x/tools/gopls@v0.4.1 h1:0e3BPxGV4B3cd0zdMuccwW72SgmHp92lAjOyxX/ScAw=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
    golang.org/x/tools@v0.0.0-20200513154647-78b527d18275 h1:e7nYe9s94RHunFJ7b+mmPxiQMOKMVSqYASToWb1EcHs=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14.4 windows/amd64


2020/06/11 21:22:47 Info:2020/06/11 21:22:47 go env for C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server
(valid build configuration = true)
(build flags: [-modfile=C:\Users\dtsp\AppData\Local\Temp\go.server.010609871.mod])
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dtsp\AppData\Local\go-build
set GOENV=C:\Users\dtsp\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dtsp\YandexDisk\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\GO
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\GO\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\dtsp\AppData\Local\Temp\go-build743783070=/tmp/go-build -gno-record-gcc-switches

2020/06/11 21:22:48 Info:2020/06/11 21:22:48 go/packages.Load
        snapshot=0
        directory=C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server
        query=[./... builtin]
        packages=4

@stamblerre
Copy link
Contributor

Glad that worked! Looks like the gopls check command does not report any errors, unlike VS Code. Just to confirm, this is the file in which you see errors in VS Code?

@DmitriyVTitov
Copy link
Author

Glad that worked! Looks like the gopls check command does not report any errors, unlike VS Code. Just to confirm, this is the file in which you see errors in VS Code?

I don't see ERRORS no more, but 'Go to definition' do not work. When I deleted root go.mod all red underscores disappeared.
Still language server is not usable without Ctrl+Click.
I mean in screenshot above I cannot Ctrl+Click even Reciever type in the function definition despite this type (Server) is in the same package (module) as server.go.

@stamblerre
Copy link
Contributor

stamblerre commented Jun 11, 2020

Deleting the go.mod is not a good solution, as that will put you back into GOPATH mode. If you can follow these steps to capture verbose logs, I can help you continue troubleshooting: https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs.

@DmitriyVTitov
Copy link
Author

Deleting the go.mod is not a good solution, as that will put you back into GOPATH mode. If you can follow these steps to capture verbose logs, I can help you continue troubleshooting: https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capturing-logs.

Sorry Rebecca, but I don't have time to switch extension on and off for now. I will continue to work without language server.
Thanks for your help!

@stamblerre
Copy link
Contributor

Not a problem. I'll leave this issue open as a reminder to add regression tests that use replace directives.

@hyangah
Copy link
Contributor

hyangah commented Jun 12, 2020

@stamblerre the gopls check output has

go env for C:\Users\dtsp\YandexDisk\go\src\transflow.ru\pkg\server
(valid build configuration = true)

while the gopls server output has

go env for C:\Users\dtsp\YandexDisk\go\src\transflow.ru
(valid build configuration = true)

Doesn't it mean the workspace roots used in two cases are different?

@stamblerre
Copy link
Contributor

Yes, it does seem like that's the case.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 17, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v1.0.0 Jul 22, 2020
@stamblerre stamblerre changed the title x/tools/gopls: unexpected errors with replace directives x/tools/gopls: don't show links on hover for replaced modules Jul 30, 2020
@stamblerre
Copy link
Contributor

stamblerre commented Jul 30, 2020

There hasn't been much activity on this issue, and we have a few CLs planned to improve the workflow with replaced modules. The one thing left to address is the hover links showing up for the original module.

Also I'ts strange that VSCode offers me to open link to, for example,
https://pkg.go.dev/transflow.ru/pkg/yandex
despite it's local package specified with replace directive in go.mod

@stamblerre stamblerre added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 13, 2020
@stamblerre stamblerre added this to Needs Triage in vscode-go: gopls by default Nov 10, 2020
@stamblerre stamblerre moved this from Needs Triage to Non-critical in vscode-go: gopls by default Nov 10, 2020
@stamblerre stamblerre removed this from Non-critical in vscode-go: gopls by default Dec 16, 2020
@stamblerre
Copy link
Contributor

After some discussion, we've concluded that the hover links may still be useful, even if the module has been replaced. We can change the links to point to the replaced module, if possible, however.

@stamblerre stamblerre changed the title x/tools/gopls: don't show links on hover for replaced modules x/tools/gopls: change links in hover for replaced modules Dec 23, 2020
@stamblerre stamblerre added this to To Do in gopls on-deck Feb 28, 2021
@stamblerre stamblerre moved this from To Do to P3 in gopls on-deck Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

4 participants