Skip to main content

VSCode

Goal

Integrate codee format with Visual Studio Code to format Fortran code.

Prerequisites

Ensure you have:

  • codee installed and accessible from your command line.
  • Visual Studio Code installed on your system. This guide has been tested with v1.96.4.
  • Basic familiarity with VSCode's interface and settings.

Install Fortran language support

Visual Studio Code requires additional extensions to work with Fortran files. We recommend installing the official Modern Fortran extension developed by fortran-lang.

Alternatively, you can choose other Fortran extensions. However, this guide assumes you have Modern Fortran installed and enabled.

Install Custom Local Formatters

Additionally, install the Custom Local Formatters extension to connect VSCode with codee format.

Configure Custom Local Formatters for codee format

Next, we need to configure Custom Local Formatters to use codee format for Fortran files:

  1. Go to File --> Preferences --> Settings in VSCode.
  2. Expand Extensions and select Custom Local Formatters.
  3. Click Edit in settings.json.

Edit in settings.json option for Custom Local
Formatters

  1. Add or merge the following configuration into your settings.json:
{
"customLocalFormatters.formatters": [
{
"command": "codee format -",
"languages": [
"FortranFreeForm",
"FortranFixedForm"
],
}
],
}

Set codee format as the default formatter

To make codee format your default Fortran formatter:

  1. Create or open a .f90 file.
  2. Right-click inside the editor and select Format Document With....
  3. Choose Configure Default Formatter.
  4. Select Custom Local Formatters to use codee format.

Repeat these steps with a .f file if you also work with fixed-form Fortran.

Usage tips

You can now format Fortran files in VSCode with codee format:

  • Right-click inside the editor and select Format Document.

Additionally, VSCode offers the option to automatically format your Fortran files whenever you save a file. If you are interested in enabling this feature, search for the Format On Save option in the VSCode settings:

Format On Save option for VSCode

Troubleshoothing

If you encounter issues with codee format:

  • Ensure codee is properly installed and accessible from the command line.

  • If you use a full path in settings.json, verify it is correct.

  • If Custom Local Formatters does not appear as a formatting option for Fortran, verify the languages section in settings.json.

  • Add --verbose to the settings.json command to view debug information of codee format under Output --> Custom Local Formatter.