Configuring fpm + Modern Fortran + fortls on VSCode issues

I’m pretty new to Fortran, so pardon if these questions are basic. i’ve installed fpm, Modern Fortran extension to VSCode and fortls, created a new project with fpm new. I’ve added stdlib as one of my dependencies on the fpm.toml file and ran fpm build. This is the end result:

So far so good, but my Problems tab is showing 2k+ issues, all of them on the dependencies. Is there any way of removing the dependencies from the error checking, while also keeping the libraries visible from VSCode to avoid the “Cannot open module foo.mod” message?

I imagined that the option would be this “Exclude Directories” thing, but I can’t manage to make it work. I’ve added all combinations of glob patterns trying to exclude the build directory, but no luck.

Additionally, I can’t interact with fortls through the command line. If I try, I get an unresponsive command prompt.

Any help is appreciated. Thanks!

1 Like

Can you post a few of these issues. They can be originating from either VSCode’s linter or fortls. My bet is the former. To appease the linter, after you have built with fpm, using something like this would probably work

  "fortran.linter.includePaths": [
    "${workspaceFolder}/build/**"
  ],

Please attach your full VSCode and fortls settings along with the respected versions, so we are on the same page.

fortls is a server to the code editor, users are not meant to interact with it directly. For debugging and developers we have a set of options that we use Configuration options - fortls. I would also suggest having a read of the whole Configuration options page not just the debug section, and letting us know what is not clear for novices such as yourself so that we can improve it.

VSCode is 1.88.1, with Modern Fortran (v3.4.2024041503 (pre-release)) and fortls 3.0.0rc2.

I haven’t changed much about VSCode settings except for playing around with excludeDirectories, but I can’t seem to remove it from the linter.

{
    "[FortranFreeForm]": {


    },
    "fortran.linter.compilerPath": "gfortran",
    "workbench.iconTheme": "vscode-icons",
    "code-runner.executorMap": {...
    },
    "files.autoSave": "afterDelay",
    "fortran.fortls.configure": "fortls",
    "fortran.logging.level": "Debug",
    "fortran.fortls.excludeDirectories": [
        "build/**",
        "/build/",
        "/build/**",
        "build/",
        "build",
        "build/dependencies/**",
        "/build/dependencies/**",
        "/build/dependencies/"
    ],
    "fortran.linter.includePaths": [
        "${workspaceFolder}/build/**"
      ],
    "emmet.preferences": {

    }
}

All of the issues are on the dependencies .f files, like so:

1 Like

The diagnostics errors are from fortls. Here is a config that should work

    // If you have a lot of dependencies you might want to fine-tune
    // your REGEX so that the linter does not seek .mod and .smod files
    // in so many directories
    "fortran.linter.includePaths": [
        "${workspaceFolder}/build/**",
        "${workspaceFolder}/src/**",
    ],
    // Previous comment applies here as well
    "fortran.fortls.directories": [
        "./src/**",
        "./build/dependencies/**"
    ],

All the other fortran settings are redundant or incorrect.

I’ve added the config that you’ve suggested and removed all other configs, but the same behavior continues, the dependencies folder is included in the error checking.

every time I restart VSCode and open my project folder, it reads the full contents of the dependencies folder like this:
image

1 Like

This is a separate issue from the ones mentioned. The pre-release has a feature enabled that will attempt to run all your sources through the linter. Disable it

"fortran.linter.initialize": false

That one did the trick! Thanks!