Documentation Index
Fetch the complete documentation index at: https://mintlify.com/prisma/prisma-engines/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Prisma Format (prisma-fmt) is a multi-purpose tool that provides:
- Schema formatting: Consistent, automatic formatting for Prisma schema files
- Language Server Protocol (LSP): Powers IDE features like autocomplete, hover, diagnostics, and more
- Schema linting: Warnings and suggestions for schema improvements
- Code actions: Quick fixes and refactoring suggestions
prisma-fmt is the bridge between your editor and the Prisma Schema Language. It’s what makes the Prisma VS Code extension and other editor integrations possible.
Architecture
Prisma Format is built on top of the PSL (Prisma Schema Language) parser and provides LSP-compliant features:Formatting
Consistent schema formatting with configurable indentation
LSP Features
Autocomplete, hover info, diagnostics, references, and code actions
Validation
Real-time schema validation and error reporting
Quick Fixes
Automated solutions for common schema issues
Core Modules
The crate is organized into focused modules:API Functions
Schema Formatting
Format Prisma schemas with consistent style:datamodel: JSON-serializedSchemaFileInput(single or multiple files)params: JSON-serializedDocumentFormattingParams(LSP standard)
Text Document Completion
Provides autocomplete suggestions:- Model names
- Field types
- Attribute names (
@id,@unique,@default, etc.) - Attribute arguments
- Datasource providers
- Generator providers
- Relation field names
- Enum values
Hover Information
Provides contextual information on hover:- Field type documentation
- Attribute descriptions
- Model relationship information
- Native type mappings
- Validation constraints
Code Actions
Suggests quick fixes and refactorings:Block Actions
Add missing opposite relation fields, add @@map for naming conventions
Field Actions
Add missing relation arguments, fix relation field types
MongoDB Actions
Add @db.ObjectId for MongoDB IDs, fix composite type usage
Multi-Schema Actions
Add schema references for multi-schema setups
Relation Mode Actions
Add relation mode configuration, add missing indexes
Relation Actions
Fix broken relations, add relation names, add referential actions
Find References
Finds all references to a symbol:- Model names (used in relations, @@map, etc.)
- Enum names (used in field types)
- Field names (used in relations, indexes)
- Composite type names (MongoDB)
Schema Validation
Validates schema and returns errors:- Syntax errors
- Type errors
- Relation errors
- Constraint violations
- Attribute validation
- Database-specific validations
Configuration Extraction
Extracts datasource and generator configuration:DMMF Generation
Generates Data Model Meta Format:- All models and their fields
- All enums and their values
- Relations and their properties
- Unique constraints and indexes
- Used for Prisma Client generation
Schema Merging
Merges multiple schema files:- Multi-file schema support
- Client generation from split schemas
- Schema composition
Linting
Provides schema quality warnings:- Naming convention violations
- Missing indexes on foreign keys
- Inefficient relation patterns
- Deprecated syntax usage
LSP Context
Internal LSP operations use a shared context:- Parsed schema database
- Configuration (datasources, generators)
- Active file being edited
- Database connector information
Code Actions in Detail
Block-Level Actions
Add missing opposite relation field:Field-Level Actions
Fix relation field types:MongoDB-Specific Actions
Add @db.ObjectId for MongoDB:Relation Mode Actions
Add missing indexes for Prisma relation mode:Integration with Editors
VS Code
The Prisma VS Code extension uses prisma-fmt:- Runs as a language server process
- Provides real-time diagnostics
- Offers autocomplete and hover info
- Enables code actions (quick fixes)
- Handles formatting on save
Other Editors
Any editor with LSP support can use prisma-fmt:- Neovim: Via
nvim-lspconfig - Emacs: Via
lsp-mode - Sublime Text: Via
LSPpackage - IntelliJ IDEA: Via Prisma plugin
Testing
prisma-fmt uses snapshot testing extensively:Test Structure
Tests useexpect! macros for snapshot testing:
Preview Features
Get available preview features:Native Types
Get native type information:Referential Actions
Get available referential actions:Binary Distribution
prisma-fmt is distributed as:- Native binary: For CLI usage and local LSP servers
- WASM module: For browser-based tools and web editors
Building
WASM Build
Seeprisma-schema-wasm crate for browser-compatible builds.
Common Issues
CRLF Line Endings
Example test:Snapshot Updates
After changing diagnostics:- Run tests with
UPDATE_EXPECT=1 - Review git diff carefully
- Ensure changes are intentional
- Commit updated snapshots
Feature Flags
Some tests require specific feature flags:Performance
The LSP implementation is designed for real-time performance:- Incremental parsing: Only re-parse changed portions
- Caching: Parser database cached between requests
- Async operations: Non-blocking LSP server
- Efficient completion: O(1) lookup for most completions
Example Usage
Formatting via CLI
Running as LSP Server
Validation
Related Components
- Prisma Schema Language - The underlying parser and validator
- Schema Engine - Uses prisma-fmt for schema validation
- Query Compiler - Uses PSL for data model understanding
Source Code
Explore the prisma-fmt source code:- Main crate:
prisma-fmt/ - LSP implementation:
prisma-fmt/src/ - Code actions:
prisma-fmt/src/code_actions/ - Completions:
prisma-fmt/src/text_document_completion.rs - Repository: prisma/prisma-engines