diff --git a/autoload/build.vim b/autoload/build.vim index b7d7c8c..1402136 100644 --- a/autoload/build.vim +++ b/autoload/build.vim @@ -4,3 +4,24 @@ function! build#dir(dir) abort let g:ycm_clangd_args = ['--compile-commands-dir='.$BUILD_DIR] YcmRestartServer endfunction + +function! build#targets(ArgLead, CmdLine, CursorPos) abort + let l:targets = [] + if filereadable($BUILD_DIR.'/build.ninja') + for l:target in split(system('ninja -C '.$BUILD_DIR.' -t targets'), '\n') + call add(l:targets, substitute(l:target, ':.*$', '', '')) + endfor + elseif filereadable($BUILD_DIR.'/Makefile') + " TODO: support make + endif + return join(l:targets, "\n") +endfunction + +function! build#run(...) abort + let l:build_dir = substitute($BUILD_DIR, '\/$', '', '') + if filereadable($BUILD_DIR.'/build.ninja') + execute 'terminal ninja -C '.l:build_dir.' '.join(a:000, ' ') + elseif filereadable($BUILD_DIR.'/Makefile') + execute 'terminal make -C '.l:build_dir.' '.join(a:000, ' ') + endif +endfunction diff --git a/plugin/commands.vim b/plugin/commands.vim index 53e4561..ae009cc 100644 --- a/plugin/commands.vim +++ b/plugin/commands.vim @@ -32,3 +32,4 @@ command! TodoFile lvimgrep /todo/ % " Change build directory command! -nargs=1 -complete=dir BuildDir call build#dir() +command! -nargs=* -complete=custom,build#targets Build call build#run()