Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: c.vim: Pull build directory from compilation database #2191

Merged
merged 1 commit into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions autoload/ale/c.vim
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ function! s:GetLookupFromCompileCommandsFile(compile_commands_file) abort
return l:empty
endfunction

function! ale#c#ParseCompileCommandsFlags(buffer, dir, file_lookup, dir_lookup) abort
function! ale#c#ParseCompileCommandsFlags(buffer, file_lookup, dir_lookup) abort
" Search for an exact file match first.
let l:basename = tolower(expand('#' . a:buffer . ':t'))
let l:file_list = get(a:file_lookup, l:basename, [])

for l:item in l:file_list
if bufnr(l:item.file) is a:buffer
return ale#c#ParseCFlags(a:dir, l:item.command)
return ale#c#ParseCFlags(l:item.directory, l:item.command)
endif
endfor

Expand All @@ -219,20 +219,19 @@ function! ale#c#ParseCompileCommandsFlags(buffer, dir, file_lookup, dir_lookup)

for l:item in l:dir_list
if ale#path#Simplify(fnamemodify(l:item.file, ':h')) is? l:dir
return ale#c#ParseCFlags(a:dir, l:item.command)
return ale#c#ParseCFlags(l:item.directory, l:item.command)
endif
endfor

return ''
endfunction

function! ale#c#FlagsFromCompileCommands(buffer, compile_commands_file) abort
let l:dir = ale#path#Dirname(a:compile_commands_file)
let l:lookups = s:GetLookupFromCompileCommandsFile(a:compile_commands_file)
let l:file_lookup = l:lookups[0]
let l:dir_lookup = l:lookups[1]

return ale#c#ParseCompileCommandsFlags(a:buffer, l:dir, l:file_lookup, l:dir_lookup)
return ale#c#ParseCompileCommandsFlags(a:buffer, l:file_lookup, l:dir_lookup)
endfunction

function! ale#c#GetCFlags(buffer, output) abort
Expand Down
6 changes: 3 additions & 3 deletions test/test_c_flag_parsing.vader
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ Execute(FlagsFromCompileCommands should tolerate empty values):
AssertEqual '', ale#c#FlagsFromCompileCommands(bufnr(''), '')

Execute(ParseCompileCommandsFlags should tolerate empty values):
AssertEqual '', ale#c#ParseCompileCommandsFlags(bufnr(''), '', {}, {})
AssertEqual '', ale#c#ParseCompileCommandsFlags(bufnr(''), {}, {})

Execute(ParseCompileCommandsFlags should parse some basic flags):
noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'))

AssertEqual
\ '-I' . ale#path#Simplify('/usr/include/xmms2'),
\ ale#c#ParseCompileCommandsFlags(bufnr(''), ale#path#Simplify('/foo/bar/xmms2-mpris'), { "xmms2-mpris.c": [
\ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [
\ {
\ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
\ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2')
Expand All @@ -183,7 +183,7 @@ Execute(ParseCompileCommandsFlags should fall back to files in the same director

AssertEqual
\ '-I' . ale#path#Simplify('/usr/include/xmms2'),
\ ale#c#ParseCompileCommandsFlags(bufnr(''), ale#path#Simplify('/foo/bar/xmms2-mpris'), {}, { "src": [
\ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [
\ {
\ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'),
\ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2')
Expand Down