Git Product home page Git Product logo

vim-coverage's Introduction

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:

  • IsAvailable(filename) - return 1 if plugin can handle the current file, otherwise 0.
  • GetCoverage(filename) - returns the coverage dict created by coverage#CreateReport that contains all coverage data.
  • name - the name of the provider.
  • optional: GetCoverageAsync(filename, callback) - gets the coverage and once done, invokes the provided callback with the coverage dict created by coverage#CreateReport that contains all coverage data.

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')})

vim-coverage's People

Contributors

alexhaxe avatar andreich avatar blueyed avatar dbarnett avatar kouk avatar malcolmr avatar okkays avatar pall-valmundsson avatar snu5mumr1k avatar stgpetrovic avatar xanderman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-coverage's Issues

Error showing coverage on modified buffer after :make

I wrote a plugin for Codecov JSON format (see https://github.com/AlexHaxe/vim-codecovjson)
and it works fine until I recompile my project (https://github.com/HaxeCheckstyle/haxe-checkstyle), generating new coverage data. Unchanged files still work, but the files that have changed show an error message:

Error detected while processing function coverage#Toggle..<SNR>216_CoverageToggle..<SNR>216_CoverageShow..<SNR>216_RenderFromCache..<SNR>216_ColorSigns:
line    2:
E158: Invalid buffer name: src/checkstyle/token/TokenTreeBuilder.hx

Error when reading .coverage file

Error detected while processing function coverage#Show[9]..function coverage#Show[5]..<SNR>75_CoverageShow[9]..coverage#ShowCoverage[45]..4[13]..maktaba#python#Eval:
line    6:
Traceback (most recent call last):
  File "/usr/lib64/python3.7/site-packages/coverage/data.py", line 293, in read_file
    self.read_fileobj(f)
  File "/usr/lib64/python3.7/site-packages/coverage/data.py", line 271, in read_fileobj
    data = self._read_raw_data(file_obj)
  File "/usr/lib64/python3.7/site-packages/coverage/data.py", line 311, in _read_raw_data
    go_away = file_obj.read(len(cls._GO_AWAY))
  File "/usr/lib64/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 99: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/fedora/.vim/plugged/vim-coverage/python/vim_coverage.py", line 33, in GetCoveragePyLines
    cov.load()
  File "/usr/lib64/python3.7/site-packages/coverage/control.py", line 677, in load
    self.data_files.read(self.data)
  File "/usr/lib64/python3.7/site-packages/coverage/data.py", line 653, in read
    data.read_file(self.filename)
  File "/usr/lib64/python3.7/site-packages/coverage/data.py", line 297, in read_file
    filename, exc.__class__.__name__, exc,
coverage.misc.CoverageException: Couldn't read data from '/home/fedora/Desktop/GIT/tinydb/.coverage': UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position 99: invalid continu
ation byte
E858: Eval did not return a valid python object

lib version

attrs==20.1.0
coverage==5.2.1
importlib-metadata==1.7.0
iniconfig==1.0.1
more-itertools==8.4.0
packaging==20.4
pluggy==0.13.1
py==1.9.0
pyparsing==2.4.7
pytest==6.0.1
pytest-cov==2.10.1
six==1.15.0
toml==0.10.1
zipp==3.1.0

Add commands & keymappings for jumping to the next uncovered line

Feature request: This plugin should define commands and keymappings for jumping to the next uncovered and/or partially-covered line so that navigating a coverage-annotated file becomes easier. The vim-signjump plugin is related prior art, but I believe that combining it with vim-coverage would just lead to jumping between each & every line of code.

Mechanism to watch & dynamically reload coverage results

After doing :CoverageShow, could you have vim watch whatever .coverage file it loaded results from and immediately notice and reload results if that changes? For example, if you run nosetests --with-coverage outside of vim and that generates new coverage results for the current file, could the plugin immediately discard the stale results and show the fresh ones?

Note we already have #27 to have a manual way to reload coverage, like :CoverageShow!.

Support rendering coverage results generated from older versions of a file

For some projects and coverage tools, coverage is expensive to evaluate and it's useful to be able to show coverage data from an older snapshot.

There's some complexity to getting this kind of snapshotted coverage functionality to work well since line numbers won't match up if there have been significant modifications to the file since, and there may need to be a way to show a diff of the modifications.

Reload coverage information / refresh cache

It does not seem to be possible currently to update already loaded coverage information currently, is it?

Maybe related to #19 ?!

I've thought about adding bang support to CoverageShow, so that CoverageShow! would refresh the cache.

What do you think?

Mechanism to invoke "bazel coverage" and show the results

For working on bazel projects, it would be great to have a simple way to show coverage results generated from bazel coverage (see https://docs.bazel.build/versions/master/command-line-reference.html#coverage and https://blog.bazel.build/2018/10/29/bazel-0.19.0.html#code-coverage).

A gcov coverage provider (#6) gets us part of the way there, but the wiring gets a little complicated for how to easily…

  1. Invoke the right bazel coverage command
  2. Clue vim-coverage in to where to find for the output files
  3. Show the coverage results on the buffer

@okkays

Does Python coverage require a Vim with Python support?

I'm having trouble getting this plugin to work with a Python project on my MacBook, and I'm wondering if it may be due to it requiring a version of Vim that was built with Python support, which the pre-supplied Vim on macOS lacks. Is this the case? The documentation doesn't mention that. If it is the case, would it be reasonable to add support for non-integrated Pythons?

Provide diagnostic command for troubleshooting

We should define a command like :CoverageInfo or :CoverageDebug to show info to help users troubleshoot, e.g.: is coverage visible, what provider was used, what providers are available, are coverage stats against the current version or an older version…

Add "show if available" variant to be used in autocmds

We should document an autocmd a user can define to show coverage on certain paths as soon as they're opened, without seeing an error or warning about missing coverage (particularly in the async case). Currently there's no obvious way to get that behavior reliably.

The coverage plugin will need to document some clear contract for what .GetCoverage should throw/return and what .GetCoverageAsync should do to signal coverage was not found, and use that to surface error information to the user consistently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.