I have a problem that seems to be benign, yet I could not figure out the solution myself.
My Fortran code uses
#include "file.f90"
directives, rather than the fortran-build-in
include("file.f90")
because the latter does not feature preprocessor directives (i.e. in files included this way, not CPP can be used).
However, if I open the code in Visual Studio Code, I get many "problem" messages that are related to fortls not understanding these include statements.
In particular, I have a module:
module precision
integer :: kind_parameter = ...
end module
And a second module using the first:
module hello
use precision
contains
#include "file.f90"
end module
And the file file.f90 contains a subroutine:
subroutine foo()
integer(kind=kind_parameter) :: i
end subroutine
then Visual Studio Code complains that kind_parameter is not defined.
As far as I understand, this is correct Fortran syntax. A workaround is to explicitly add use precision in the subroutine:
subroutine foo()
use precision
integer(kind=kind_parameter) :: i
end subroutine
Then, the errors disappear. I am using Visual Studio Code with the modern Fortran extension and fortls (which is different from fortran-language-server).
Is there a way for fortls to recognize the use statement correctly?
I suspected that fortls has trouble with the CPP directive and tried to force it to use CPP on lowercase file extensions, but this did not not change anything. The only thing that I can do is to manually add all use statements in all routines, which is tedious.