" File: py-coverage-highlight.vim " Author: Marius Gedminas " Version: 0.4 " Last Modified: 2010-01-09 " " Overview " -------- " Vim script to higlight coverage report results. " " Installation " ------------ " Copy this file to $HOME/.vim/plugin directory " " Usage with Ned Batchelder's coverage.py " --------------------------------------- " Produce a coverage report with coverage (it's assumed that you use " zc.buildout and the coverage script is ./bin/coverage relative to the " current working directory). Open a source file. Use :HiglightCoverage " to load coverage info, and :HiglightCoverageOff to turn it off. " " Usage with Python's trace.py " ---------------------------- " Produce a coverage report with Python's trace.py. Open a source file. " Load the highlighting with :HiglightCoverage filename/to/coverage.report " Turn off the highlighting with :HiglightCoverageOff or :sign unplace * if !has("python") finish endif hi NoCoverage ctermbg=gray guibg=#ffcccc hi SignColumn guibg=white ctermbg=NONE sign define NoCoverage text=>> texthl=NoCoverage linehl=NoCoverage function! HiglightCoverage(filename) sign unplace * python <>>>>>'): signs.place(lineno) def parse_coverage_output(output, filename): # Example output: # Name Stmts Exec Cover Missing # ----------------------------------------------------------- # src/foo/bar/baz/qq/__init__ 146 136 93% 170-177, 180-184 last_line = output.splitlines()[-1] filename = os.path.relpath(filename) filename_no_ext = os.path.splitext(filename)[0] signs = Signs() if last_line.startswith(filename_no_ext + ' '): print last_line last_line = last_line[len(filename_no_ext) + 1:].lstrip() columns = last_line.split(None, 3) if len(columns) > 3: parse_lines(columns[3], signs) else: print "Got confused by %s" % repr(last_line) print "Expected it to start with %s" % repr(filename_no_ext + ' ') print "Full output:" print output def parse_lines(formatted_list, signs): for item in formatted_list.split(', '): if '-' in item: lo, hi = item.split('-') else: lo = hi = item lo, hi = int(lo), int(hi) for lineno in range(lo, hi+1): signs.place(lineno) filename = vim.eval('a:filename') if filename: parse_cover_file(filename) else: filename = vim.eval('bufname("%")') if os.path.exists('.coverage') and os.path.exists('bin/coverage'): print "Running bin/coverage -rm", filename output = subprocess.Popen(['bin/coverage', '-rm', filename], stdout=subprocess.PIPE).communicate()[0] parse_coverage_output(output, filename) else: modulename = filename2module(filename) filename = find_coverage_report(modulename) print "Using", filename parse_cover_file(filename) END endf command! -nargs=? -complete=file -bar HiglightCoverage call HiglightCoverage() command! HiglightCoverageOff sign unplace *