fortran-language-server
fortran-language-server copied to clipboard
CMake compilation database support
Currently the language server supports 'only' a manually generated configuration file for communicating the file hierarchy. With CMake it's possible to generate a compilation database with contains all flags, directories, etc. for a given file. It would be nice for CMake user to add the reading of this database.
Thanks for the suggestion. I will look into this. I think that the manual config file is probably fine for 99% of projects, since you only need to specify directories/files if you want to exclude subdirectories of the project root. However, there may be some projects with complicated structures (likely using CMake) that would benefit from this more automated approach.
Yes you are probably right about that percentage number. Another advantage of the compilation database are that all compiler arguments are listed as well. My guess is that you're using gfortran for the diagnostics? Nevertheless other compiler may complain about other stuff. Say one is using PGI or IBM XL compilers, which may provide different errors etc. An issue with that approach may be that in a mixed language project ( which may be a case of use for CMake ) one would have to filter out the relevant Fortran files.
Actually, the only diagnostics currently implemented are simple ones that can be derived from the language server's internal representation of the code. At some point it would be nice to add a more complete set of diagnostics using compilers if a user provided the necessary build information as you described.
compile_commands.json parsing is not too difficult and there are mature generators.
You may check out https://github.com/nickdiego/compiledb and Buiding EAR.
One practical use case for this could be to extract the preprocessor definitions from the compiler command line per file and use them instead of the static ones from .fortls.
My only concern in general is that CMake doesn't produce this compilation db file by default which would limit the out-of-the-box experience.