fortran-language-server icon indicating copy to clipboard operation
fortran-language-server copied to clipboard

CMake compilation database support

Open MagBad opened this issue 7 years ago • 5 comments

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.

MagBad avatar Sep 04 '18 09:09 MagBad

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.

hansec avatar Sep 04 '18 14:09 hansec

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.

MagBad avatar Sep 04 '18 15:09 MagBad

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.

hansec avatar Sep 10 '18 15:09 hansec

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.

MaskRay avatar Oct 11 '18 06:10 MaskRay

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.

letmaik avatar Aug 06 '19 20:08 letmaik