-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
The gopls debug server can be very useful for debugging, but...
- It's often not available when the user needs it, because
-debug=addr
must be passed at the command line when gopls is started. - It's hard to find, because best practice is to bind to
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.