Skip to content

x/tools/gopls: add a command to start the debug server #45518

@findleyr

Description

@findleyr

The gopls debug server can be very useful for debugging, but...

  1. It's often not available when the user needs it, because -debug=addr must be passed at the command line when gopls is started.
  2. 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.

CC @heschi @stamblerre @ianthehat

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions