VS Code formatter extension for modern free-form Fortran (f90/f95/f2003/f2008) using the sable CLI.
Quick Start
- Install this VS Code extension.
- Open a free-form Fortran file.
- Run
Format Document.
- If
sable is missing, choose one of:
Install now to install sable-fortran from inside VS Code
How to install for manual instructions (Copy pip command, Run installer, or Open README)
- Or: run
pip install sable-fortran directly in your preferred environment
- If VS Code asks for a default formatter, choose
Sable Fortran Formatter.
- When prompted, choose whether to enable format-on-save (
Yes or No).
- If you choose
No, format manually with Format Document.
You can also run Sable Fortran Formatter: Install formatter (sable-fortran) from the Command Palette.
No additional extension settings are required for the default sable setup if sable is available on PATH (or if fortranFormatter.path points to it).
Optional configuration
Only add settings if you want to override defaults:
{
"fortranFormatter.path": "sable",
"fortranFormatter.args": ["format", "--diff", "${file}"],
"fortranFormatter.formatFolderArgs": ["format", "${folder}"],
"fortranFormatter.useStdin": false,
"fortranFormatter.cwd": "${workspaceFolder}",
"fortranFormatter.timeoutMs": 10000
}
If you want format-on-save preconfigured instead of using the prompt:
{
"[fortran-modern]": {
"editor.defaultFormatter": "eirik.sable-fortran-formatter",
"editor.formatOnSave": true
},
"[fortran_free-form]": {
"editor.defaultFormatter": "eirik.sable-fortran-formatter",
"editor.formatOnSave": true
}
}
Notes
Format Document formats the current file.
Format Selection is supported and formats whole selected lines.
Sable Fortran Formatter: Format Folder is available from Command Palette and Explorer folder context menu.
Sable Fortran Formatter: Install formatter (sable-fortran) installs sable-fortran into a selected Python environment with progress and output logging.
Sable: Reset Sable formatter settings removes Sable-specific Fortran formatter overrides from VS Code settings.
- Only modern, free-form Fortran is supported. Fixed-format (legacy) Fortran is not supported.
- If
fortranFormatter.path is set by workspace/workspace-folder settings, the extension prompts for confirmation (Allow and Remember) before running it.
- After successful install, if
fortranFormatter.path is invalid but the newly selected environment has sable, the extension offers to update the setting automatically.
Supported language IDs
The formatter provider is registered for:
fortran-modern
FortranModern
FortranFreeForm
fortran_free_form
fortran_free-form
Troubleshooting
Formatter executable not found:
- Use the
Install now prompt action, or run Sable Fortran Formatter: Install formatter (sable-fortran).
- For manual install:
python -m pip install sable-fortran.
- If needed, set
fortranFormatter.path to the absolute sable executable path for your selected environment.
- Install command fails:
- Open the extension output channel from the error action (
Show output) to inspect pip/interpreter errors.
- Confirm you selected the intended interpreter/environment in the installer picker.
- Timeout errors: increase
fortranFormatter.timeoutMs.
- Wrong project root for include/config resolution: set
fortranFormatter.cwd to ${workspaceFolder} or a specific directory.
- Empty formatting output in text mode: use diff mode (
--diff) or configure your formatter invocation to print formatted source to stdout.
- No format-on-save prompt: the prompt appears only after
Sable Fortran Formatter is selected as the default formatter for that Fortran language, and only if [language].editor.formatOnSave is not already true.