Compare commits

...

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
014c959fee Improve comment clarity in FindCompileCommands
Co-authored-by: w0rp <3518142+w0rp@users.noreply.github.com>
2026-02-12 00:25:08 +00:00
copilot-swe-agent[bot]
520c775c6a Fix FindCompileCommands to handle absolute paths in c_build_dir_names
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>
2026-02-12 00:24:39 +00:00
copilot-swe-agent[bot]
7f79d30fb9 Initial plan 2026-02-12 00:20:49 +00:00
2 changed files with 43 additions and 2 deletions

View File

@@ -249,11 +249,19 @@ function! ale#c#FindCompileCommands(buffer) abort
" Search in build directories if we can't find it in the project.
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:dirname in ale#Var(a:buffer, 'c_build_dir_names')
let l:c_build_dir = l:path . s:sep . l:dirname
let l:c_build_dir = ale#path#GetAbsPath(l:path, l:dirname)
let l:json_file = l:c_build_dir . s:sep . 'compile_commands.json'
if filereadable(l:json_file)
return [l:path, l:json_file]
" For absolute build dir paths, use the parent
" of the build dir as the project root. For
" relative paths, use the directory found by
" searching upwards from the file.
let l:root = ale#path#IsAbsolute(l:dirname)
\ ? fnamemodify(l:c_build_dir, ':h')
\ : l:path
return [l:root, l:json_file]
endif
endfor
endfor

View File

@@ -0,0 +1,33 @@
Before:
Save g:ale_c_build_dir_names
call ale#test#SetDirectory('/testplugin/test')
After:
Restore
call ale#test#RestoreDirectory()
Execute(FindCompileCommands should find compile_commands.json with relative build dir names):
call ale#test#SetFilename('test-files/c/json_project/subdir/dummy')
let g:ale_c_build_dir_names = ['build']
AssertEqual
\ [
\ ale#path#Simplify(g:dir . '/test-files/c/json_project'),
\ ale#path#Simplify(g:dir . '/test-files/c/json_project/build/compile_commands.json'),
\ ],
\ ale#c#FindCompileCommands(bufnr(''))
Execute(FindCompileCommands should find compile_commands.json with absolute build dir names):
call ale#test#SetFilename('test-files/c/json_project/subdir/dummy')
let g:ale_c_build_dir_names = [ale#path#Simplify(g:dir . '/test-files/c/json_project/build')]
AssertEqual
\ [
\ ale#path#Simplify(g:dir . '/test-files/c/json_project'),
\ ale#path#Simplify(g:dir . '/test-files/c/json_project/build/compile_commands.json'),
\ ],
\ ale#c#FindCompileCommands(bufnr(''))