doc

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2025 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package doc implements support for documentation of Gno packages and realms, in a similar fashion to `go doc`. As a reference, the official implementation for `go doc` is used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToText

func ToText(w io.Writer, text, prefix, codePrefix string)

Types

type Documentable

type Documentable struct {
	// contains filtered or unexported fields
}

Documentable is a package, symbol, or accessible which can be documented.

func NewDocumentableFromMemPkg

func NewDocumentableFromMemPkg(mpkg *std.MemPackage, unexported bool, symbol, accessible string) (*Documentable, error)

NewDocumentableFromMemPkg gets the pkgData from mpkg and returns a Documentable

func ResolveDocumentable

func ResolveDocumentable(dirs, modDirs, args []string, unexported bool) (*Documentable, error)

ResolveDocumentable returns a Documentable from the given arguments. Refer to the documentation of gno doc for the formats accepted (in general the same as the go doc command). An error may be returned even if documentation was resolved in case some packages in dirs could not be parsed correctly.

dirs specifies the gno system directories to scan which specify full import paths in their directories, such as @/examples and @/gnovm/stdlibs; modDirs specifies directories which contain a gno.mod file.

func (*Documentable) WriteDocumentation

func (d *Documentable) WriteDocumentation(w io.Writer, o *WriteDocumentationOptions) error

func (*Documentable) WriteJSONDocumentation

func (d *Documentable) WriteJSONDocumentation(opt *WriteDocumentationOptions) (*JSONDocumentation, error)

WriteJSONDocumentation returns a JSONDocumentation for the package A useful opt is Source=true. opt may be nil

type JSONDocumentation

type JSONDocumentation struct {
	PackagePath string   `json:"package_path"`
	PackageLine string   `json:"package_line"` // package io // import "io"
	PackageDoc  string   `json:"package_doc"`  // markdown of top-level package documentation
	Bugs        []string `json:"bugs"`         // From comments with "BUG(who): Details"

	// These match each of the sections in a pkg.go.dev package documentation
	Values []*JSONValueDecl `json:"values"` // constants and variables declared
	Funcs  []*JSONFunc      `json:"funcs"`  // Funcs and methods
	Types  []*JSONType      `json:"types"`
}

JSONDocumentation holds package documentation suitable for transmitting as JSON with printable string fields

func (*JSONDocumentation) JSON

func (jsonDoc *JSONDocumentation) JSON() string

type JSONField

type JSONField struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Doc  string `json:"doc"` // markdown
}

type JSONFunc

type JSONFunc struct {
	Type      string       `json:"type"` // if this is a method
	Name      string       `json:"name"`
	Crossing  bool         `json:"crossing"` // true if the first param is "cur realm"
	Signature string       `json:"signature"`
	Doc       string       `json:"doc"` // markdown
	Params    []*JSONField `json:"params"`
	Results   []*JSONField `json:"results"`
}

type JSONInterfaceElement

type JSONInterfaceElement struct {
	Method *JSONFunc `json:"method,omitempty"` // Normal interface method
	Type   string    `json:"type,omitempty"`   // Embedded type
}

type JSONType

type JSONType struct {
	Name  string `json:"name"`  // "MyType"
	Type  string `json:"type"`  // "struct { ... }"
	Doc   string `json:"doc"`   // godoc documentation...
	Alias bool   `json:"alias"` // if an alias like `type A = B`
	Kind  string `json:"kind"`  // struct | interface | array | slice | map | channel | func | pointer | ident
	// TODO: Use omitzero when upgraded to Go 1.24
	InterElems []*JSONInterfaceElement `json:"inter_elems,omitempty"` // interface methods or embedded types (Kind == "interface") (struct methods are in JSONDocumentation.Funcs)
	Fields     []*JSONField            `json:"fields,omitempty"`      // struct fields (Kind == "struct")
}

type JSONValue

type JSONValue struct {
	Name string `json:"name"`
	Doc  string `json:"doc"`
	Type string `json:"type"` // often empty
}

type JSONValueDecl

type JSONValueDecl struct {
	Signature string       `json:"signature"`
	Const     bool         `json:"const"`
	Values    []*JSONValue `json:"values"`
	Doc       string       `json:"doc"` // markdown
}

type WriteDocumentationOptions

type WriteDocumentationOptions struct {
	// ShowAll shows all symbols when displaying documentation about a package.
	ShowAll bool
	// Source shows the source code when documenting a symbol.
	Source bool
	// Unexported shows unexported symbols as well as exported.
	Unexported bool
	// Short shows a one-line representation for each symbol.
	Short bool
	// contains filtered or unexported fields
}

WriteDocumentationOptions represents the possible options when requesting documentation through Documentable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL