Fortls not finding some module dependencies

I’m having a problem with fortls sporadically saying it can’t find the .mod files for some of the modules in my project.

I have a mixed Fortran-C codebase, with a mix of legacy FORTRAN and modern modular Fortran. I am trying to get it set up and working in VSCode in Windows, using the Modern Fortran extension and fortls, with a Mingw installation of gfortran 8.5. It uses CMake. It’s almost fully working. It builds and runs.

Fortls sometimes lints a use statement and says it can’t find the .mod file (“no such file or directory”). I dug into the VSCode “Output” tab and saw that fortls doesn’t actually use the .mod files from the primary build, which are all present in the expected location. Rather it runs small compiler jobs on demand in the background to generate the .mod files using the gfortran -fsyntax-only option and places them in a different directory for its own use. I tried rerunning some of these commands manually and sometimes it works, but sometimes it fails because the module depends on another module whose .mod file it can’t find.

Is this a known issue, that fortls can’t generate .mod files recursively to resolve dependencies?

Update: Adding more diagnostic info.

Here’s a sample from the VSCode Output pane with line breaks added for readability:

[INFO - 1:42:18 PM] [build.single] Compiler query command line: 
C:\Users\<user>\Local\mingw-w64\bin\gfortran.EXE 
-fsyntax-only -cpp -ffree-line-length-none -ffixed-line-length-none -Wall 
-J c:\Users\<user>\AppData\Roaming\Code\User\workspaceStorage\531fdd820992dc2444bf7af4f6575b02\fortran-lang.linter-gfortran\include 
-ffree-form 
-o c:\Users\<user>\<project_path>\aero.f90.o 
c:\Users\<user>\<project_path>\aero.f90

There’s no info in the Output pane about the success or failure of this command.

There’s a PR to add compile_commands.json support to fortls that might be worth trying out to see if it helps.

I’m not using VSCode to drive the build. This project has its own build scripts that invoke CMake and mingw-make.

But hypothetically if I wanted to try out the PR, how could I do that? Would I have to pull down the repo and build fortls from source?