Skip to content

x/tools/gopls: support for comment rendering #64936

@firelizzard18

Description

@firelizzard18

I propose adding a gopls command that uses doc/comment to render documentation comments of package-level declarations. The intent is that this command would be used by a development environment to render pkgsite-style documentation for workspace packages. This could serve the following purposes:

  1. Viewing documentation for code changes that have not been published yet.
  2. Viewing documentation for private repositories.
  3. Reviewing documentation as I write it, to ensure it is formatted the way I want.
  4. Viewing documentation from within my development environment, without needing to switch to a browser.

I'll grant the first three items can be achieved by running pkgsite locally, but that does not address (4), it is less than convenient, and in my experience does not work well for (3).

I propose:

  1. gopls/internal/lsp/cache/docs, which will locate documentation comments, parse them with doc/comment.Parser, and convert the doc/comment.Doc into marshallable types such that the result can be cached.
  2. gopls/internal/lsp/command.Interface.RenderDocs, which will retrieve doc/comment.Docs from a snapshot and render them:
type RenderDocsParams struct {
	Package        protocol.URI
	Declaration    protocol.Location // location of the declaration to generate docs for, optional, omit to render for the entire package
	Format         string            // comment, html, markdown, or text
	HeadingLevel   int               // doc/comment.Printer.HeadingLevel
	HeadingIdTmpl  string            // template for rendering header IDs with doc/comment.Printer.HeadingID
	DocLinkTmpl    string            // template for rendering document links with doc/comment.Printer.DocLinkURL
	DocLinkBaseURL string            // doc/comment.Printer.DocLinkBaseURL
	TextPrefix     string            // doc/comment.Printer.TextPrefix
	TextCodePrefix string            // doc/comment.Printer.TextCodePrefix
	TextWidth      int               // doc/comment.Printer.TextWidth
}

type RenderDocsResult struct {
	Result string
}

CC @hyangah @adonovan

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions