language

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 Imported by: 0 modules, 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 (
	DefaultTextWidth       = 80
	DefaultTabWidth        = 4
	DefaultMaxWrap         = 20
	DefaultMaxIndentRetain = 40
	DefaultWrapIndicator   = "\u21aa" // '↪' - rightwards arrow with hook
)
View Source
const MinSoftWrapWidth = 10

MinSoftWrapWidth is the width soft-wrap must exceed to engage, below which the wrapped rows are too narrow to read

Variables

View Source
var (
	ErrInvalidAutoPairConfig = errors.New("invalid auto-pair config")
)

Functions

This section is empty.

Types

type AutoPairConfig

type AutoPairConfig struct {
	Present bool
	Enable  *bool
	Pairs   [][2]rune
}

AutoPairConfig is a language's bracket-pairing behavior. Present marks the section as configured, separating an explicit disable from silence

func (*AutoPairConfig) AutoPairs

func (a *AutoPairConfig) AutoPairs() (core.AutoPairs, bool)

AutoPairs returns the configured pairs only

func (*AutoPairConfig) OrDefault

func (a *AutoPairConfig) OrDefault() (core.AutoPairs, bool)

OrDefault returns the configured pairs, or the built-in set when unset

func (*AutoPairConfig) UnmarshalTOML

func (a *AutoPairConfig) UnmarshalTOML(value any) error

UnmarshalTOML accepts either a bool or a table of pair characters

type DetectArgs added in v0.4.12

type DetectArgs struct {
	Path    string
	Content string
	Default string
}

DetectArgs is a file path and its content, both used to identify the language, plus the name to fall back to when nothing matches

type FileType

type FileType struct {
	Extension string
	Glob      string
}

FileType matches files to a language, by extension or by glob

type Formatter

type Formatter struct {
	Command string
	Args    []string
}

Formatter is the external command that formats a language's documents

type Indent

type Indent struct {
	TabWidth *int
	Unit     string
}

Indent is a language's indentation style, with a nil TabWidth deferring to the editor default

type Language

type Language struct {
	Name           string `toml:"name"`
	LanguageID     string `toml:"language-id"`
	InjectionRegex string `toml:"injection-regex"`

	FileTypes []FileType
	Shebangs  []string `toml:"shebangs"`
	Roots     []string `toml:"roots"`

	CommentTokens      []string
	BlockCommentTokens []core.BlockCommentToken

	Indent    Indent
	AutoPairs AutoPairConfig

	TextWidth *int     `toml:"text-width"`
	SoftWrap  SoftWrap `toml:"soft-wrap"`
	Rulers    []int    `toml:"rulers"`

	LanguageServers []string
	AutoFormat      bool `toml:"auto-format"`
	Formatter       *Formatter
}

Language describes one language: how files are recognized as it, and the comment, indent, wrap, and server behavior that follows

func ForFilename added in v0.1.21

func ForFilename(langs Languages, path string) *Language

ForFilename returns the configured language matching path

type Languages

type Languages struct {
	Languages       []Language
	LanguageServers map[string]Server
}

Languages is the loaded language configuration: every known language and the language servers they refer to by name

func LoadBundledLanguages

func LoadBundledLanguages() (Languages, bool)

LoadBundledLanguages returns the definitions embedded in the binary

func LoadLanguagesForWorkspace

func LoadLanguagesForWorkspace(args loader.WorkspaceFiles) (Languages, bool)

LoadLanguagesForWorkspace merges bundled, user, and workspace definitions

type Registry added in v0.4.12

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

Registry holds the language configuration merged for the working directory, loading it on first use and again after Invalidate. The zero value is ready

func (*Registry) Detect added in v0.4.12

func (r *Registry) Detect(args DetectArgs) string

Detect identifies a language from the file name, then its shebang, trying Chroma's lexers by name and content when no definition matches and returning Default when nothing does

func (*Registry) FileChanged added in v0.4.12

func (r *Registry) FileChanged(path string)

FileChanged drops the loaded configuration when path is a file it came from

func (*Registry) Get added in v0.4.12

func (r *Registry) Get(name string) *Language

Get returns the definition for a language name, or an empty one when no user configuration directory exists or no definition has that name

func (*Registry) Invalidate added in v0.4.12

func (r *Registry) Invalidate()

Invalidate drops the loaded configuration so the next use reloads it

type Server

type Server struct {
	Command      string
	Args         []string
	Environment  map[string]string
	Config       map[string]any
	Timeout      int
	RootPatterns []string
}

Server is how to launch and configure one language server

type SoftWrap

type SoftWrap struct {
	Enable          *bool   `toml:"enable"`
	WrapIndicator   *string `toml:"wrap-indicator"`
	WrapAtTextWidth *bool   `toml:"wrap-at-text-width"`
}

SoftWrap is a language's wrapping behavior, each nil field deferring to the editor setting

type TextFormat

type TextFormat struct {
	ViewportWidth       int
	TabWidth            int
	SoftWrap            bool
	MaxWrap             int
	MaxIndentRetain     int
	WrapIndicator       string
	SoftWrapAtTextWidth bool
}

TextFormat is the resolved layout of a document's text: the width to wrap at, how tabs measure, and how wrapped rows are indicated

func DefaultTextFormat

func DefaultTextFormat(w int) *TextFormat

DefaultTextFormat builds the render format used when no language matches

func TextFormatForConfig

func TextFormatForConfig(lang *Language, textWidth *int, softWrap SoftWrap, w int) *TextFormat

TextFormatForConfig builds the render format for a language and width

func (*TextFormat) WrapIndicatorPrefix added in v0.1.19

func (t *TextFormat) WrapIndicatorPrefix() string

WrapIndicatorPrefix is the indicator plus its gap, as drawn at the start of a soft-wrapped continuation row

Jump to

Keyboard shortcuts

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