Fix FindCompileCommands to handle absolute paths in c_build_dir_names#5096
Open
Fix FindCompileCommands to handle absolute paths in c_build_dir_names#5096
Conversation
Use ale#path#GetAbsPath to resolve build directory paths, which correctly handles both absolute and relative paths. When the dirname is absolute, derive the project root from the parent of the build directory. Co-authored-by: w0rp <3518142+w0rp@users.noreply.github.com>
Co-authored-by: w0rp <3518142+w0rp@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ALE unable to locate compile_commands.json
Fix FindCompileCommands to handle absolute paths in c_build_dir_names
Feb 12, 2026
Mirror the existing s:CanParseMakefile pattern to ensure the g:ale_c_build_dir_names variable always exists when ale#Var is called, even if test Save/Restore cycles delete it. Co-authored-by: w0rp <3518142+w0rp@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ale#c#FindCompileCommandsfails to locatecompile_commands.jsonwheng:ale_c_build_dir_namescontains absolute paths, because it unconditionally joins the build dir name onto the search path (producing e.g./repo//repo/BUILD_CMAKE/L031).Changes
l:path . s:sep . l:dirnamewithale#path#GetAbsPath(l:path, l:dirname), which returns the path as-is when it's already absoluteale#Setfor test stability: Addale#Set('c_build_dir_names', ...)insideFindCompileCommandsto ensure the variable survives VaderSave/Restorecycles — mirrors the existings:CanParseMakefilepatterntest_c_find_compile_commands.vadercovering both relative and absolutec_build_dir_namesOriginal prompt
This section details on the original issue you should resolve
<issue_title>ALE can't locate compile_commands.json with absolute paths in c_build_dir_names</issue_title>
<issue_description>## Information
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 6 2023 13:20:20)
MS-Windows 64-bit GUI/console version with OLE support
Included patches 1-2092
Operating System: Windows 11
What went wrong
ale#c#FindCompileCommandsfailed to findcompile_commands.jsondespite the location being provided inc_build_dir_names.Reproducing the bug
My build set-up puts
compile_commands.jsonin a path that is typicallyBUILD_CMAKE\platformwhere platform varies depending on the microcontroller in use for that specific project. To get ALE to find it, I added this toafter/ftplugin/c.vim:(where g:repository_root is the root of the VCS repository)
That results in:
With those absolute paths, ALE cannot find the
compile_commands.json. I think it is because, on this line ofc.vim, it is appending the build dir to another path (so probably ending up with something likec:\path\to\repo\c:\path\to\repo\BUILD_CMAKE\L031).I've implemented a work-around for now by changing:
to:
That fixes the issue and results in:
However, it would be nice if ALE could cope with absolute paths - it took me a long time to figure out why it wasn't working with gcc, especially since cppcheck does work with the absolute path.
:ALEInfo
Current Filetype: cpp
Available Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Linter Aliases:
'cc' -> ['gcc', 'clang', 'g++', 'clang++']
Enabled Linters: ['cc', 'ccls', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'cspell', 'flawfinder']
Ignored Linters: []
Suggested Fixers:
'astyle' - Fix C/C++ with astyle.
'clang-format' - Fix C, C++, C#, CUDA, Java, JavaScript, JSON, ObjectiveC and Protobuf files with clang-format.
'clangtidy' - Fix C/C++ and ObjectiveC files with clang-tidy.
'remove_trailing_lines' - Remove all blank lines at the end of a file.
'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
'uncrustify' - Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.
Linter Variables:
" Press Space to read :help for a setting
let g:ale_cpp_cc_executable = ''
let g:ale_cpp_cc_header_exts = ['h', 'hpp']
let g:ale_cpp_cc_options = '-std=c++14 -Wall'
let g:ale_cpp_cc_use_header_lang_flag = -1
let g:ale_cpp_ccls_executable = 'ccls'
let g:ale_cpp_ccls_init_options = {}
let g:ale_cpp_clangcheck_executable = 'clang-check'
let g:ale_cpp_clangcheck_options = ''
let g:ale_cpp_clangd_executable = 'clangd'
let g:ale_cpp_clangd_options = ''
let g:ale_cpp_clangtidy_checks = []
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_cpp_clangtidy_extra_options = ''
let g:ale_cpp_clangtidy_options = ''
let g:ale_cpp_clazy_checks = ['level1']
let g:ale_cpp_clazy_executable = 'clazy-standalone'
let g:ale_cpp_clazy_options = ''
let g:ale_cpp_cppcheck_executable = 'C:\Program Files\Cppcheck Premium\cppcheck.exe'
let g:ale_cpp_cppcheck_options = '--enable=style --premium=misra-c++-2023 --premium=misra-c-2025:all'
let g:ale_cpp_cpplint_executable = 'cpplint'
let g:ale_cpp_cpplint_options = ''
let g:ale_cpp_cquery_cache_directory = 'c:\cygwin\home\al.cache\cquery'
let g:ale_cpp_cquery_executable = 'cquery'
let g:ale_cpp_flawfinder_executable = 'flawfinder'
let g:ale_cpp_flawfinder_minlevel = 1
let g:ale_cpp_flawfinder_options = ''
Global Variables:
" Press Space to read :help for a setting
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:false
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = v:false
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 'auto'
let g:ale_echo_cursor = v:true
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%linter% says %s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = v:false
let g:ale_fixers = {}
let g:ale_his...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.