feat(docker): add Linux LSP support by fixing compile_commands.json paths#2303
feat(docker): add Linux LSP support by fixing compile_commands.json paths#2303abhatem wants to merge 1 commit intoTheSuperHackers:mainfrom
Conversation
Greptile Overview
|
| Filename | Overview |
|---|---|
| scripts/docker-build.sh | Added fix_compile_commands() function to automatically fix compile_commands.json paths after build, with proper error handling |
| scripts/fix_compile_commands.py | New Python script to transform Docker container paths to host paths for LSP support; logic works but replacement order could be more robust |
Sequence Diagram
sequenceDiagram
participant User
participant docker-build.sh
participant Docker Container
participant fix_compile_commands.py
participant Host Filesystem
User->>docker-build.sh: Execute build script
docker-build.sh->>Docker Container: Run build in container
Docker Container->>Host Filesystem: Generate compile_commands.json<br/>(with container paths /build/cnc)
docker-build.sh->>fix_compile_commands.py: Run post-build fix script
fix_compile_commands.py->>Host Filesystem: Read compile_commands.json<br/>from build/docker/
fix_compile_commands.py->>fix_compile_commands.py: Transform paths:<br/>- /build/cnc → host path<br/>- backslashes → forward slashes<br/>- strip Wine drive letters
fix_compile_commands.py->>Host Filesystem: Write fixed compile_commands.json<br/>to project root
docker-build.sh->>User: Build complete, LSP ready
Last reviewed commit: db5cdaf
| #!/usr/bin/env python3 | ||
| """ | ||
| Compile commands fixer for Linux development. | ||
| This script makes the compile_commands.json generated by the Docker build | ||
| usable on the Linux host by: | ||
| - Rewriting container paths (/build/cnc) to host absolute paths. | ||
| - Converting Windows backslashes to forward slashes. | ||
| - Stripping Wine drive letters (Z:). | ||
| """ |
There was a problem hiding this comment.
Missing copyright header. Since this is a newly created community file, add:
| #!/usr/bin/env python3 | |
| """ | |
| Compile commands fixer for Linux development. | |
| This script makes the compile_commands.json generated by the Docker build | |
| usable on the Linux host by: | |
| - Rewriting container paths (/build/cnc) to host absolute paths. | |
| - Converting Windows backslashes to forward slashes. | |
| - Stripping Wine drive letters (Z:). | |
| """ | |
| #!/usr/bin/env python3 | |
| # Copyright 2026 TheSuperHackers | |
| # | |
| # This file is part of Command & Conquer: Generals and Command & Conquer: Zero Hour. | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
| """ | |
| Compile commands fixer for Linux development. | |
| This script makes the compile_commands.json generated by the Docker build | |
| usable on the Linux host by: | |
| - Rewriting container paths (/build/cnc) to host absolute paths. | |
| - Converting Windows backslashes to forward slashes. | |
| - Stripping Wine drive letters (Z:). | |
| """ |
Context Used: Rule from dashboard - Only flag missing GPL license headers in file prologues. Do not comment about missing or incomplete ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/fix_compile_commands.py
Line: 1:10
Comment:
Missing copyright header. Since this is a newly created community file, add:
```suggestion
#!/usr/bin/env python3
# Copyright 2026 TheSuperHackers
#
# This file is part of Command & Conquer: Generals and Command & Conquer: Zero Hour.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Compile commands fixer for Linux development.
This script makes the compile_commands.json generated by the Docker build
usable on the Linux host by:
- Rewriting container paths (/build/cnc) to host absolute paths.
- Converting Windows backslashes to forward slashes.
- Stripping Wine drive letters (Z:).
"""
```
**Context Used:** Rule from `dashboard` - Only flag missing GPL license headers in file prologues. Do not comment about missing or incomplete ... ([source](https://app.greptile.com/review/custom-context?memory=1cd6ffcb-aeb0-457d-899f-184a39b97b1e))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
scripts/fix_compile_commands.py
Outdated
| import json | ||
| import os | ||
| import sys | ||
| import re |
There was a problem hiding this comment.
Unused import re - not used anywhere in the code
| import re |
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/fix_compile_commands.py
Line: 15:15
Comment:
Unused import `re` - not used anywhere in the code
```suggestion
```
How can I resolve this? If you propose a fix, please make it concise.926ec90 to
2b2e052
Compare
scripts/fix_compile_commands.py
Outdated
| # Handle paths that might start with just \build\cnc (from Windows context) | ||
| if path.startswith('/'): | ||
| # Already handled or unrelated absolute path | ||
| pass | ||
|
|
There was a problem hiding this comment.
Dead code - the if path.startswith('/') block only contains a pass statement and always returns the unmodified path at line 49. This doesn't affect functionality but is unnecessary.
| # Handle paths that might start with just \build\cnc (from Windows context) | |
| if path.startswith('/'): | |
| # Already handled or unrelated absolute path | |
| pass | |
| # Replace the container mount point with the host root directory | |
| # The container mounts the project at /build/cnc | |
| if path.startswith('/build/cnc'): | |
| return os.path.join(root_dir, path[len('/build/cnc'):].lstrip('/')) | |
| return path |
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/fix_compile_commands.py
Line: 44:48
Comment:
Dead code - the `if path.startswith('/')` block only contains a `pass` statement and always returns the unmodified `path` at line 49. This doesn't affect functionality but is unnecessary.
```suggestion
# Replace the container mount point with the host root directory
# The container mounts the project at /build/cnc
if path.startswith('/build/cnc'):
return os.path.join(root_dir, path[len('/build/cnc'):].lstrip('/'))
return path
```
How can I resolve this? If you propose a fix, please make it concise.2b2e052 to
1aacdc5
Compare
….json Added scripts/fix_compile_commands.py to rewrite container paths to host paths and updated scripts/docker-build.sh to automatically run it after build.
1aacdc5 to
db5cdaf
Compare
Summary
This PR improves the development experience for Linux contributors by making the
compile_commands.jsongenerated inside the Docker container usable on the host machine.Problem
Currently, when building with
docker-build.sh, the generatedcompile_commands.jsoncontains:/build/cnc/...instead of the host's workspace path.\which confuse Linux LSP servers (like clangd/ccls).Z:references from Wine.This causes "Go to Definition" and other LSP features to fail in Linux editors (VS Code, Emacs, Neovim) because they cannot locate the source files.
Solution
scripts/fix_compile_commands.py: A Python script that:scripts/docker-build.sh: Automatically runs the fix script after a successful build ifpython3is detected.Testing
docker-build.shstill compiles the game successfully.compile_commands.jsonis generated and paths are correctly mapped to the host.Notes
scripts/fix_compile_commands.pywas mostly AI generated but human verified and tested