Support parsing of compile_commands.json#504
Conversation
Add parser for Clang Compilation Database (compile_commands.json) to extract include directories, preprocessor definitions, and source files from build systems like CMake and fpm. The parser extracts -I (include dirs), -J/-module (module dirs), and -D (preprocessor definitions) from compiler arguments. It also builds a file-to-module-dir mapping from -J flags, which is used for disambiguating modules with the same name in different compilation units. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Extract file-to-module-dir mapping from -J flags to disambiguate modules with the same name across different compilation targets. Changes: - Modify obj_tree to support multiple objects with the same key - Add obj_tree_getter callback for context-aware module lookup - Load compile_commands.json during workspace init Parser enhancements for real-world fpm/CMake projects: - Recursive search fallback for non-standard locations - Path normalization with basename lookup when build paths differ - Filter intermediate -pp.f90 preprocessor files - Track module output dirs per file for target grouping Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
@certik maybe you got time to look at this as well? |
gnikit
left a comment
There was a problem hiding this comment.
This is a substantially more invasive change changing how the language servers parser works.
I will have a look properly but we will have to isolate the impact.
I am happy to split the PR in smaller chunks or make changes according to your feedback |
|
Awesome thanks. I'll have a look tomorrow during my flight |
|
@zandivx make sure the CI passes first, it's currently failing. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #504 +/- ##
==========================================
- Coverage 88.22% 87.82% -0.41%
==========================================
Files 35 36 +1
Lines 4800 5051 +251
==========================================
+ Hits 4235 4436 +201
- Misses 565 615 +50 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add support for parsing
compile_commands.jsonto enable module disambiguation when multiple modules share the same name across different compilation units. This is a feature I wanted to have, prompted Claude Code to implement it and tested it to have the expected behavior.Changes include:
compile_commands.jsonfiles, which extracts include directories (-I), module directories (-J/-module) and preprocessor definitions (-D)-Jflag mapping to group files by compilation unit, enabling correct "go to definition" when the same module name exists in different targetscompile_commands: Custom path tocompile_commands.jsondisable_compile_commands: Opt-out flag for projects that don't want this feature./,build/,builddir/and recursively forcompile_commands.jsonfileInternal changes
obj_treenow stores multiple entries per key (asObjTreeEntrynamedtuples) to support duplicate module namesCloses #512.