This extension is now deprecated in favor of Metals.
Read more about the deprecation here.
Visual Studio Code extension for formatting Scala code with scalafmt.
This extension is published on the Marketplace. Just search for vscode-scalafmt
and install it!
You can also try the latest unpublished version by building from source:
- Clone this repo
- Run
npm install
to install its dependencies- Run
npm run build
Now you should have a file named
vscode-scalafmt-{version}.vsix
in the current directory.
Open VS Code, open the Command Palette (
CMD + Shift + P
) and selectInstall from VSIX...
. Now pick the file above and you should be ready to go!
The extension integrates directly with the Format Document
and Format Selection
commands of VSCode.
- Open the Command Palette (
CMD + Shift + P
) - Select
Format Document
or simply
Alt + Shift + F
Alternatively you can format a selection of lines and using Format Selection
in the Command Palette (CMD + K CMD + F
).
It respects the editor.formatOnSave
setting.
Create a .scalafmt.conf
file as described in http://scalameta.org/scalafmt/#Configuration. By default the extension will look for this file in ${workspaceRoot}/.scalafmt.conf
. You can customize this path with the scalafmt.configFilePath
setting of VS Code.
The file you're formatting needs to be syntactically correct for Scalafmt to work. Fix the syntax of your code and retry.
This is most likely a bug in the parsing of the configuration file. The way it's currently done is hackish (to use kind words). If you face one of these, please open an issue including the entire .scalafmt.conf
you're using.
Open the Command Palette (CMD + P
) and check if you have the Format Document
option available. If you don't... have you tried turning it off and on again? Seriously, something is off, try restarting VS Code and/or re-installing the extension.
This is again a failure in the parsing of the configuration file. If this happens, check if your config file contains unwrapped string literals (i.e. strings without the quotes) that have a /
in it (e.g. some/path
). This is a known bug that is already being addressed. An easy workaround is to wrap those strings in quotes (e.g. "some/path"
).