Last active
August 25, 2025 16:37
-
-
Save boeckhoff/81ecee276b27a5ab88d82f9481f6b461 to your computer and use it in GitHub Desktop.
painfully inefficient AI generated python script as extra build step to fix file clangd windows filename issue in vscode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DOESNT WORK, FIX ON THE WAY | |
| Steps: | |
| - create python script | |
| - add tasks to tasks.json | |
| - add to all build tasks: "dependsOn": ["fix-compile-commands"] | |
| untested, AI generated, slow and ugly but works for me. | |
| clangd, please fix this and prevent me from making horrible workarounds like these <3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import json | |
| import os | |
| import sys | |
| def normalize_drive_letter(path: str) -> str: | |
| # Only relevant on Windows paths like C:\... | |
| if len(path) >= 2 and path[1] == ":" and path[0].isalpha(): | |
| return path[0].lower() + path[1:] | |
| return path | |
| def main(): | |
| file = "compile_commands.json" | |
| if len(sys.argv) > 1: | |
| file = sys.argv[1] | |
| if not os.path.exists(file): | |
| print(f"File not found: {file}") | |
| sys.exit(1) | |
| with open(file, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| changed = False | |
| for entry in data: | |
| for key in ("file", "directory", "command"): | |
| if key in entry: | |
| new_value = normalize_drive_letter(entry[key]) | |
| if new_value != entry[key]: | |
| entry[key] = new_value | |
| changed = True | |
| if changed: | |
| with open(file, "w", encoding="utf-8") as f: | |
| json.dump(data, f, indent=2) | |
| print(f"Normalized drive letters in {file}") | |
| else: | |
| print(f"No changes needed in {file}") | |
| if __name__ == "__main__": | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // Fix necessary due to https://github.com/clangd/vscode-clangd/issues/687? | |
| "label": "fix-compile-commands", | |
| "type": "shell", | |
| "command": "python", | |
| "args": [ | |
| "${workspaceFolder}\\YOUR_SCRIPT_PATH\\normalize_compile_commands.py", | |
| "${workspaceFolder}\\YOUR_COMPILE_COMMANDS_PATH\\compile_commands.json" | |
| ], | |
| "problemMatcher": [] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment