Compare commits
No commits in common. "aaa8acf5a286122ff7ab51aca2ccf98be4317d1b" and "a0df92852a5edead4c83dcd391c13fd65cc401c7" have entirely different histories.
aaa8acf5a2
...
a0df92852a
@ -1,75 +1,27 @@
|
|||||||
function! build#dir(...) abort
|
function! build#dir(dir) abort
|
||||||
if a:0 == 0
|
let l:cwd = getcwd()
|
||||||
" No arguments, find build directories.
|
let $BUILD_DIR = l:cwd.'/'.a:dir
|
||||||
let s:dirs = split(substitute(globpath('.', 'build*'), '\.\/', '', 'g'), '\n')
|
|
||||||
let l:len = len(s:dirs)
|
|
||||||
if l:len == 0
|
|
||||||
echoerr 'no build directories found'
|
|
||||||
elseif l:len == 1
|
|
||||||
" One build directory found, use it.
|
|
||||||
let l:dir = s:dirs[0]
|
|
||||||
unlet s:dirs
|
|
||||||
else
|
|
||||||
" Multiple build directories found, create popup menu to select one.
|
|
||||||
" Set the callback to this function on completion, handled below.
|
|
||||||
call popup_menu(s:dirs, #{
|
|
||||||
\ filter: 'popup_filter_menu',
|
|
||||||
\ callback: 'build#dir',
|
|
||||||
\ })
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if a:0 == 1
|
|
||||||
" Single argument, invoked by :BuildDir.
|
|
||||||
let l:dir = a:1
|
|
||||||
elseif a:0 == 2
|
|
||||||
" Two arguments, called back by popup_menu().
|
|
||||||
let l:dirs = s:dirs
|
|
||||||
unlet s:dirs
|
|
||||||
if a:2 == -1
|
|
||||||
" Selection in popup_menu() was cancelled.
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
let l:dir = l:dirs[a:2 - 1]
|
|
||||||
else
|
|
||||||
echoerr 'build#dir called with too many arguments'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
if exists('l:dir')
|
|
||||||
" Set build directory and restart YouCompleteMe.
|
|
||||||
let $BUILD_DIR = getcwd().'/'.substitute(l:dir, '\/$', '', '')
|
|
||||||
let g:ycm_clangd_args = ['--compile-commands-dir='.$BUILD_DIR]
|
let g:ycm_clangd_args = ['--compile-commands-dir='.$BUILD_DIR]
|
||||||
YcmRestartServer
|
YcmRestartServer
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! build#targets(ArgLead, CmdLine, CursorPos) abort
|
function! build#targets(ArgLead, CmdLine, CursorPos) abort
|
||||||
if !exists('$BUILD_DIR')
|
|
||||||
echoerr 'build directory not set'
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
let l:targets = []
|
let l:targets = []
|
||||||
if filereadable($BUILD_DIR.'/build.ninja')
|
if filereadable($BUILD_DIR.'/build.ninja')
|
||||||
" Ask ninja for the list of targets and prepare for returning.
|
|
||||||
for l:target in split(system('ninja -C '.$BUILD_DIR.' -t targets'), '\n')
|
for l:target in split(system('ninja -C '.$BUILD_DIR.' -t targets'), '\n')
|
||||||
call add(l:targets, substitute(l:target, ':.*$', '', ''))
|
call add(l:targets, substitute(l:target, ':.*$', '', ''))
|
||||||
endfor
|
endfor
|
||||||
elseif filereadable($BUILD_DIR.'/Makefile')
|
elseif filereadable($BUILD_DIR.'/Makefile')
|
||||||
" TODO: Support make, it's much less straight forwards than ninja.
|
" TODO: support make
|
||||||
endif
|
endif
|
||||||
return join(l:targets, "\n")
|
return join(l:targets, "\n")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! build#run(...) abort
|
function! build#run(...) abort
|
||||||
if !exists('$BUILD_DIR')
|
let l:build_dir = substitute($BUILD_DIR, '\/$', '', '')
|
||||||
call echo#error('build directory not set')
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
let l:build_dir = $BUILD_DIR
|
|
||||||
if filereadable($BUILD_DIR.'/build.ninja')
|
if filereadable($BUILD_DIR.'/build.ninja')
|
||||||
" Execute ninja in a terminal window.
|
|
||||||
execute 'terminal ninja -C '.l:build_dir.' '.join(a:000, ' ')
|
execute 'terminal ninja -C '.l:build_dir.' '.join(a:000, ' ')
|
||||||
elseif filereadable($BUILD_DIR.'/Makefile')
|
elseif filereadable($BUILD_DIR.'/Makefile')
|
||||||
" Execute make in a terminal window.
|
|
||||||
execute 'terminal make -C '.l:build_dir.' '.join(a:000, ' ')
|
execute 'terminal make -C '.l:build_dir.' '.join(a:000, ' ')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
function! echo#warning(message) abort
|
|
||||||
echohl WarningMsg
|
|
||||||
echomsg a:message
|
|
||||||
echohl None
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! echo#error(message) abort
|
|
||||||
echohl ErrorMsg
|
|
||||||
echomsg a:message
|
|
||||||
echohl None
|
|
||||||
endfunction
|
|
@ -31,5 +31,5 @@ command! -nargs=+ -complete=file Debug call do#debug(<f-args>)
|
|||||||
command! TodoFile lvimgrep /todo/ %
|
command! TodoFile lvimgrep /todo/ %
|
||||||
|
|
||||||
" Change build directory
|
" Change build directory
|
||||||
command! -nargs=? -complete=dir BuildDir call build#dir(<f-args>)
|
command! -nargs=1 -complete=dir BuildDir call build#dir(<f-args>)
|
||||||
command! -nargs=* -complete=custom,build#targets Build call build#run(<f-args>)
|
command! -nargs=* -complete=custom,build#targets Build call build#run(<f-args>)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user