VS Code Modern Fortran v3.1.0 Release

Modern Fortran Release v3.1.0 is finally out! :tada:

You will note that we had to release v3.1.0 instead of v3.0.0, due to some semver ordering issues.


  • If you like the extension consider leaving a VS Marketplace review
  • If you have any questions about the extension feel free to open a Q&A in our Discussion Board
  • If you want to get involved feel free to reach out to me, either here or on GitHub. General Contributing instructions can be found here

A summary of the changes can be found below:

What’s New

Linting

The linting diagnostics have been improved, with supported being added for
the Intel’s compilers, allowing custom compiler root paths and additional
diagnostic messages such as preprocessor warnings.

Intel OneAPI compilers

Intel compilers are now supported set the following options in settings.json:

{
  "fortran.linter.compiler": "ifort",
  "fortran.linter.compilerPath": "/path/to/intel/compilers/bin/ifort" // or ifx
}

Preprocessor warnings

Preprocessor warnings and errors are now properly supported during linting

Linting Diagnostics Preprocessor

Language Server fortls

A lot of the higher level features like Hover, Go-To, Peeking definitions and
finding References are provided by Language Servers. Modern Fortran now natively
supports the fortls Language Server.

Modern Fortran will prompt you to install fortls with pip upon initialization if
not detected in your system.

You can select a custom path to a fortls installation by setting the setting

{
  "fortran.fortls.path": "/path/to/fortls"
}

Some options for fortls have explicit settings through Modern Fortran settings,
like fortran.fortls.notifyInit and fortran.fortls.incrementalSync. You can
find a complete list of the explicit options in the Feature Contributions tab
of the Modern Fortran extension.

In case there is no explicit setting for a fortls option, you can pass the
option to fortls through

{
  "fortran.fortls.extraArgs": ["--nthreads=8", "--autocomplete_name_only"]
}

For more information about fortls configuration options see the
fortls Documentation

Multi Workspace and Single file support

It is now possible to have Language Server support with fortls for multiple
workspaces and single files. Simply open a standalone Fortran file and fortls or add a
folder to the workspace.

Configuration file watcher

There are 2 ways of passing options to fortls either through the VS Code
settings.json or through the fortls configuration file.
fortls is listening for changes on both types of files and will pass them to the server
without having to restart.

Warning: This feature is experimental if changes do not take effect you
can always restart fortls through the Command Palette.

Commands

Two convenience commands have been added, accessible from the Command Palette with
the prefix Fortran:

  • Fortran: Restart the Fortran Language Server
  • Fortran: Rescan Linter paths

Debug Hovering

Debugging functionality was previously limited when it came to nested
user-defined types and hovering. This issue has been resolved and full
information about an object can be shown in the hover messages while debugging.

Debugging Hover

Deprecations

Visual Studio Code Extensions

Due to the plethora of changes to the Modern Fortran extension the following
VS Code extensions are redundant and no longer compatible with Modern Fortran:

  • FORTRAN IntelliSense: provided an interface for a now deprecated Language Server. It has been superseeded by fortls nad its native integration with Modern Fortran.
  • Fortran Breakpoint Support: is redundant and deprecated, Modern Fortran has native breaking point support.
  • fortran: is redundant and deprecated, Modern Fortran has native support for Syntax Highlighting.
  • External Formatters like vscode-modern-fortran-formatter are redundant and deprecated, Modern Fortran has native formatter support for fprettify and findent.

Visual Studio Code Settings

The following settings have been deprecated are replaced by the following:

  • includePaths in favour of linter.includePaths
  • gfortranExecutable in favour of linter.compilerPath
  • linterEnabled in favour of linter.compiler == Disabled
  • linterExtraArgs in favour of linter.extraArgs
  • linterModOutput in favour of linter.modOutput
  • ProvideSymbols in favour of provide.symbols
  • symbols
  • provideHover in favour of provide.hover
  • provideCompletion in favour of provide.autocomplete

Other

There are a number of other bug fixes, feature enhancements and minor
improvements that have taken place in both the extension and the syntax highlighting. A brief list is shown below:

  • Changed need for matching begin-end scope names, in the following constructs:
    Functions, Modules, Programs, Module Procedures, Subroutines, Submodules.
    For a more detailed explanation as to why see the issue
    (#278)
  • Changed linter.compilerPath to use the full path to the compiler instead of the root
    (#500)
  • Merged Language Server’s log channel to Modern Fortran’s log channel
  • Fixed error stop variable syntax highlighting
    (#486)
  • Fixed issue with linter cache containing outdated folders
    (#464)
  • Fixed slow performance of very long lines by using a different solution for
    (#207)
    (#309)
  • Fixes linter activation from Disabled to some compiler X without having
    to restart the extension
    (#296)
  • Fixes nopass pointer erroneous syntax highlighting
    (#318)
  • Fixes % accessor highlighting for type-bound subroutines
    (#325)
  • Fixes fortls not spawning when ignoreWarning was set to true
    (#365)
  • Fixes formatting on Windows (needed .exe extension)
    (#354)
  • Fixes onSave formatting errors
    (#364)
20 Likes

Great work!!

1 Like

Absolutely brilliant, great stuff!

1 Like

Absolutely wonderful piece of software!
As a gnu/Linux user (open-suse) is there anything I must do to get the latest release or it will update automatically at the next package manager update?

1 Like

It should autoupdate (that is the default setting in VS Code). You can however make sure that your version is v3.1.0 by doing the following (see v3.1.0 next to the Extension name)

1 Like

BTW if someone knows people that currently work at Intel on the Fortran side of things, could you point them to this release to notify them that we support their compilers for linting now. I don’t think they are aware.

Attention @greenrongreen - please see the note above by @gnikit .

Thanks @FortranFan and @gnikit ! I’ll give it a try with VS Code on my Mac and put a reference on our User Forum.

3 Likes

Unfortunately, the link is broken (404).

Since some time (weeks, months?) I get these messages and no pipping or configuring seem to fix it. Does anybody else have this problem?
image

Then link must be old, I’ll update it, here is the working link: Configuration options - fortls

As for the fortls version, it would appear that you are using an outdated version. Specifically the outdated fortls is the one spawned by VS Code with the option:

  "fortran.fortls.path": "fortls"

Try and just use the default version in your global Python env (user level)

1 Like

It’s unclear how this can be done. Should I delete the option? I thought this option is exactly meant to point to the system version of fortls.

You will have to provide some more info, there is a number of things that can be going on.

  1. What have you set for "fortran.fortls.path"?
  2. What OS are you on?
  3. Open a new terminal and type fortls -v and post the output
  4. If you have anything other than the default option in "fortran.fortls.path", from a terminal also check the version of that custom fortls installation and post the output
  5. Also post the Output from the Modern Fortran log channel in VS Code
1 Like

Sorry, your first reply sounded like the solution was self-explanatory. That’s why I didn’t provide more info. I think I found the problem, see below.

For the sake of completeness:

  1. The entry is missing from JSON, I suppose because I put the default fortls in the text field.
  2. CentOS 8 Stream
  3. Before it was 2.2.10 , now it’s 2.9.0 (see below).
  4. Default
  5. Cannot replicate anymore after (finally) upgrading.

Solution

Apparently upgrading to a new version didn’t work but didn’t print an error either, while VS Code continued using the old version. And whenever I tried to uninstall, it only removed the (working or not) new version, not the old one.

$ fortls -v
2.2.10

$ python3.9 -m pip install --user --upgrade fortls
Requirement already satisfied: fortls in ./.local/lib/python3.9/site-packages (2.9.0)
Requirement already satisfied: json5 in ./.local/lib/python3.9/site-packages (from fortls) (0.9.8)
Requirement already satisfied: packaging in ./.local/lib/python3.9/site-packages (from fortls) (21.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./.local/lib/python3.9/site-packages (from packaging->fortls) (3.0.7)

$ type fortls 
fortls is /home/u2073032/.local/bin/fortls

$ cat ~/.local/bin/fortls 
#!/usr/bin/python3.9
# -*- coding: utf-8 -*-
import re
import sys
from fortls.__init__ import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

$ pip3.9 uninstall fortls                       
Found existing installation: fortls 2.9.0
Uninstalling fortls-2.9.0:
  Would remove:
    /home/u2073032/.local/bin/fortls
    /home/u2073032/.local/lib/python3.9/site-packages/fortls-2.9.0.dist-info/*
    /home/u2073032/.local/lib/python3.9/site-packages/fortls/*
Proceed (Y/n)? y
  Successfully uninstalled fortls-2.9.0

$ pip3.9 uninstall fortls
Found existing installation: fortls 2.2.10
Uninstalling fortls-2.2.10:
  Would remove:
    /home/u2073032/.local/lib/python3.9/site-packages/fortls-2.2.10.dist-info/*
Proceed (Y/n)? y
  Successfully uninstalled fortls-2.2.10

$ pip3.9 uninstall fortls
WARNING: Skipping fortls as it is not installed.

$ pip3.9 install --user fortls 
Collecting fortls
  Using cached fortls-2.9.0-py3-none-any.whl (92 kB)
Requirement already satisfied: packaging in ./.local/lib/python3.9/site-packages (from fortls) (21.3)
Requirement already satisfied: json5 in ./.local/lib/python3.9/site-packages (from fortls) (0.9.8)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./.local/lib/python3.9/site-packages (from packaging->fortls) (3.0.7)
Installing collected packages: fortls
Successfully installed fortls-2.9.0

$ fortls -v
2.9.0

I had not tried to uninstall the same package twice in a row. Didn’t know that was even possible. Thanks for your help!

Hello,

I have 2 points to mention:

1/ I face difficulties to configure correctly Modern Fortran Extension :

I am building a code with cmake in a directory located in:
$BUILD_DIR/myCode

The modules are present in directory:
$BUILD_DIR/myCode/modules

I gave that information to the extension:
Fortran > Linter: Include Paths
$BUILD_DIR/myCode/modules

and as it didn’t work, I also add it to:
Fortran > Linter: Mod Output
$BUILD_DIR/myCode/modules

But fortls doesn’t find the modules.

2/ Is it possible to quickly show all subroutines present in a file

  1. If you are using $BUILD_DIR in your definition of of the paths VS Code will not be able to resolve the variable name and hence it will fail. As a side note, the directories are relative to the VS Code root i.e. the directory where VS Code is open from. Other than that you settings seem okay to me, you will have to post either a screenshot or the relevant parts of your json settings for a more detailed response. The .mod files are generated by the compiler i.e. linter, so you should configure and build before you start. fortls is complementary to the linter.
    fortls by default will recursively look for source files (not the .mod files). I think there is a diagnostic message when you use an external module but that should not cause any problems. These are the fortls options for file discovery Configuration options - fortls you can configure them either via VS Code or via a fortls configuration file.

  2. That is what the Symbol Outline in VS Code does View: Focus on Outline View. It’s a little menu by default on the bottom left that shows all the symbols inside a file. You can also trigger an interactive menu by pressing Ctrl+Shift+O (or Cmd+Shift+O) and scroll through the same symbols or start typing to narrow the displayed results. Ctrl+T (or Cmd+T) will show the same but for all symbols in the whole worskspace. Click or press Enter to go to the symbol. For more info have a look at the fortls webpage, fortls (Feature tab).

2 Likes

Hello,

I entered full path for modules and includePath but it is still not working. Here are few screen captures:




and for the second point, I am unabble to show the structure of Fortran files:

First of all, welcome to the community @Christophe!

Linter

One obvious thing I noticed is the include Paths. There should be one item per line, so that should fix the linter (most likely). If you have any other compiler flags that you use for compilation e.g. -DHAVE_MPI you need to pass those to the extra args, (one per line).

fortls

Is that location to the fortls binary working? You can find out by doing something like this in a terminal

/your/fortls/inst/fortls --debug_filepath your_file.F90 --debug_rootpath . --debug_parser

If you could post the log channel output (copy-paste) of the extension that would also help

FYI when it comes to sharing settings for VS Code it is easier if you send the relevant parts of the settings.json. You can change between the UI and the JSON format via that little icon

image

1 Like

Here is the output for Modern Fortran

and here is the result of command:
~/.local/bin/fortls --debug_filepath Main.F90 --debug_rootpath . --debug_parser

(small file)

Testing parser
  File = "Main.F90"
  Detected format: free

=========
Parser Output
=========

=== PreProc Pass ===


=== Parsing Pass ===

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !!! Doc string - Line:1
Main.f90 !!! Doc string - Line:2
Christophe Peyret !!! Doc string - Line:3
Copyright (c) 1995-2022. All rights reserved. !!! Doc string - Line:4
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!! Doc string - Line:5
program space !!! PROGRAM - Ln:7
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !!! Doc string - Line:8
  use mpi !!! USE - Ln:9
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!! Doc string - Line:10
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !!! Doc string - Line:11
  integer  :: iErr !!! VARIABLE - Ln:12
  external :: driver_space !!! VARIABLE - Ln:13
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!! Doc string - Line:16
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !!! Doc string - Line:18
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!! Doc string - Line:27
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !!! Doc string - Line:30
Initialisation environnement MPI !!! Doc string - Line:31
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!! Doc string - Line:33

I still think you "fortran.linter.includePaths" are wrong, there should be one path per line in the output and the settings UI should look like this

As for fortls I am not sure what’s going on. What version are you using?

1 Like

Thanks,

Adding path item by item make fortls works.
I’m using version 2.11.0 of fortls

That is very usefull because I can see all warnings (and errors) now and correct it

But I still do not succeed to see the list of procedures and function contained in one file.