Displays coverage information in the sign column.
Displays a coverage summary report in a pop-up window.
Currently supports:
- C/C++ (lcov)
- C# (lcov - see wiki for details)
- Dart (lcov)
- Go (coverprofile)
- Javascript/Typescript (lcov): jest
- Julia (lcov): Pkg.jl
- Python (json): coverage.py
- Ruby (json): SimpleCov
- Rust (json): grcov
- Swift (json)
- PHP (cobertura)
- Lua (lcov)
- Anything that generates lcov files
Branch (partial) coverage support:
| Language | Supported |
|---|---|
| C/C++ | ❌ |
| C# | ❌ |
| Dart | ✔️ (untested) |
| Go | ❌ |
| Javascript/Typescript | ✔️ |
| Julia | ✔️ (untested) |
| Python | ✔️ |
| Ruby | ❌ |
| Rust | ❌ |
| Swift | ❌ |
| PHP | ❌ |
| Lua | ❌ |
Note: This plugin does not run tests. It justs loads/displays a coverage report generated by a test suite. To run tests from neovim with coverage enabled, try one of these plugins:
This plugin depends on plenary and optionally on the lua-xmlreader luarock to parse the cobertura format.
Using vim-plug (not including the luarock dependency):
Plug 'nvim-lua/plenary.nvim'
Plug 'andythigpen/nvim-coverage'The following lua is required to configure the plugin after installation.
require("coverage").setup()Using packer:
use({
"andythigpen/nvim-coverage",
requires="nvim-lua/plenary.nvim",
-- Optional: needed for PHP when using the cobertura parserrocks= { 'lua-xmlreader' },
config=function()
require("coverage").setup()
end,
})Using lazyvim:
{
"andythigpen/nvim-coverage",
version="*",
config=function()
require("coverage").setup({
auto_reload=true,
})
end,
},See docs for more info.
Example:
require("coverage").setup({
commands=true, -- create commandshighlights= {
-- customize highlight groups created by the plugincovered= { fg="#C3E88D" }, -- supports style, fg, bg, sp (see :h highlight-gui)uncovered= { fg="#F07178" },
},
signs= {
-- use your own highlight groups or text markerscovered= { hl="CoverageCovered", text="▎" },
uncovered= { hl="CoverageUncovered", text="▎" },
},
summary= {
-- customize the summary pop-upmin_coverage=80.0, -- minimum coverage threshold (used for highlighting)
},
lang= {
-- customize language specific settings
},
})- Create a new lua module matching the pattern
coverage.languages.<filetype>where<filetype>matches the vim filetype for the coverage language (ex. python). - Implement the required methods listed below.
Required methods:
localM= {}
--- Loads a coverage report.-- This method should perform whatever steps are necessary to generate a coverage report.-- The coverage report results should passed to the callback, which will be cached by the plugin.-- @param callback called with results of the coverage reportM.load=function(callback)
-- TODO: callback(results)end--- Returns a list of signs that will be placed in buffers.-- This method should use the coverage data (previously generated via the load method) to -- return a list of signs.-- @return list of signsM.sign_list=function(data)
-- TODO: generate a list of signs using:-- require("coverage.signs").new_covered(bufnr, linenr)-- require("coverage.signs").new_uncovered(bufnr, linenr)end--- Returns a summary report.-- @return summary reportM.summary=function(data)
-- TODO: generate a summary report in the formatreturn {
files= {
{ -- all fields, except filename, are optional - the report will be blank if the field is nilfilename=fname, -- filename displayed in the reportstatements=statements, -- number of total statements in the filemissing=missing, -- number of lines missing coverage (uncovered) in the fileexcluded=excluded, -- number of lines excluded from coverage reporting in the filebranches=branches, -- number of total branches in the filepartial=partial_branches, -- number of branches that are partially covered in the filecoverage=coverage, -- coverage percentage (float) for this file
}
},
totals= { -- optionalstatements=total_statements, -- number of total statements in the reportmissing=total_missing, -- number of lines missing coverage (uncovered) in the reportexcluded=total_excluded, -- number of lines excluded from coverage reporting in the reportbranches=total_branches, -- number of total branches in the reportpartial=total_partial_branches, -- number of branches that are partially covered in the reportcoverage=total_coverage, -- coverage percentage to display in the report
}
}
endreturnM
