VSCode
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:
- Go to
File
-->Preferences
-->Settings
in VSCode. - Expand
Extensions
and selectCustom Local Formatters
. - Click
Edit in settings.json
.
- 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:
- Create or open a
.f90
file. - Right-click inside the editor and select
Format Document With...
. - Choose
Configure Default Formatter
. - Select
Custom Local Formatters
to usecodee 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:
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 thelanguages
section insettings.json
. -
Add
--verbose
to thesettings.json
command to view debug information ofcodee format
underOutput
-->Custom Local Formatter
.