Skip to content

kpumuk/thrift-weaver

Repository files navigation

Logo
Weaver for Apache Thrift
Linter, Formatter, LSP Server and a VS Code Extension

Weaver for Apache Thrift helps you write and format Apache Thrift IDL files.

Note

Weaver for Apache Thrift is an independent project for Apache Thrift tooling. Apache Thrift is a trademark of The Apache Software Foundation. Repository names, module paths, and extension identifiers currently use thrift-weaver.

It has three parts:

  • thriftfmt: a safe formatter for .thrift files
  • thriftlint: a linter for .thrift files
  • thriftls: an LSP server for editors.
  • a VS Code extension with syntax highlighting and LSP support.

It is made for daily editor use. It keeps comments. It stays stable. It can handle broken or half-written files while you type.

All three binaries are pure Go (CGO_ENABLED=0) and embed the Apache Thrift grammar wasm artifact. No external .wasm file is required at runtime.

Important

Read RFC 0001 before code changes. If behavior or policy changes, update the RFC in the same PR.

Why Use Weaver for Apache Thrift

  • One stack for CLI and editor use.
  • Safe mode: if format is not safe, the tool returns an error.

Usage

Preferred method of installation

Install the extension from a Marketplace:

Manual method for installation

Download the VSIX from the latest GitHub release. Open the Command Palette and select "Extensions: Install from VSIX...", then open the file you just downloaded.

Local Installation

Needs

  • Go (pinned in mise.toml).
  • Node.js and npm (for the VS Code extension).

Setup From Source (recommended)

git clone https://github.com/kpumuk/thrift-weaver.git
cd thrift-weaver
mise trust
mise install
mise exec lefthook -- lefthook install

Build the CLIs:

go build -o thriftfmt ./cmd/thriftfmt
go build -o thriftlint ./cmd/thriftlint
go build -o thriftls ./cmd/thriftls

Quick Install With go install

go install github.com/kpumuk/thrift-weaver/cmd/thriftfmt@latest
go install github.com/kpumuk/thrift-weaver/cmd/thriftlint@latest
go install github.com/kpumuk/thrift-weaver/cmd/thriftls@latest

For stable installs, use a version tag, not @latest.

Use thriftfmt

Common commands:

thriftfmt path/to/file.thrift
thriftfmt --write path/to/file.thrift
thriftfmt --check path/to/file.thrift
thriftfmt --stdin --assume-filename foo.thrift < input.thrift
thriftfmt --range 120:240 path/to/file.thrift

Main flags:

  • --write, -w: write in place.
  • --check: non-zero exit when the file would change.
  • --stdin: read source from stdin.
  • --stdout: force stdout output.
  • --assume-filename: file name used in parser context and errors.
  • --line-width: preferred max line width (default 100).
  • --range start:end: byte range, half-open.
  • --debug-tokens, --debug-cst: debug dumps.

Exit codes:

  • 0: success.
  • 1: --check found changes.
  • 2: unsafe to format.
  • 3: internal or usage error.

Warning

thriftfmt refuses unsafe formatting and reports errors. It does not guess.

Use thriftlint

Common commands:

thriftlint path/to/file.thrift
thriftlint --stdin --assume-filename foo.thrift < input.thrift
thriftlint --format json path/to/file.thrift

Main flags:

  • --stdin: read source from stdin.
  • --assume-filename: file name used in parser context and diagnostics.
  • --format: text (default) or json.

Exit codes:

  • 0: no lint or parser diagnostics.
  • 1: diagnostics were found.
  • 3: internal or usage error.

Use thriftls

thriftls is a stdio LSP server. Your editor starts it.

Current features:

  • Live text sync.
  • Errors as you type.
  • Full-file lint diagnostics on open/save and debounced full-file lint on change.
  • Document formatting and range formatting.
  • Document symbols.
  • Folding ranges.
  • Selection ranges.
  • Semantic tokens (textDocument/semanticTokens/full).

Current built-in lint rules:

  • explicit field IDs required
  • explicit field IDs unique within the same containing field list
  • field names unique within the same containing field list
  • unqualified local type references must resolve, including typedef base types and container inner types
  • oneway functions must return void and must not declare throws
  • unqualified local throws types must resolve to exceptions
  • unqualified local service extends targets must resolve to services
  • deprecated field xsd_optional
  • deprecated field xsd_nillable
  • deprecated field xsd_attrs
  • deprecated struct/exception xsd_all
  • required fields inside union
  • negative explicit enum values

Runtime notes:

  • didChange uses incremental reparsing when edit eligibility checks pass; otherwise it falls back to a full reparse for that version.
  • Lint on change is currently full-file only. Changed-range lint is experimental and not enabled in the normative path.
  • Semantic lint currently resolves only unqualified names declared in the current document. Dotted include-qualified references are skipped until cross-file indexing exists.
  • There is no parser backend toggle. The supported runtime path is the embedded wasm parser.

VS Code Extension

The extension lives in editors/vscode.

Build for local development:

npm --prefix editors/vscode ci
npm --prefix editors/vscode run compile

Package a .vsix:

npm --prefix editors/vscode run package

Key settings:

  • thrift.server.path.
  • thrift.server.args.
  • thrift.format.lineWidth.
  • thrift.trace.server.
  • thrift.managedInstall.enabled.
  • thrift.managedInstall.manifestUrl.
  • thrift.managedInstall.allowInsecureHttp.

Managed install is on by default. If it fails and thrift.server.path is set, the extension uses that path.

Config Notes

  • Formatter defaults: line width 100, indent 2 spaces, max blank lines 2.
  • Mixed newline files are normalized to the main style (LF or CRLF) with an info message.
  • Invalid UTF-8 input is refused for formatting.

Contributing

Start with the RFC, then code.

Daily commands:

mise run fmt
mise run lint
mise run test
mise run ci

If you change behavior or policy, update RFC 0001 in the same PR.

Repository Map

  • cmd/: CLI entry points (thriftfmt, thriftlint, thriftls).
  • internal/: core engine packages (text, lexer, syntax, format, lsp).
  • grammar/tree-sitter-thrift/: Apache Thrift grammar and generated parser assets.
  • editors/vscode/: VS Code extension client.
  • testdata/: formatter fixtures, LSP scenarios, and corpus files.
  • docs/: RFCs, architecture notes, user guide, and release policy.

More Docs