formatter

package
v0.3.25 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package formatter implements a deterministic, comment-preserving TypeRB printer. Parsing happens first; the printer then uses the lossless token stream so comments, strings, percent literals, and heredocs are never lost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(source []byte) ([]byte, []diagnostic.Diagnostic)

func FormatWithOptions added in v0.3.9

func FormatWithOptions(source []byte, options Options) ([]byte, []diagnostic.Diagnostic)

func NextLineIndent added in v0.3.17

func NextLineIndent(source []byte) string

NextLineIndent returns the indentation for a new line following a tokenizable, possibly incomplete source fragment.

func NextLineIndentWithIndentation added in v0.3.18

func NextLineIndentWithIndentation(source []byte, indentation string) string

NextLineIndentWithIndentation returns the next-line indentation using the given display unit.

func ReindentPartial added in v0.3.17

func ReindentPartial(source []byte) []byte

ReindentPartial applies canonical leading indentation to a tokenizable source fragment without requiring the fragment to parse as a complete program. It preserves all non-leading text and the contents of multiline tokens so an interactive editor can safely call it while a submission is still open.

func ReindentPartialWithIndentation added in v0.3.18

func ReindentPartialWithIndentation(source []byte, indentation string) []byte

ReindentPartialWithIndentation applies leading indentation using the given display unit. It is intended for interactive editors that keep canonical formatting at submission boundaries but need a different on-screen width.

Types

type Options added in v0.3.9

type Options struct {
	// CanonicalImportPath returns the authored spelling that should be printed
	// for one parsed import. Project-aware callers may use their shared module
	// resolver; source-only callers leave it nil and preserve import paths.
	CanonicalImportPath func(string) string
}

Jump to

Keyboard shortcuts

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