srcref

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package srcref formats AST positions as repo-relative "file:line" references suitable for embedding in generated reference docs.

Generators usually want to point a reader at the exact source line that defines a flag, route, or config field. srcref handles the fiddly bits: resolving go/token.Pos against a FileSet, trimming an absolute path to a repo-relative one, and degrading gracefully when the position is invalid.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SrcRef

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

SrcRef formats positions against a shared FileSet.

func New

func New(fset *token.FileSet) *SrcRef

New returns a SrcRef bound to fset. The FileSet must outlive the SrcRef; it typically lives for the duration of a single docsgen run.

func (*SrcRef) Format

func (s *SrcRef) Format(pos token.Pos, root string) string

Format renders pos as "path/to/file.go:LINE". If root is non-empty and the resolved filename lives underneath root, the result is relative to root; otherwise the absolute filename is used.

Returns "" if the position is invalid or the FileSet is nil.

Jump to

Keyboard shortcuts

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