Git Product home page Git Product logo

vsc-erlang-formatter's Introduction

Erlang Formatter for Visual Studio Code

Automatically format your Erlang code.

Features

Auto format on Save

Auto format on save

Setup

1. Install the VSC extension

Install the Erlang Formatter from the Visual Studio Marketplace from this link or by searching from the Extensions tab within the app itself. If you have trouble finding it search for erlang-formatter.

2. Install Rebar

Follow the official Rebar install instructions or use the commands below which will download rebar3 to a temporary directory and install it for your OS user.

cd ~/projects
git clone https://github.com/erlang/rebar3.git
cd rebar3
./bootstrap
./rebar3 local install

Then add rebar3 to your PATH by putting it to your shell configuration file (for example ~/.zshrc or ~/.bash_profile).

export PATH=$PATH:~/.cache/rebar3/bin

3a. Default formatter setup

If you just want to get up and running quickly, run the following command for a good default. Otherwise read the section below for more detail.

echo -e "{plugins, [rebar3_format]}." >> ~/.config/rebar3/rebar.config

NOTE: The first time you format your code it might take a few seconds if rebar3 hasn't already downloaded the formatter plugin.

3b. Choosing a specific formatter

There are three main options for Erlang formatters right now. They are all written in Erlang and depend on rebar3. There's no community consensus on which to use, so you'll just have to pick one. Simply add the plugin to your project's rebar.config file, or set it up globally by adding it to ~/.config/rebar3/rebar.config instead. Then you'll be able to format Erlang files anywhere without project configuration.

{plugins, [rebar3_format]}.
  • Steamroller - Opinionated formatter with minimal configuration
{plugins, [steamroller]}.
  • erlfmt - Opinionated formatter with minimal configuration
{plugins, [erlfmt]}.

4. Extension configuration

Add the extension config to your preferences file.

  • Open preferences (Cmd/Ctrl + ,)
  • Open settings.json (Click the icon at the top right with the document's corner being folded over to open the file)
  • Paste this in:
"[erlang]": {
  "editor.defaultFormatter": "szTheory.erlang-formatter",
  "editor.formatOnSave": true
},
"erlangFormatter.formatter": "rebar3_format",

NOTE: If you want to use another formatter just replace rebar3_format with either steamroller or erlfmt. NOTE: You don't need to enable formatOnSave. If it's disabled then you can just manually select Format Document from the Command Palette (Cmd/Ctrl + Shift + P) in VS Code to run the formatter.

Links

Thanks

Thanks to the authors of these projects, which were highly valuable resources.

Formatters

Visual Studio Code Extensions

Releasing

  1. Bump the version number
  2. Update CHANGELOG.md
  3. npm run test
  4. vsce package
  5. vsce publish

For more info see "Publishing Extensions"

vsc-erlang-formatter's People

Contributors

dependabot[bot] avatar filmor avatar sztheory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

filmor 00mjk ajfafg

vsc-erlang-formatter's Issues

Integrate with Erlang language server for faster response times

Format on save is slow right now because it just runs the rebar3 steamroll command from CLI, so you get the BEAM startup lag of ~0.3s. By using the Erlang language server it will avoid the boot time since the Erlang env will already be warm and it can just run the command directly from the VM. This is how the Elixir LS fork does it with their mix format which is snappy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.