Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaelsq/nvim-goc.lua
Go Coverage for Neovim
https://github.com/rafaelsq/nvim-goc.lua
coverage go lua neovim plugin testing
Last synced: 14 days ago
JSON representation
Go Coverage for Neovim
- Host: GitHub
- URL: https://github.com/rafaelsq/nvim-goc.lua
- Owner: rafaelsq
- License: mit
- Created: 2021-08-30T21:51:35.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T14:07:19.000Z (9 months ago)
- Last Synced: 2024-07-31T20:42:36.226Z (3 months ago)
- Topics: coverage, go, lua, neovim, plugin, testing
- Language: Lua
- Homepage:
- Size: 36.1 KB
- Stars: 43
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - rafaelsq/nvim-goc.lua - Highlight your buffer with Golang Code Coverage. (Programming Languages Support / Golang)
README
# nvim-goc.lua
easy go coverage![image](https://user-images.githubusercontent.com/1598854/131515315-6178a680-cad1-4ccb-90e4-c61245f10b67.png)
## Setup
```lua
-- if set, when we switch between buffers, it will not split more than once. It will switch to the existing buffer instead
vim.opt.switchbuf = 'useopen'local goc = require'nvim-goc'
goc.setup({ verticalSplit = false }) -- default to horizontalvim.keymap.set('n', 'gcf', goc.Coverage, {silent=true}) -- run for the whole File
vim.keymap.set('n', 'gct', goc.CoverageFunc, {silent=true}) -- run only for a specific Test unit
vim.keymap.set('n', 'gcc', goc.ClearCoverage, {silent=true}) -- clear coverage highlights-- If you need custom arguments, you can supply an array as in the example below.
-- vim.keymap.set('n', 'gcf', function() goc.Coverage({ "-race", "-count=1" }) end, {silent=true})
-- vim.keymap.set('n', 'gct', function() goc.CoverageFunc({ "-race", "-count=1" }) end, {silent=true})vim.keymap.set('n', ']a', goc.Alternate, {silent=true})
vim.keymap.set('n', '[a', goc.AlternateSplit, {silent=true}) -- set verticalSplit=true for verticalcf = function(testCurrentFunction)
local cb = function(path, index)
if path then-- `xdg-open|open` command performs the same function as double-clicking on the file.
-- change from `xdg-open` to `open` on MacOSx
vim.cmd(":silent exec \"!xdg-open file://" .. path .. "\\\\#file" .. index .. "\"")
end
endif testCurrentFunction then
goc.CoverageFunc(nil, cb, 0)
else
goc.Coverage(nil, cb)
end
end-- If you want to open it in your browser, you can use the commands below.
-- You need to create a callback function to configure which command to use to open the HTML.
-- On Linux, `xdg-open` is generally used, on MacOSx it's just `open`.
vim.keymap.set('n', 'gca', cf, {silent=true})
vim.keymap.set('n', 'gcb', function() cf(true) end, {silent=true})-- default colors
-- vim.api.nvim_set_hl(0, 'GocNormal', {link='Comment'})
-- vim.api.nvim_set_hl(0, 'GocCovered', {link='String'})
-- vim.api.nvim_set_hl(0, 'GocUncovered', {link='Error'})
```