Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge compile commands #1

Closed
wants to merge 14 commits into from
Closed

Merge compile commands #1

wants to merge 14 commits into from

Conversation

yiftahw
Copy link
Owner

@yiftahw yiftahw commented Oct 23, 2024

Abstract

Usage

define the following entries in .vscode/settings.json:

// already implemented
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/merged_compile_commands.json",
// new
"C_Cpp.mergeCompileCommands": { 
"sources": [
        "${workspaceFolder}/build/proj1/compile_commands.json",
        "${workspaceFolder}/build/proj2/compile_commands.json",
    ],
    "destination": "${workspaceFolder}/build/merged_compile_commands.json"
},
  • NOTE: "C_Cpp.default.compileCommands" is not changed (to a list) for backwards compatibility.

Why are glob patterns not supported here?

  • the CMake Tools extension supports glob patterns without consuming heavy CPU resources as it only tries to recursively search for compile_commands.json files when a build is finished succesfully. (one time per build process)
  • the C/C++ extension doesn't know when a build is started (or finished), it will need to recursively monitor files constantly.
    • can create a non-negligible and persistent CPU load if directories contain many files.
    • will trigger many false positive events.

Error Handling

  • files defined in "sources" don't exist
    • how would we notify the user? (should we?)
    • there are currently no squiggles in settings.json
    • logs in C++ Configuration Errors are used exclusively by the native language server
    • error popups seems excessive for this kind of error
  • cannot create the destination folder/file (permissions, invalid path)
    • error popup seems ok in this scenario
  • compile_commands.json can't be parsed
    • error popup seems ok in this scenario

State Machine

stateDiagram-v2 
[*] --> load : settings.json loaded/changed
load : close file watchers<br>load configuration
check_dst: check if destination file exists
load --> check_dst
create : merge compile commands
check_srcs : check if any of the sources<br>is newer than dst
check_dst --> check_srcs : true
check_dst --> create : false
missingbank : periodically check if missing files are created
filewatchers : create source file watchers
check_srcs --> filewatchers: false
check_srcs --> create : true
missingbank --> filewatchers : file created
filewatchers --> missingbank : error<br>file missing
filewatchers --> create : source file changed
filewatchers --> check_dst : error<br>file watcher limit hit
create --> filewatchers : Success
create --> [*] : Error
Loading

TODO:

  • implement periodic file watchers on non-existant files
  • finalize error handling/user notifications scheme
  • some validation in settings.ts in getMergeCompileCommands()
  • add tests
  • remove console.log() prints

@yiftahw yiftahw closed this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple compile commands files per project
1 participant