A Prettier plugin for AL language and a VS Code extension that provides code formatting using this plugin.
- Install from VS Code Extensions Marketplace (direct link: AL Prettier or search for "AL Prettier")
- Or install manually by downloading the
.vsixfile and runningcode --install-extension al-prettier-vscode-0.2.1.vsix
- Use the keyboard shortcut:
Shift+Alt+F(Windows/Linux) orShift+Option+F(macOS) - Or right-click and select "Format Document"
Selection formatting is currently not supported. This feature will be available in future releases.
Enable format on save in VS Code settings:
{
"[al]": {
"editor.defaultFormatter": "alexander-drogin.al-prettier-vscode",
"editor.formatOnSave": true
}
}You can customize the formatting behavior in VS Code settings:
{
"alPrettier.tabWidth": 4,
"alPrettier.useTabs": false,
"alPrettier.printWidth": 120,
"alPrettier.groupGlobalVars": "none",
"alPrettier.noLineBreaksInAttributes": false,
"alPrettier.removeEmptyElements": false
}- tabWidth (default: 4): Number of spaces per indentation level
- useTabs (default: false): Use tabs instead of spaces for indentation
- printWidth (default: 120): Specify the line length that the printer will wrap on
- groupGlobalVars (default: "none"): Group all global vars in the object. Available options: "none" - keep the variables as is; "top": move all variable declarations to the top, after the object properties; "bottom": move variables to the bottom; "beforeCode": place variables before procedures.
- noLineBreaksInAttributes (default: false): Disable wrapping of procedure attributes even if the line exceeds maximum print width. Attributes are always printed in a single line.
- removeEmptyElements (default false): Remove elements without content (this includes table fieldgroups, page actions and layout sections)
- VS Code 1.75 or later
- AL language support (from Microsoft Dynamics 365 Business Central AL Language extension)
- Requires valid AL syntax to format correctly. Formatting of an AL statement that cannot be parsed correctly will throw an error.
- Range formatting is in development and currently not supported.
- #pragma, #if not CLEANX and similar precompiler instructions are interpreted as leading comments for the next token and may be unaligned after formatting.
- Not all AL objects are supported (yet). Currently supported objects:
- Codeunit
- Enum
- Enum extension
- Interface
- Page
- Page extension
- Query
- Report (without embedded RDL layout)
- Table
- Table extension
Contributions are welcome! Please submit issues and pull requests to the repository.
MIT