Skip to content

Commit

Permalink
Code coverage efficiency improvements and options
Browse files Browse the repository at this point in the history
Also, there's now an option to turn off automatic location list opening
with mess detector/code sniffer violations.
  • Loading branch information
Jon Cairns committed May 11, 2012
1 parent 853aa7d commit 4fd426c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
44 changes: 24 additions & 20 deletions autoload/phpqa.vim
Expand Up @@ -83,27 +83,29 @@ endf

" Run the PHP linter to check for syntax errors
function! phpqa#PhpLint()
if 0 != len(g:phpqa_php_cmd)
let l:bufNo = bufnr('%')
call s:RemoveSigns()
let l:php_output=system(g:phpqa_php_cmd." -l ".@%." 1>/dev/null")
let l:php_list=split(l:php_output, "\n")
if 0 != len(l:php_list)
let l:php_list[0] = "P ".l:php_list[0]
set errorformat=%t\ %m\ in\ %f\ on\ line\ %l
lexpr l:php_list[0]
call s:AddSigns(l:bufNo)
lope
return 1
else
if 1 == g:phpqa_verbose
echohl Error | echo "No syntax errors" | echohl None
if &filetype == "php"
if 0 != len(g:phpqa_php_cmd)
let l:bufNo = bufnr('%')
call s:RemoveSigns()
let l:php_output=system(g:phpqa_php_cmd." -l ".@%." 1>/dev/null")
let l:php_list=split(l:php_output, "\n")
if 0 != len(l:php_list)
let l:php_list[0] = "P ".l:php_list[0]
set errorformat=%t\ %m\ in\ %f\ on\ line\ %l
lexpr l:php_list[0]
call s:AddSigns(l:bufNo)
lope
return 1
else
if 1 == g:phpqa_verbose
echohl Error | echo "No syntax errors" | echohl None
endif
lgete []
lcl
endif
lgete []
lcl
elseif 1 == g:phpqa_verbose
echohl Error | echo "PHP binary set to empty, not running lint" | echohl None
endif
elseif 1 == g:phpqa_verbose
echohl Error | echo "PHP binary set to empty, not running lint" | echohl None
endif
return 0
endfunction
Expand Down Expand Up @@ -177,7 +179,9 @@ function! phpqa#PhpQaTools(runcs,runmd)
set errorformat=%t\ %f:%l:%c:\ %m,%t\ %f:%l\ %m
lgete error_list
call s:AddSigns(l:bufNo)
lope
if g:phpqa_open_loc
lope
endif
else
lgete []
lcl
Expand Down
15 changes: 14 additions & 1 deletion plugin/phpqa.vim
Expand Up @@ -66,6 +66,12 @@ if !exists("g:phpqa_codecoverage_autorun")
let g:phpqa_codecoverage_autorun = 0
endif

" Whether to show signs for covered code (or only not covered)
" It may speed things up to turn this off
if !exists("g:phpqa_codecoverage_showcovered")
let g:phpqa_codecoverage_showcovered = 1
endif

" Whether to automatically run codesniffer when saving a file
if !exists("g:phpqa_codesniffer_autorun")
let g:phpqa_codesniffer_autorun = 1
Expand All @@ -81,6 +87,12 @@ if !exists("g:phpqa_run_on_write")
let g:phpqa_run_on_write = 1
endif

" Whether to open the location list automatically with CodeSniffer/Mess
" detector violations
if !exists("g:phpqa_open_loc")
let g:phpqa_open_loc = 1
endif


" Run all QA tools
function! phpqa:RunAll()
Expand Down Expand Up @@ -108,8 +120,9 @@ endif
nnoremap <unique> <script> <Plug>CodeCoverageToggle <SID>CodeCoverageToggle
nnoremap <silent> <SID>CodeCoverageToggle :call phpqa#CodeCoverageToggle()<cr>
" Run all tools automatically on write
" Run all tools automatically on write and other events
autocmd BufWritePost * call phpqa:RunAll()
autocmd BufRead * call phpqa#PhpLint()
autocmd BufRead * call phpqa:RunCodeCoverage()

" Allow each command to be called individually
Expand Down
20 changes: 18 additions & 2 deletions plugin/python/codecoverage.vim
Expand Up @@ -33,23 +33,39 @@ try:
except NameError:
doc = None

" t0 = time.time() "

if doc is None:
doc = libxml2.parseFile(clover)
mtime = time.ctime(os.path.getmtime(clover))

ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("/coverage/project/file[@name='"+fileName+"']/line[@type='stmt']")
cur_signs = int(vim.eval('g:phpqa_num_cc_signs'))
showcovered = int(vim.eval('g:phpqa_codecoverage_showcovered'))
cmd_list = ''

for node in res:
ctxt.setContextNode(node)
lnum = node.prop('num')
cnt = int(node.prop('count'))
if showcovered == 0 and cnt > 0:
continue
cur_signs += 1
sign = "CodeCoverageCovered" if cnt > 0 else "CodeCoverageNotCovered"
vim.command('let g:phpqa_num_cc_signs = g:phpqa_num_cc_signs + 1')
vim.command('sign place 4783 name='+sign+' line='+lnum+' file='+fileName)
cmd_list += 'exec "sign place 4783 name='+sign+' line='+lnum+' file='+fileName+'" | '

vim.command(cmd_list)
vim.command('let g:phpqa_num_cc_signs='+str(cur_signs))

"""
t = time.time() - t0
print "Completed in "+str(t)+" seconds"
"""

ctxt.xpathFreeContext()


EOF
else
echohl Error | echo "Code coverage support for PHPQA requires Vim compiled with Python" | echohl None
Expand Down

0 comments on commit 4fd426c

Please sign in to comment.