Skip to content

Fix FindCompileCommands to handle absolute paths in c_build_dir_names#5096

Open
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-ale-compile-commands-path
Open

Fix FindCompileCommands to handle absolute paths in c_build_dir_names#5096
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-ale-compile-commands-path

Conversation

Copy link

Copilot AI commented Feb 12, 2026

ale#c#FindCompileCommands fails to locate compile_commands.json when g:ale_c_build_dir_names contains absolute paths, because it unconditionally joins the build dir name onto the search path (producing e.g. /repo//repo/BUILD_CMAKE/L031).

Changes

  • Absolute path support: Replace l:path . s:sep . l:dirname with ale#path#GetAbsPath(l:path, l:dirname), which returns the path as-is when it's already absolute
  • Correct project root for absolute dirs: When the build dir is absolute, use its parent as the project root instead of the upward-search path
  • Defensive ale#Set for test stability: Add ale#Set('c_build_dir_names', ...) inside FindCompileCommands to ensure the variable survives Vader Save/Restore cycles — mirrors the existing s:CanParseMakefile pattern
  • Tests: Add test_c_find_compile_commands.vader covering both relative and absolute c_build_dir_names
" Before — breaks with absolute paths
let l:c_build_dir = l:path . s:sep . l:dirname

" After — handles both relative and absolute
let l:c_build_dir = ale#path#GetAbsPath(l:path, l:dirname)
Original 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#FindCompileCommands failed to find compile_commands.json despite the location being provided in c_build_dir_names.

Reproducing the bug

My build set-up puts compile_commands.json in a path that is typically BUILD_CMAKE\platform where platform varies depending on the microcontroller in use for that specific project. To get ALE to find it, I added this to after/ftplugin/c.vim:

let cmake_build = []
for path in glob(g:repository_root .. '/BUILD*', v:false, v:true)
	if isdirectory(path)
		let cmake_build += [path]
	endif
endfor
for path in glob(g:repository_root .. '/BUILD*/*', v:false, v:true)
	if isdirectory(path)
		let cmake_build += [path]
	endif
endfor

let g:ale_c_build_dir_names = cmake_build

(where g:repository_root is the root of the VCS repository)

That results in:

echo g:ale_c_build_dir_names
> ['c:\path\to\repo\BUILD_CMAKE', 'c:\path\to\repo\BUILD_CMAKE\L031']

With those absolute paths, ALE cannot find the compile_commands.json. I think it is because, on this line of c.vim, it is appending the build dir to another path (so probably ending up with something like c:\path\to\repo\c:\path\to\repo\BUILD_CMAKE\L031).

I've implemented a work-around for now by changing:

let cmake_build += [path]

to:

let cmake_build += [fnamemodify(path, ":~:.")]

That fixes the issue and results in:

echo g:ale_c_build_dir_names
['BUILD_CMAKE', 'BUILD_CMAKE\L031']

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.

Copilot AI and others added 2 commits February 12, 2026 00:24
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
Copilot AI requested a review from w0rp February 12, 2026 00:25
@w0rp w0rp marked this pull request as ready for review February 17, 2026 20:17
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>
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.

ALE can't locate compile_commands.json with absolute paths in c_build_dir_names

2 participants