Skip to content

jlchmura/prettier-lpc-vscode

Repository files navigation

prettier-lpc-vscode

VSCode extension to format LPC (Lars Pensjö C) files with Prettier. It is written mainly for the LDMud flavor of LPC, but includes support for most FluffOS syntax as well.

WARNING

This extension should still be considered an early release. It may break your code. Use at your own risk.

Changelog

See CHANGELOG.md.

Installation

Install from the VS Code Marketplace: prettier-lpc-vscode

Configuration

This plugin, like Prettier, is opinionated. The plugin honors standard prettier config options which can be set via a .prettierrc file. In particular, the following options may be of interest to LPC developers:

API Option Description
printWidth Same option as in Prettier
tabWidth Same option as in Prettier
useTabs Same option as in Prettier
pairVariables See Pair Arrays

Multi-Line Objects

For arrays and functions, this plugin follow's prettier's multi-line objects rule. For tips on how to control whether objects are collapsed to a single line, or not, see: https://prettier.io/docs/en/rationale.html#multi-line-objects

Pair Arrays

In LDMud flavors of LPC there are often arrays that are treated as pairs. A common example of this is dest_dir. For example:

dest_dir = ({
  "room/pub", "west",
  "room/street1", "east",
});

By default, this plugin is set to identify a list of common variable names for which arrays should be formatted in pair mode as shown above. This list can be customized (or set to an empty array to completely disable this feature) by using the pairVariables setting.

An array can also be forced into pair mode by utilizing the @prettier-pair hint:

// @prettier-pair
string *pairs = ({
  "key 1", "value 1",
  "key 2", "value 2",
});

If you love this extension, you could

Buy Me A Coffee

Known Limitations

The folowing languages features are not supported yet:

  • Lambda parsing works, but is untested. Use extra caution.
  • Union types
  • Coroutines
  • LWobjects

To-Do

  • Support for remaining language features/syntax
  • Split AST parsing into separate package
  • Split prettier plugin portion into separate package
  • Add more options for customization

Other useful LPC tools

Also check out the LPC Language Services extension.