mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-14 22:21:52 +08:00
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>
This commit is contained in:
@@ -249,11 +249,18 @@ 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]
|
||||
" Use the parent of the build dir for absolute
|
||||
" paths, otherwise use the path 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
|
||||
|
||||
Reference in New Issue
Block a user