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

Add python 3 support #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion plugin/Phpqa.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ if 0 == has("signs")
endif

let $CUR_DIRECTORY=expand("<sfile>:p:h")
source $CUR_DIRECTORY/python/codecoverage.vim
if 1 == has('python3')
source $CUR_DIRECTORY/python/codecoverage_py3.vim
else
if 1 == has('python')
source $CUR_DIRECTORY/python/codecoverage.vim
endif
endif

let g:phpqa_check = 1

Expand Down
70 changes: 70 additions & 0 deletions plugin/python/codecoverage_py3.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function! AddCodeCoverageSigns(clover)
if has('python3')
python3 << EOF
import lxml.etree
import vim
import os.path
import time

global doc
global mtime

try:
mtime
except NameError:
mtime = 0

clover = vim.eval('a:clover')
buf = vim.eval('bufname("%")')
fileName = vim.eval('fnamemodify("'+buf+'","%")')

"""
XML may already be parsed and held in memory
Check the file modification time, and only re-parse
if it's been modified.
"""
try:
try:
doc
if doc != None:
cmtime = time.ctime(os.path.getmtime(clover))
if cmtime > mtime:
doc = None
except NameError:
doc = None

" t0 = time.time() "

if doc is None:
doc = lxml.etree.parse(clover)
mtime = time.ctime(os.path.getmtime(clover))

#ctxt = doc.xpathNewContext()
#res = ctxt.xpathEval("//file[substring(@name, string-length(@name) - string-length('"+fileName+"') + 1)='"+fileName+"']/line[@type='stmt']")
res = doc.xpath("//file[substring(@name, string-length(@name) - string-length('"+fileName+"') + 1)='"+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:
lnum = node.attrib['num']
cnt = int(node.attrib['count'])
if showcovered == 0 and cnt > 0:
continue
cur_signs += 1
sign = "CodeCoverageCovered" if cnt > 0 else "CodeCoverageNotCovered"
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))

except os.error:
vim.command('echohl Error | echo "Missing or inaccessible code coverage file" | echohl None')
except Exception as e:
vim.command('echohl Error | echo "An error has occured while parsing the code coverage file" | echohl None')

EOF
else
echohl Error | echo "Code coverage support for PHPQA requires Vim with Python3" | echohl None
endif
endfunction