diff --git a/autoload/coverage.vim b/autoload/coverage.vim index 6f04050..705b53e 100644 --- a/autoload/coverage.vim +++ b/autoload/coverage.vim @@ -144,14 +144,23 @@ endfunction function! coverage#GetFormattedStats(filename) abort if has_key(s:cache, a:filename) let l:data = s:cache[a:filename] - let l:stats = {'total': 0} - for l:state in s:coverage_states - let l:stats[l:state] = len(l:data[l:state]) - let l:stats['total'] += len(l:data[l:state]) - endfor - let l:percentage = 100.0 * l:stats.covered / l:stats.total - return printf('Coverage is %.2f%% (%d/%d lines).', - \ l:percentage, l:stats.covered, l:stats.total) + if has_key(l:data, 'stats') + let l:stats = l:data.stats + else + let l:stats = {'total': 0} + for l:state in s:coverage_states + let l:stats[l:state] = len(l:data[l:state]) + let l:stats['total'] += len(l:data[l:state]) + endfor + if has_key(l:data, 'percentage') + let l:stats.percentage = printf('%s%%', l:data.percentage) + else + let l:stats.percentage = printf('%.2f%%', 100.0 * l:stats.covered / l:stats.total) + endif + let l:data['stats'] = l:stats + endif + return printf('Coverage is %s (%d/%d lines (%d partial)).', + \ l:stats.percentage, l:stats.covered, l:stats.total, l:stats.partial) endif endfunction diff --git a/autoload/coverage/python.vim b/autoload/coverage/python.vim index 667ec47..78ee041 100644 --- a/autoload/coverage/python.vim +++ b/autoload/coverage/python.vim @@ -56,8 +56,10 @@ function! coverage#python#GetCoveragePyProvider() abort \ 'vim_coverage.GetCoveragePyLines(%s, %s)', \ string(l:cov_file), \ string(a:filename))) - let [l:covered_lines, l:uncovered_lines] = l:coverage_data - return coverage#CreateReport(l:covered_lines, l:uncovered_lines, []) + let [l:covered_lines, l:uncovered_lines, l:partial_lines, l:percentage] + \ = l:coverage_data + return coverage#CreateReport(l:covered_lines, l:uncovered_lines, l:partial_lines, + \ {'percentage': l:percentage}) endfunction return l:provider diff --git a/python/vim_coverage.py b/python/vim_coverage.py index d7382fb..c43a919 100644 --- a/python/vim_coverage.py +++ b/python/vim_coverage.py @@ -19,7 +19,9 @@ def GetCoveragePyLines(path, source_file): - """Get (covered, uncovered) lines for source_file from .coverage file at path. + """Get coverage information for source_file from .coverage file at path. + + Returns (covered, uncovered, partial, percentage). """ prev_cwd = os.getcwd() source_file = os.path.abspath(source_file) @@ -39,4 +41,10 @@ def GetCoveragePyLines(path, source_file): except TypeError: covered_lines = cov.data.line_data()[source_file] uncovered_lines = cov.analysis(source_file)[2] - return (covered_lines, uncovered_lines) + + analysis = cov._analyze(source_file) + partial = list(analysis.missing_branch_arcs().keys()) + + percentage = analysis.numbers.pc_covered_str + + return (covered_lines, uncovered_lines, partial, percentage) diff --git a/vroom/main.vroom b/vroom/main.vroom index a74a48f..803c063 100644 --- a/vroom/main.vroom +++ b/vroom/main.vroom @@ -35,7 +35,7 @@ a fake coverage provider. :silent edit $VROOMDIR/testdata/dummy.py :CoverageShow test_coverage_provider - ~ Coverage is 50.00% (7/14 lines). + ~ Coverage is 50.00% (7/14 lines (0 partial)). :silent file foo.unrecognized :CoverageShow test_coverage_provider ~ Error rendering coverage: ERROR\(NotFound\): Provider (regex) diff --git a/vroom/python.vroom b/vroom/python.vroom index 179d4c1..d167027 100644 --- a/vroom/python.vroom +++ b/vroom/python.vroom @@ -34,4 +34,4 @@ surface the coverage results inside your vim editor. :call WriteFakeCoveragePyFile(g:tmpdir, {'blah.py': [1, 2, 5]}) :CoverageShow coverage.py - ~ Coverage is 50.00% (3/6 lines). + ~ Coverage is 50% (3/6 lines (1 partial)).