I am working with the Modern Fortran extension in Visual Studio Code on Windows and keep encountering a persistent issue. Despite having correctly installed findent, fortran-language-server, and fprettify using a specific Python interpreter and updating my user settings.json in VS Code to include the necessary path, the extension does not seem to recognize findent, and I continue to receive the following message:

Installing findent.exe through pip with --user option
Source: Modern Fortran

enter image description here

Here are the steps I've taken:

  1. Selected the Python interpreter inside Visual Studio Code explicitly set to C:\Users\<userName>\AppData\Local\Programs\Python\Python312\python.exe.
  2. Installed the required packages with the commands:
    • C:\Users\<userName>\AppData\Local\Programs\Python\Python312\Scripts\pip.exe install findent --user
    • C:\Users\<userName>\AppData\Local\Programs\Python\Python312\Scripts\pip.exe install fortran-language-server
    • C:\Users\<userName>\AppData\Local\Programs\Python\Python312\Scripts\pip.exe install fprettify
  3. Added the following to my settings.json to ensure the VS Code terminal recognizes the scripts installed by pip:
    "terminal.integrated.env.windows": {
        "PATH": "${env:PATH};C:\\Users\\<userName>\\AppData\\Roaming\\Python\\Scripts;"
    }
    

Despite these configurations, indentation, beautifying, and prettifying for Fortran code do not work, and I keep seeing the prompt to install findent.

Has anyone faced a similar issue, or can you offer insight into what might be missing or incorrectly configured in my setup?

1

There are 1 best solutions below

0
gnikit On

In Modern Fortran, Windows autodetection of Python packages is a bit problematic at the moment, see PR and GSoC project.

Solution 1: quick

That being said for users that don't have the default pip location added to their PATH, a very low effort, platform independent, workaround is shown in this comment.

Solution 2: long

If you want to get it working without the aforementioned workaround, you will have to:

  • Start by installing the pre-Release of Modern Fortran
  • To make debugging easier set the option fortran.logging.level to DEBUG, your VS Code OUTPUT pane should now contain all sorts of useful messages under Modern Fortran.

Formatting

  • In step 2. when installing fprettify copy the directory where pip installs the .exe
  • use it to set the Modern Fortran option fortran.formatting.path equal to that directory (without fprettiffy.exe, just the full directory).

Language server

  • You must use fortls not fortran-language-server. Install via pip install fortls --pre to install the pre-release (highly recommended).
  • Similarly to the formatter, copy the directory where pip install the fortls.exe
  • Set Modern Fortran option fortran.fortls.path to install directory + fortls.exe in your VS Code settings (quite annoying that the formatter and this option require slightly different inputs, we will fix in a future release).

The debug logs in the OUTPUT pane will be extremely helpful when you are trying to setup your machine.


As a side note, I think Step 3. should not work for any VS Code extension, unless they have gone out of their way to implement such functionality. The VS Code extension environment knows nothing about the VS Code terminal PATH. I think the terminal inherits from the VS Code environment, not the other way around.