options

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package options is the configuration layer of thrift-ls. It loads and layers the thrift-ls.json document — formatting settings (owned by the formatter), include paths, and the log level — so configuration sources can override each other: defaults, a JSON config file, CLI flags, and LSP workspace settings.

The config file is discovered by walking up from the file being formatted, like Biome's config discovery. THRIFT_LS_CONFIG overrides the search with an explicit path.

Index

Constants

View Source
const ConfigFileName = "thrift-ls.json"

ConfigFileName is the JSON config file name.

Variables

This section is empty.

Functions

func AnchorIncludes added in v0.2.0

func AnchorIncludes(p *Patch, dir string)

AnchorIncludes resolves relative include paths in p against dir (the config file's directory), so resolution works the same no matter where the process was launched from. Absolute paths pass through.

func FindConfig

func FindConfig(dir string) (string, error)

FindConfig returns the absolute path of the config file for dir: THRIFT_LS_CONFIG when set, otherwise the nearest thrift-ls.json walking up from dir. An empty path means no config exists. The path is absolute because relative include paths in the config anchor to it.

func FindNearestConfig added in v0.2.0

func FindNearestConfig(dir string) (string, error)

FindNearestConfig returns the nearest thrift-ls.json found by walking from dir toward the filesystem root. It returns an absolute path, or an empty path when no config exists. It does not read THRIFT_LS_CONFIG.

Types

type LintConfig added in v0.1.8

type LintConfig struct {
	// Disabled names analyzers (by Name) to skip.
	Disabled *[]string `json:"disabled"`

	// Severity overrides a diagnostic's severity by code.
	Severity *map[string]string `json:"severity"`
}

LintConfig tunes the analysis pipeline: which analyzers run, and at what severity their diagnostics surface.

func (LintConfig) Validate added in v0.1.8

func (l LintConfig) Validate() error

Validate checks the lint settings for validity.

type Patch

type Patch struct {
	formatter.FormatPatch

	IncludePaths *[]string   `json:"includePaths"`
	LogLevel     *int        `json:"logLevel"`
	Lint         *LintConfig `json:"lint"`
}

Patch is a partial set of options; nil fields are unset. The formatting fields are promoted from the embedded formatter patch and decode flat, so thrift-ls.json keeps its top-level keys ("printWidth", ...).

func Default

func Default() Patch

Default returns the default options as a fully-set patch.

func Effective

func Effective(cfg *Patch) Patch

Effective returns the effective options for a file: defaults with the config patch applied. cfg may be nil.

func Load

func Load(path string) (*Patch, error)

Load reads and parses a config file. Unknown keys are rejected so that typos and stale settings (e.g. the removed overrides feature) fail loudly. This is the CLI edge (plain disk I/O); the server discovers through its FileSource instead (see lsp.FileConfigSource).

func Parse

func Parse(data []byte) (*Patch, error)

Parse parses a config document. Unknown keys are rejected so that typos and stale settings (e.g. the removed overrides feature) fail loudly. Include paths in the document are left as written; Load resolves them against the config file's directory.

func (Patch) Apply

func (p Patch) Apply(base Patch) Patch

Apply overlays p onto base: every set field of p replaces the corresponding field of base.

func (Patch) Validate

func (p Patch) Validate() error

Validate checks every set field for validity.

type Resolved added in v0.2.0

type Resolved struct {
	Patch *Patch
	Path  string
}

Resolved is one config lookup: the patch plus where it came from. Path is the source location for diagnostics (the thrift-ls.json path for file discovery, "" for in-memory sources). A nil Patch means no config.

type Source added in v0.2.0

type Source func(dir string) (Resolved, error)

Source resolves the config patch for a directory. It returns the patch plus its origin, so callers can pin diagnostics to the file. Frontends backed by a build system serve in-memory patches with no path.

Note the nil convention lives with the consumer: on lsp.Options a nil Source means file discovery through the server Files, and only options.PinnedSource(nil) disables it. A Source returning (Resolved{}, nil) also means no config.

func PinnedSource added in v0.2.0

func PinnedSource(patch *Patch) Source

PinnedSource always returns patch, skipping discovery. A nil patch means defaults. An explicit --config flag builds one of these.

Jump to

Keyboard shortcuts

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