Skip to content

Commit

Permalink
Try to fix coverage and deprecation warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyachur committed Feb 19, 2024
1 parent 8580ecc commit 2fd8bec
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
12 changes: 3 additions & 9 deletions autoload/cmake4vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,11 @@ function! cmake4vim#init() abort

" Optional variable allow to specify the build executor
" Possible values: 'job', 'dispatch', 'system', 'term', ''
let g:cmake_build_executor = get(g:, 'cmake_build_executor' , '')
let g:cmake_build_executor = get(g:, 'cmake_build_executor' , '')

" Possible values: sp - horizontal mode, vsp - vertical mode
let g:cmake_build_executor_split_mode = get(g:, 'cmake_build_executor_split_mode', 'sp')
if exists('g:cmake_build_executor_height') && g:cmake_build_executor_height !=# '' && !exists('g:cmake_build_executor_window_size')
call utils#common#Warning('g:cmake_cxx_compiler option is deprecated and will be removed at the April of 2024 year!' .
\ ' Please use `let g:cmake_build_executor_window_size=<size>` instead.')
let g:cmake_build_executor_window_size = g:cmake_build_executor_height
else
let g:cmake_build_executor_window_size = get(g:, 'cmake_build_executor_window_size', 10)
endif
let g:cmake_build_executor_split_mode = get(g:, 'cmake_build_executor_split_mode' , 'sp')
let g:cmake_build_executor_window_size = get(g:, 'cmake_build_executor_window_size', 10)

" Build path
let g:cmake_build_path_pattern = get(g:, 'cmake_build_path_pattern' , '' )
Expand Down
10 changes: 10 additions & 0 deletions autoload/utils/common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ function! utils#common#Warning(msg) abort
\ echomsg a:msg |
\ echohl None
endfunction

" Resolve deprecated variables
function! utils#common#getWindowSize() abort
if exists('g:cmake_build_executor_height') && g:cmake_build_executor_height !=# ''
call utils#common#Warning('g:cmake_build_executor_height option is deprecated and will be removed at the April of 2024 year!' .
\ ' Please use `let g:cmake_build_executor_window_size=<size>` instead.')
let g:cmake_build_executor_window_size = g:cmake_build_executor_height
endif
return g:cmake_build_executor_window_size
endfunction
12 changes: 6 additions & 6 deletions autoload/utils/exec/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ function! s:vimClose(channel) abort
call s:createQuickFix()

if l:open_qf == 0
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
else
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
cbottom
endfunction
Expand Down Expand Up @@ -106,7 +106,7 @@ function! s:nVimExit(job_id, data, event) abort
endif
call s:createQuickFix()
if a:data != 0 || l:open_qf != 0
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
endfunction

Expand All @@ -117,10 +117,10 @@ function! s:createJobBuf() abort
" qflist is open somewhere
if !empty(filter(range(1, winnr('$')), 'getwinvar(v:val, "&ft") ==# "qf"'))
" move the cursor there
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
silent execute 'keepalt edit ' . s:cmake4vim_buf
else
silent execute printf('keepalt botright %d %s %s', g:cmake_build_executor_window_size, g:cmake_build_executor_split_mode, s:cmake4vim_buf)
silent execute printf('keepalt botright %d %s %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode, s:cmake4vim_buf)
endif
setlocal bufhidden=hide buftype=nofile buflisted nolist
setlocal noswapfile nowrap nomodifiable
Expand Down Expand Up @@ -149,7 +149,7 @@ function! utils#exec#job#stop() abort
endif
let s:cmake4vim_jobs_pool = []
call s:createQuickFix()
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
call utils#common#Warning('Job is cancelled!')
endfunction

Expand Down
2 changes: 1 addition & 1 deletion autoload/utils/exec/system.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function! utils#exec#system#run(cmd, open_qf, errFormat) abort
cgetexpr l:s_out
call setqflist( [], 'a', { 'title' : a:cmd } )
if a:open_qf == 1 || l:ret_code != 0
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
if !empty(a:errFormat)
let &l:errorformat = l:old_error
Expand Down
18 changes: 11 additions & 7 deletions autoload/utils/exec/term.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function! s:vimClose(channel, status) abort
call s:createQuickFix()

if l:open_qf == 0
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
else
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
cbottom

Expand Down Expand Up @@ -86,7 +86,7 @@ function! s:nVimExit(job_id, data, event) abort
call s:createQuickFix()

if a:data != 0 || l:open_qf != 0
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', g:cmake_build_executor_window_size)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
if a:data == 0
silent echon 'Success! ' . l:cmd
Expand Down Expand Up @@ -118,7 +118,7 @@ function! utils#exec#term#run(cmd, open_qf, cwd, err_fmt) abort
\ 'err_fmt': a:err_fmt
\ }
if has('nvim')
execute g:cmake_build_executor_window_size . g:cmake_build_executor_split_mode
execute utils#common#getWindowSize() . g:cmake_build_executor_split_mode
execute 'enew'
let l:job = termopen(a:cmd, {
\ 'on_stdout': function('s:nVimOut'),
Expand All @@ -130,18 +130,22 @@ function! utils#exec#term#run(cmd, open_qf, cwd, err_fmt) abort
let l:termbufnr = bufnr()
else
let l:cmd = has('win32') ? a:cmd : [&shell, '-c', a:cmd]
silent execute printf('keepalt botright %d %s', g:cmake_build_executor_window_size, g:cmake_build_executor_split_mode)
let l:job = term_start(l:cmd, {
silent execute printf('keepalt botright %d %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode)
let l:options = {
\ 'term_name': l:cmake4vim_term,
\ 'exit_cb': function('s:vimClose'),
\ 'out_cb': function('s:vimOut'),
\ 'term_finish': 'close',
\ g:cmake_build_executor_split_mode ==# 'sp' ? 'term_rows' : 'term_cols': utils#common#getWindowSize(),
\ 'out_modifiable' : 0,
\ 'err_modifiable' : 0,
\ 'norestore': 1,
\ 'curwin': 1,
\ 'cwd': a:cwd
\ })
\ }
call utils#common#Warning(l:options)
call utils#common#Warning(g:cmake_build_executor_height)
let l:job = term_start(l:cmd, l:options)
endif
if has('nvim')
let s:cmake4vim_term['termbuf'] = l:termbufnr
Expand Down
2 changes: 1 addition & 1 deletion autoload/utils/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function! utils#window#OpenCMakeInfoWindow() abort
let wcmd = s:cmake_info_win_name
let s:cmake_info_prev_win_id = winnr()

silent execute printf('botright %d %s %s', g:cmake_build_executor_window_size, g:cmake_build_executor_split_mode, wcmd)
silent execute printf('botright %d %s %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode, wcmd)
endfunction

function! utils#window#GotoCMakeInfoWindow() abort
Expand Down
6 changes: 6 additions & 0 deletions test/tests/basic/generate_cmake_project.vader
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ Execute ([CMake generate] Create incorrect folder):
Assert !isdirectory("custom-folder"), "Build directory shouldn't exist"
call utils#fs#makeDir('custom-folder')
Assert !isdirectory("custom-folder"), "Build directory shouldn't exist"

Execute ([CMake generate] Verify deprecated warning):
let g:cmake_build_executor_height = 10
Assert !isdirectory("cmake-build-Release"), "Build directory shouldn't exist"
silent CMake
Assert filereadable("cmake-build-Release/CMakeCache.txt"), "CMakeCache.txt should be generated"
2 changes: 2 additions & 0 deletions test/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function! ResetPluginOptions()
let g:cmake_selected_kit = ''
let g:cmake_kits = {}
let g:cmake_kits_global_path = ''
let g:cmake_build_executor_height = ''
let g:cmake_build_executor_window_size = 10

let g:cmake_vimspector_default_configuration = {
\ 'adapter': '',
Expand Down

0 comments on commit 2fd8bec

Please sign in to comment.