-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: add a command to start the debug server #45518
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
I assume this means the debugging collector would always be running and collecting the information, it would just not be bound to a serving port until the command was issued? |
It looks like it is always running and collecting information: Either way, I don't see a reason we couldn't start collection when the debug server is started. |
Some of the information it collects required ends to have corresponding starts, it would not surprise me at all if it crashes if you just start it on demand, if we really want to we can make it all work I am sure. |
For additional context, this issue came out of a discussion we had about making it easier to help new users troubleshoot. Not having logging enabled or not being able to find logs was a pain point. (actually, this is not just for new users: I often have to use some combination of The tentative plan is to spend some effort making the debug server a one-stop shop for debugging resources. |
Change https://golang.org/cl/309409 mentions this issue: |
Change https://golang.org/cl/309810 mentions this issue: |
The utility of the debug server is limited by the requirement to start gopls with the `-debug` flag and then look in the logs to see which port the debug server is bound to. This CL adds a new custom command `gopls.startDebugging` to start the debug server on demand if it isn't already running, and return its debug address. It also does some gymnastics to make this turn on debugging for any intermediate gopls forwarders, when using daemon mode. For golang/go#45518 Change-Id: I48a90088f96aca54f34f93bedbfe864515320f61 Reviewed-on: https://go-review.googlesource.com/c/tools/+/309409 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The gopls debug server can be very useful for debugging, but...
-debug=addr
must be passed at the command line when gopls is started.localhost:0
, and the actual port the server is listening on is buried in the logs.The reason for (1) is that the debug server exposes the internals of the gopls server, including file contents, and so for privacy on shared machines we shouldn't always bind. The reason for (2) is simply that we have no better way to surface the information: we could use a ShowMessage request, but depending on LSP client those are easy to miss, transient, or annoying.
We propose to solve this by providing a new command (
gopls.startDebugging
) that starts the debug server if it wasn't already running, and returns its URL. We can integrate this in VS Code via a menu item, and either VS Code can open the returned address, or we can use the new window/showDocument request to ask clients to open it. T.B.D.: my suspicion is that not many clients support window/showDocument.The hope is that this makes the debug server more commonly available for diagnostic purposes, and therefore makes it worthwhile to add more functionality to it. For example we could always have recent RPC logs in-memory, start profiling on-demand, inspect more internal state - the possibilities are endless.
Special consideration for the gopls daemon: we should ideally start debugging for each server in the serving path, both forwarder(s) and daemon. Each server can intercept the
gopls.startDebugging
command and add its own information.CC @heschi @stamblerre @ianthehat
The text was updated successfully, but these errors were encountered: