Is there a document formatter extension for Solidity files within visual studio code?

Viewed 1808

I am used to formatting my code by using the (Ctrl + Shift + i) keyboard shortcut. However, when I use the same shortcut for solidity code (with .sol extension) I get a notification telling me 'There is no document formatter for solidity files installed'. Does anyone know of an extension that can do the job?

2 Answers

Prettier works with solidity files.

There are some issues recently on their GitHub page but I have been using it recently and it does the job.

To use Prettier as a default formatter for solidity files:

  • Open any .sol file and press Ctrl + Shift + P
  • Search for format document with
  • Set the default formatter to Prettier

These are the two visual studio integrations listed in the solidity documentation.

I dont use visual studio so i dont know if its exactly what you are looking for but maybe it helps.

EDIT: I've been using VS and the solidity extension recommended is: Visual Studio Code extension

The extension provides:

  • Syntax highlighting

  • Snippets

  • Compilation of the current contract (Press F1 Solidity : Compile Current Solidity Contract), or F5

  • Compilation of all the contracts (Press F1 Solidity : Compile all Solidity Contracts), or Ctrl+F5 / Cmd+F5
  • Code completion for all contracts / libraries in the current file and all referenced imports
  • Default project structure (solidity files needs to be in the 'src' directory, and libraries in the 'lib' directory). Libraries will follow the same structure.
  • Compilation supporting EIP82 (dappfile and dependency packages)
  • Support for different solidity versions (Remote and local)
  • Code generation using https://github.com/Nethereum/abi-code-gen, it includes currently the default template for Nethereum service, dtos generation. (Open 'contractName.json' after compilation from the bin folder. Press F1 and press - - Solidity: Code generate from compilation output..) Please contribute more templates.
  • Linting using Solhint or Solium
Related