google / vim-coverage

Apache License 2.0
101 stars 22 forks source link

vim-coverage is a utility for visualizing test coverage results in vim. vim-coverage relies on maktaba for registration and management of coverage providing plugins.

For details, see the helpfiles in the doc/ directory. The helpfiles are also available via :help vim-coverage if vim-coverage is installed (and helptags have been generated).

Commands

Use :CoverageShow to show file coverage for the current buffer. Use :CoverageToggle to toggle coverage visibility for the current file.

Installation

This example uses Vundle, whose plugin-adding command is Plugin.

" Add maktaba and coverage to the runtimepath.
" (The latter must be installed before it can be used.)
Plugin 'google/vim-maktaba'
Plugin 'google/vim-coverage'
" Also add Glaive, which is used to configure coverage's maktaba flags. See
" `:help :Glaive` for usage.
Plugin 'google/vim-glaive'
call glaive#Install()
" Optional: Enable coverage's default mappings on the <Leader>C prefix.
Glaive coverage plugin[mappings]

Make sure you have updated maktaba recently. Older versions had an issue detecting installed libraries.

Using coverage providers

The easiest way to see the list of available providers is via tab completion: Type :CoverageShow <TAB> in vim.

To use a particular provider, type :CoverageShow PROVIDER-NAME. This will either show coverage in the current buffer using the selected provider or show an error message if provider is not available. Normally you will trigger providers via key mappings and/or autocommand hooks.

vim-coverage currently defines several coverage providers:

  1. A coverage.py provider for python.
  2. A covimerage provider for vimscript.
  3. A gcov provider for gcov, which handles lcov tracefiles.

See https://github.com/google/vim-coverage/issues for other planned integrations.

Coverage offers a lot of customization on colors and signs rendered for covered and uncovered lines. You can get a quick view of all coverage flags by executing :Glaive coverage, or start typing flag names and use tab completion. See :help Glaive for usage details.

Defining custom providers

Any plugin wishing to be a coverage provider needs only to register itself using Maktaba's registry feature, passing a dictionary of following format:

Example:

let s:registry = maktaba#extension#GetRegistry('coverage')
call s:registry.AddExtension({
    \ 'name': 'my_provider',
    \ 'GetCoverage': function('myplugin#GetCoverage'),
    \ 'GetCoverageAsync': function('myplugin#GetCoverageAsync'),
    \ 'IsAvailable': function('myplugin#IsAvailable')})