Support `compile_commands.json` in `fortls`

I recently ran into the issue that fortls did not jump to the correct definition in a large code base, as there existed several globals with the same name, but in different compilation units, so they were not actually compiled together. From using clangd for C and C++ I really liked the approach of parsing a compile_commands.json file to pass the actual compilation flags to the language server. I prompted Claude Code to implement a feature in fortls to parse a compile_commands.json file and it works as expected. My fork now shows me the correct definitions. You can check it out here: GitHub - zandivx/fortls: fortls - Fortran Language Server
What do you think of this feature? Would someone be willing to do a code review if I opened a PR with these changes? I am happy to make further changes if needed. Thx in advance!

3 Likes

The ability to parse compile_commands.json would be great! I’ve had a quick look over your commits, and they look reasonable. It looks like you’re handling the two slightly different formats of the json file, which is great. My main comment would be to switch to using the builtin pathlib module over os – it’s got a much nicer interface, among other things. ruff check --select=PTH should catch everything.

1 Like

FYI fpm >= 0.12.0 does export it