outline

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 34 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LangGo         = "Go"
	LangPython     = "Python"
	LangJavaScript = "JavaScript"
	LangTypeScript = "TypeScript"
	LangRust       = "Rust"
	LangJava       = "Java"
	LangKotlin     = "Kotlin"
	LangCSharp     = "C#"
	LangRuby       = "Ruby"
	LangC          = "C"
	LangCPP        = "C++"
	LangPHP        = "PHP"
	LangScala      = "Scala"
	LangLua        = "Lua"
	LangShell      = "Shell"
)

Language names returned by langForExt.

Variables

This section is empty.

Functions

func CommentAndStringSpans

func CommentAndStringSpans(ctx context.Context, path string, src []byte) (spans [][2]int, ok bool)

CommentAndStringSpans returns the byte ranges [start, end) of the comments and string literals in src, in order, as the language's tree-sitter grammar parses them. ok is false when the language has no grammar or ctx ended.

func IsTestFile

func IsTestFile(rel string) bool

IsTestFile reports whether rel, a slash-separated path relative to a workspace root, is a test, test data or test support code, by the naming and directory conventions of the languages in the extension table (LangForExt). It is the one classifier the tools rank by, so a consumer that ranks, filters or splits files the same way can agree with them.

Any file under a directory named test, tests, __tests__, spec, testdata, testutil, testutils or testhelpers counts. Otherwise a source file (one whose extension is in the table) counts when its name, without the extension:

  • ends in _test or starts with test_ (Go, Python, Rust, C, Ruby, ...);
  • ends in _spec (Ruby) or in .test or .spec (JavaScript, TypeScript);
  • ends in Test or Tests after at least one character (Java, Kotlin, C#, Ruby), or in IT (Java integration tests);
  • is test support: conftest.py, setupTests, jest.setup or vitest.setup.

The rule is a convention, not a parse: it reads no file.

func LangFor

func LangFor(path string, src []byte) string

LangFor returns the language of the file at path, whose content is src: the extension table's answer, except that a `.h` header containing C++ is C++. src may be nil, in which case the extension alone decides.

func LangForExt

func LangForExt(ext string) string

LangForExt returns the language name for a file extension (with the leading dot, in any case), or "" if the extension is not in the table. It is the exported form of the table's lookup, so a package that names languages can use the table instead of keeping a copy.

Types

type Backend

type Backend string

Backend names the mechanism that produced a File's declarations.

const (
	BackendGoAST      Backend = "go/ast"
	BackendTreeSitter Backend = "tree-sitter"
	BackendNone       Backend = "none"
)

type Decl

type Decl struct {
	Kind      Kind
	Name      string
	Container string
	Signature string
	Exported  bool
	StartLine int // 1-based, inclusive
	EndLine   int // 1-based, inclusive; 0 when unknown
}

Decl is one declaration in a source file.

type File

type File struct {
	Path    string  // slash-separated, relative to Options.Root or absolute
	Lang    string  // language name from the extension table
	Backend Backend // which backend produced the declarations
	Decls   []Decl  // sorted by StartLine, ties broken by Name; never nil
}

File is the outline of one source file.

func Outline

func Outline(ctx context.Context, abs string, src []byte, opts Options) (File, error)

Outline returns the outline of a single file: Go files from go/ast, the other languages in the extension table from their tree-sitter grammar (when built with cgo), anything else as none. An unreadable file is an error; a cancelled context returns ctx.Err().

func OutlineMany

func OutlineMany(ctx context.Context, srcs []Source, opts Options) ([]File, error)

OutlineMany outlines many files, returning one File per input in order. A file that cannot be read is returned as none; a cancelled context returns ctx.Err().

type Kind

type Kind string

Kind is the closed set of declaration kinds.

const (
	KindFunc      Kind = "func"
	KindMethod    Kind = "method"
	KindType      Kind = "type"
	KindClass     Kind = "class"
	KindInterface Kind = "interface"
	KindEnum      Kind = "enum"
	KindTrait     Kind = "trait"
	KindConst     Kind = "const"
	KindVar       Kind = "var"
	KindModule    Kind = "module"
	KindMacro     Kind = "macro"
)

type Options

type Options struct {
	Root         string // when non-empty, File.Path is relative to this
	MaxFileBytes int64  // 0 means 1 MiB
}

Options configures outlining.

type Source

type Source struct {
	Abs string // absolute path
	Src []byte // optional; when nil the file is read from disk
}

Source identifies a file to outline.

Jump to

Keyboard shortcuts

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