Modern Fortran for VS Code v4.0.0 Release

Hi all, it’s been a while!

Modern Fortran Release v4.0.0 is finally out! :tada:

This effort has been a few years of work and took a lot longer to release than expected.
I have written a top-level summary of most new features, but the changes are numerous. Below are some comments I would like to point out in addition to the What’s New section below.

  • Users will be pleased to know that the extension is available in both VS Code Marketplace and Open VSX Marketplace. For Open VSX users the bullet points in this section are of particular relevance. Nightly pre-releases will be available to both chanels.

  • Windows users should finally have a slightly better experience with python installing packages and a full rework is in progress (albeit slowly).

  • Issues with extension signing and publisher verification have been fully resolved.

  • Features like the Linter Initialisation I would classify as experimental, and stay away from unless your project is very simple. Probably this feature will be reworked with fpm/cmake in mind.

If you like the extension consider leaving a VS Marketplace review or a Open VSX Marketplace review.

The roadmap for the next major features to Modern Fortran is far from being complete and I would love to hear your ideas. Currently I am thinking:

  • linting for nvidia compilers
  • Better python support
  • integration with fpm/cmake/makefiles
  • some major refactorings in the codebase

On a personal note, I will be off for a few months, but when I am back I am excited to start working on fortls, Modern Fortran and our many other Fortran-lang projects.

Thanks for your time and chat soon,
Giannis


What’s New (v4.0.0)

:tada: Modern Fortran Release v4.0.0 :tada:!

Linter

fypp support

Adds some initial support for fypp when using gfortran. More compilers will follow soon!

Improved diagnostics for GNU Fortran

Added support for parsing plain text diagnostics from gfortran v11+
thus allowing the display of multiline diagnostics

module err_mod
    private
    implicit none   ! <- Error here previously not shown
    contains
        subroutine foo(arg1, arg2)
            integer, intent(in) :: arg1, arg2
            print*, 'arg1:', arg1, 'arg2:', arg2
        end subroutine foo
        subroutine proc_with_err()
            call foo()
        end subroutine proc_with_err
end module err_mod

LFortran Linter support

The LFortran linter is now available in the extension. It can be enabled by setting the fortran.linter.compiler setting to lfortran.

Persistent Cache

By default, now the linter uses a unique VS Code, workspace specific persistent cache directory to store all output files generated by the linter. This should prevent
any unexpected behaviour where the linter produces unwanted .mod files that
are then picked up by the build system.

You can clean the cache by running the Fortran: Clean Linter generated files command, see Commands for more details.

Dynamic Linter Options

Linter options now update automatically when settings change, so you don’t need to restart the extension or reload the window for changes to take effect.

Reduced Linter Noise

Duplicate diagnostic messages from the linter have been removed, resulting in a cleaner problems panel.

Commands

A series of new commands have been added, see New Commands section for more details.

  • Fortran: Initialize Fortran Linter
  • Fortran: Clean Linter generated files
  • Fortran: Clean All Linter Diagnostics

User Interface (UI)

Run and Debug individual files

You can now run and debug individual files. This is useful for debugging small snippets of code. To do this, right-click on the file and select Run File or Debug File from the context menu.

Log Channel improvements

The Modern Fortran log channel has had a small revamp.
Logs are now colourized to make reading them easier

Setting verbosity level

You can now choose the verbosity level of the extension by setting the following option in the settings

{
  "fortran.logging.level": "Error"
}

Added Fortran Logo icon

Added a new icon for the Fortran Language files

image

Added relative path resolution for fortls and formatters

It is now possible to define the path to fortls or the formatters using relative
paths to the top-most workspace folder.

"fortran.fortls.path": "./venv/bin/fortls"

Added variable resolution support for fortls

Previously, internal VS Code variables like ${workspaceFolder} were not resolved
when defining the path to fortls. This has now been fixed.

"fortran.fortls.path": "${workspaceFolder}/venv/bin/fortls"

Added fpm.toml schema validation

Leveraging the support for schemas from the Even Better TOML extension,
Modern Fortran now provides a schema for fpm.toml file validation and autocompletion.

fpm-toml-validation

Added fortls configuration schema validation

We have also added schema support for fortls configuration files, providing validation and autocompletion. Currently this is manually updated, in the future we will automate and improve the integration between the two.

Syntax Highlighting improvements

  • Added highlighting for sync and event image control statements.
  • Fixed various highlighting issues for FORMAT statements, Fixed Form comments, and labelled if/where constructs.
  • Fixed nested type bound procedure highlighting e.g. call a%b%c%foo() a, b and c are correctly highlighted now.
  • And many other changes that are too long to list.

Improved Installation of dependencies using VS Code Tasks

The extension dependencies are now installed using Visual Studio Code’s Tasks. That means that the commands are run from within the VS Code terminal, inheriting any environment variables already present. Particularly useful when using Python virtual environments.

New Commands

A series of new commands have been added for the linter

Fortran: Initialize Fortran Linter (Experimental)

Runs a naive mock compilation of all the Fortran source files found in the project
in order to generate the .mod and .smod files necessary for the linter. This
also generates all the Diagnostics for the project.

Fortran: Clean Linter generated files

Cleans all the .mod and .smod files generated by the linter that are placed
in the persistent cache storage of VS Code for this workspace.

Fortran: Clean All Linter Diagnostics

Cleans all the diagnostics generated by the linter.

New Settings

Hide Release Notes fortran.notifications.releaseNotes

Hide release notes when the extension in being installed or updated.

"fortran.notifications.releaseNotes": true

Linter Initialization fortran.linter.initialize (Experimental)

An option, by default false, that will attempt to initialize the linter with
all the Fortran source files found in the workspace upon the extension activation.

Performs the same task as the Fortran: Initialize Fortran Linter command.

Cleaning Diagnostics fortran.experimental.keepInitDiagnostics (Experimental)

An option to keep or discard all the diagnostics generated by running the
initialization process of the linter.

Log Channel Verbosity fortran.logging.level

An option to set the verbosity level of the extension log channel.

Other Changes

Improved performance of the linter

Converted the linter into using asynchronous processes, which should improve the overall performance and responsiveness of the diagnostics.

Update native symbol provider

The native symbol provider (one used when fortls is not present) has been updated
to use the new VS Code API.

Changed Linter glob resolution module to glob from fast-glob

The fast-glob module was causing issues with the linter when using the ** glob pattern. The parent directory would not be included in the results see, https://github.com/mrmlnc/fast-glob/issues/47.

This was problematic since users had to define the include directories twice,
once with the glob pattern and once without it. We have switched to the glob,
which is slower but does not suffer from this issue.

The cache used by the linter should help mitigate any performance issues.

Nightly Build Release Channel

We have introduced a Nightly Release Channel for the extension. This version is built and published every day at 00:00 UTC, allowing you to test the latest features and bug fixes as soon as they are merged.

:bug: Bug Fixes :bug:

For a complete list of bug fixes, please see the CHANGELOG, this is just a very small curated summary.

  • Fixed bug where the linter’s internal cache directory would not always exist
    (#698)
  • Fixed brittle installation process of Python packages on Windows
    (#1121)
  • Fixed bug where formatting arguments would not be updated from settings.json
    (#1007)
  • Fixed bug where linter would not use the correct Fortran file association
    (#904)
  • Fixed bug where custom line length arguments (e.g. -ffree-line-length-none) were overridden by defaults
    (#925)
22 Likes

Thank you and all who contributed! This is absolutely critical infrastructure for modern Fortran development. Thinking back to before this existed it was like the dark ages! Great work!

3 Likes