Skip to main content
The prisma-fmt binary provides formatting and language server protocol (LSP) features for Prisma schema files. It’s used by editor extensions and the Prisma CLI.

Binary Location

After building:

Command Line Interface

The prisma-fmt binary supports multiple modes:

format

Format a Prisma schema file:
--input
path
Input file to format. If not specified, reads from stdin.
--output
path
Output file for formatted content. If not specified, writes to stdout.
--tabwidth
number
default:"2"
Number of spaces for indentation
Example:

native-types

Get available native types for database connectors:
Output: JSON array of available native types for the datasource provider:

referential-actions

Get available referential actions for the datasource:
Output: JSON array of supported referential actions:

preview-features

List all available preview features:
Output: JSON array of preview features:

debug-panic

Artificially panic for testing error handling:
This command intentionally crashes the process. Only use for testing.

Language Server Protocol (LSP)

Prisma-fmt implements the Language Server Protocol for editor integration. It’s typically used through editor extensions, not invoked directly.

LSP Features

Formatting

Formats the entire document with configurable indentation.

Completion

Provides context-aware completions:
  • Model and field names
  • Attribute names (@id, @unique, etc.)
  • Datasource providers
  • Generator configurations
  • Relation field types

Hover Information

Shows documentation when hovering over:
  • Field types
  • Attributes
  • Native types
  • Relations

Code Actions

Provides quick fixes and refactorings:
  • Add missing @relation attributes
  • Create missing opposite relation fields
  • Add missing @map or @@map attributes
  • Fix relation names
Example code action:

Find References

Finds all references to:
  • Models
  • Fields
  • Enums

Rename

Renames symbols across the schema file.

Document Symbols

Provides outline view of:
  • Models
  • Enums
  • Datasources
  • Generators

Editor Integration

Prisma-fmt is typically used through editor extensions:

VS Code

The Prisma VS Code extension uses prisma-fmt:

Neovim

Using nvim-lspconfig:

Other Editors

Any LSP-compatible editor can use prisma-fmt by configuring it as a language server for .prisma files.

Building the Binary

1

Build with Cargo

2

Find the binary

3

Test formatting

WebAssembly Build

Prisma-fmt is also available as a WebAssembly module for use in browsers:
Output: ./target/prisma-schema-wasm/

WASM API

Testing

Prisma-fmt uses snapshot testing with expect-test:

Example Test

Environment Variables

RUST_LOG
string
Configure logging verbosity (e.g., debug, prisma_fmt=trace)
UPDATE_EXPECT
1
Update expect-test snapshots during test runs

Prisma Format Component

Deep dive into prisma-fmt architecture

PSL Overview

Prisma Schema Language specification

PSL Parser

How schema parsing works

PSL Validation

Schema validation system