Skip to content

Formatting

Ashwin Shenoy edited this page Mar 19, 2022 · 2 revisions

Formatting

You can easily format your prisma files using LSP's format feature. There are several ways to invoke it.

  1. Using the context menu. Right click in your schema file & select LSP -> Format File to format. This option is also available from the main menu as Edit -> LSP: Format File.
  2. Using the command palette. Open the command palette and select LSP: Format File.

Customizing how to invoke LSP's format.

The command for LSP's format is lsp_format_document. So you can bind it to any key binding you want. As an example,

{
    "keys": ["shift+alt+f"],
    "command": "lsp_format_document"
}

Format on save.

If you want to automatically format your schema files on save, then:

  1. Open any Prisma schema file.
  2. From the main menu, go to Preferences -> Settings -- Syntax Specific. This should open a split layout window.
  3. On the right hand side, paste the following and save the file.
// These settings override both User and Default settings for the Prisma syntax
{
    "lsp_format_on_save": true
}

Your Prisma schema files will now automatically be formatted everytime you save them.

The lsp_format_on_save is a setting that automatically invokes LSP's format feature (provided by the language server) on your document on save.