Giter Club home page Giter Club logo

vscode-scalafmt's Introduction

DEPRECATED

This extension is now deprecated in favor of Metals.

Read more about the deprecation here.


vscode-scalafmt

Visual Studio Code extension for formatting Scala code with scalafmt.

vscode-scalafmt

Try this out!

This extension is published on the Marketplace. Just search for vscode-scalafmt and install it!

Building from source

You can also try the latest unpublished version by building from source:

  1. Clone this repo
  2. Run npm install to install its dependencies
  3. 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 select Install from VSIX.... Now pick the file above and you should be ready to go!

How to use

The extension integrates directly with the Format Document and Format Selection commands of VSCode.

Manually

  1. Open the Command Palette (CMD + Shift + P)
  2. Select Format Document

or simply

  1. Alt + Shift + F

Alternatively you can format a selection of lines and using Format Selection in the Command Palette (CMD + K CMD + F).

Automatically, on save

It respects the editor.formatOnSave setting.

Configuration

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.

Troubleshooting

I get a Scala syntax error when formatting

The file you're formatting needs to be syntactically correct for Scalafmt to work. Fix the syntax of your code and retry.

I get a weird null-related error or a MatchError

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.

Nothing happens when I use the format shortcut

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.

I get a java.lang.Error

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").

vscode-scalafmt's People

Contributors

gabro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

constantine2nd

vscode-scalafmt's Issues

Detect .scalafmt.conf

Currently the extension uses the default configuration.
As soon as the JS facade accepts options, we should look for a .scalafmt.conf file in the current workspace and use those options.

Format selection

Again, this is blocked by the JS Facade, but it should be fairly trivial to implement.

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.