xaizek / dotvim (License: Unspecified) (since 2018-12-07)
Vim configuration and plugins.
Commit 2004945111073d039eb7c91dc0a64f247463ab0f

Add optional uncov plugin
Author: xaizek
Author date (UTC): 2020-06-18 17:32
Committer name: xaizek
Committer date (UTC): 2020-06-18 17:32
Parent(s): 5d7d86cbbbe57b54c1dd2d1ba30070d934cdbf68
Signing key: 99DC5E4DB05F6BE2
Tree: 2c5f0cc24668c312c2560754ab18e0fbe85d52a2
File Lines added Lines deleted
after/pack/shadows/start/shadowed-plugins/plugin/uncov.vim 3 0
pack/apps/opt/uncov/autoload/uncov.vim 187 0
pack/apps/opt/uncov/doc/uncov.txt 57 0
pack/apps/opt/uncov/plugin/uncov.vim 16 0
File after/pack/shadows/start/shadowed-plugins/plugin/uncov.vim added (mode: 100644) (index 0000000..4042844)
1 if !exists('g:loaded_uncov')
2 packadd uncov
3 endif
File pack/apps/opt/uncov/autoload/uncov.vim added (mode: 100644) (index 0000000..8bc3fe8)
1 " Vim plugin for querying coverage information from uncov command-line tool.
2
3 " Maintainer: xaizek <xaizek@posteo.net>
4 " Last Change: 2020 April 24
5 " License: Same terms as Vim itself (see `help license`)
6
7 """"""""""""""""""""""""""""""""""""""""""""""""""""""""
8
9 let s:initialized = 0
10
11 function! uncov#ShowCoverage(reload, ...) abort
12 if !s:initialized
13 let s:initialized = 1
14 call s:Initialize()
15 endif
16
17 let l:buildid = '@@'
18 if a:0 > 0
19 if a:1 !~ '^@-\?\d\+\|@@$'
20 echohl ErrorMsg | echo 'Wrong argument:' a:1 | echohl None
21 return
22 endif
23 let l:buildid = a:1
24 endif
25
26 if a:reload
27 let l:repo = b:uncovRepo
28 let l:relFilePath = b:uncovRelFilePath
29 else
30 let l:repo = fugitive#repo()
31 let l:relFilePath = FugitivePath(@%, '')
32 endif
33
34 call s:MakeBuffer(l:repo, l:relFilePath, l:buildid, a:reload)
35 endfunction
36
37 function! s:Initialize()
38 augroup Uncov
39 autocmd! ColorScheme *
40 \ highlight UncovCovered ctermbg=darkgreen guibg=darkgreen
41 \| highlight UncovMissed ctermbg=darkred guibg=darkred
42 augroup end
43 doautocmd Uncov ColorScheme
44
45 " mind that text is set to unbreakable space
46 sign define UncovCovered text=  texthl=UncovCovered
47 sign define UncovMissed text=  texthl=UncovMissed
48 endfunction
49
50 function! s:MakeBuffer(repo, relFilePath, buildid, reload) abort
51 let l:coverageInfo = systemlist('uncov '.a:repo.dir().' get '.a:buildid.' /'
52 \.shellescape(a:relFilePath))
53 if v:shell_error != 0
54 let l:errorMsg = 'uncov error: '.join(l:coverageInfo, '\n')
55 echohl ErrorMsg | echo l:errorMsg | echohl None
56 return
57 endif
58 let l:commit = l:coverageInfo[0]
59
60 let l:gitArgs = ['show', l:commit.':'.a:relFilePath]
61 let l:cmd = call(a:repo.git_command, l:gitArgs, a:repo)
62 let l:fileLines = systemlist(l:cmd)
63 if v:shell_error != 0
64 let l:errorMsg = 'git error: '.join(l:fileLines, '\n')
65 echohl ErrorMsg | echo l:errorMsg | echohl None
66 return
67 endif
68
69 let l:cursPos = getcurpos()
70
71 if a:reload
72 enew
73 else
74 tabedit
75 endif
76
77 let b:uncovRepo = a:repo
78 let b:uncovRelFilePath = a:relFilePath
79
80 let l:coverage = l:coverageInfo[1:]
81 let [l:loclist, b:uncovCovered, b:uncoRelevant] =
82 \ s:ParseCoverage(l:coverage, l:fileLines)
83
84 " XXX: insert buildid here?
85 execute 'silent!' 'file' escape('uncov:'.a:relFilePath, ' \%')
86 call setline(1, l:fileLines)
87 setlocal buftype=nofile bufhidden=wipe noswapfile nomodified nomodifiable
88
89 execute 'doautocmd BufRead' a:relFilePath
90 execute 'doautocmd BufEnter' a:relFilePath
91
92 call cursor(l:cursPos[1:])
93 call setloclist(0, l:loclist)
94 call s:FoldCovered(l:coverage)
95
96 " make sure line under the cursor is not folded
97 silent! normal! zO
98
99 command -buffer UncovInfo call s:PrintCoverageInfo()
100 command -buffer -nargs=? Uncov call uncov#ShowCoverage(1, <f-args>)
101
102 UncovInfo
103 endfunction
104
105 function! s:ParseCoverage(coverage, fileLines) abort
106 let l:loclist = []
107 let l:bufnr = bufnr('%')
108
109 let l:lineNo = 1
110 let l:relevant = 0
111 let l:covered = 0
112 for l:hits in a:coverage
113 let l:hits = str2nr(l:hits)
114 if l:hits != -1
115 let l:group = (l:hits == 0) ? 'UncovMissed' : 'UncovCovered'
116 execute 'sign place' l:lineNo
117 \ 'line='.l:lineNo
118 \ 'name='.l:group
119 \ 'buffer='.l:bufnr
120 if l:hits == 0
121 let l:loclist += [{
122 \ 'bufnr': l:bufnr,
123 \ 'lnum': l:lineNo,
124 \ 'text': '(not covered) '.a:fileLines[l:lineNo - 1] }]
125 else
126 let l:covered += 1
127 endif
128 let l:relevant += 1
129 endif
130
131 let l:lineNo += 1
132 endfor
133
134 return [l:loclist, l:covered, l:relevant]
135 endfunction
136
137 function! s:FoldCovered(coverage) abort
138 let l:nLines = line('$')
139
140 let l:lineNo = 1
141 let l:toFold = 0
142 for l:hits in a:coverage
143 if str2nr(l:hits) == 0
144 if l:toFold > 3
145 let l:startContext = (l:toFold == l:lineNo - 1 ? 0 : 1)
146 execute (l:lineNo - (l:toFold - l:startContext)).','
147 \.(l:lineNo - 1 - 1)
148 \.'fold'
149 endif
150
151 let l:toFold = 0
152 else
153 let l:toFold += 1
154 endif
155
156 let l:lineNo += 1
157
158 " handle case when coverage information contains more lines than the
159 " file gracefully by adjusting line number and number of lines to fold
160 " to do not go past the end of the buffer
161 if l:lineNo > l:nLines + 1
162 let l:lineNo -= 1
163 if l:toFold > 0
164 let l:toFold -= 1
165 endif
166 endif
167 endfor
168
169 if l:toFold > 3
170 let l:startContext = (l:toFold == len(a:coverage) ? 0 : 1)
171 execute (l:lineNo - (l:toFold - l:startContext)).','
172 \.(l:lineNo - 1)
173 \.'fold'
174 endif
175 endfunction
176
177 function! s:PrintCoverageInfo() abort
178 " redraw is to avoid message disappearing (see `:help :echo-redraw`)
179 redraw
180
181 let l:covered = b:uncovCovered
182 let l:relevant = b:uncoRelevant
183
184 let l:coverage = l:relevant != 0 ? 1.0*l:covered/l:relevant : 1.0
185 echomsg printf('Coverage: %3.2f%% (%d/%d)', 100.0*l:coverage,
186 \ l:covered, l:relevant)
187 endfunction
File pack/apps/opt/uncov/doc/uncov.txt added (mode: 100644) (index 0000000..b21f7c0)
1 *uncov.txt* For Vim version 7.4 Last change: 2017 May 09
2
3
4 uncov plugin documentation
5
6
7 uncov plugin *uncov*
8
9 1. Prerequisites................................|uncov-prerequisites|
10 2. Description..................................|uncov-description|
11 3. Usage........................................|uncov-usage|
12
13 Author: xaizek <xaizek@posteo.net>
14 License: Same terms as Vim itself (see |license|)
15
16 ==============================================================================
17 1. Prerequisites *uncov-prerequisites*
18
19 Vim-fugitive plugin by Tim Pope:
20
21 https://github.com/tpope/vim-fugitive.git
22
23 This dependency can be removed in future versions.
24
25 ==============================================================================
26 2. Description *uncov-description*
27
28 This plugin provides integration with uncov command-line tool. It helps to
29 view latest coverage information about currently opened file easily.
30
31 The plugin opens a separate tab page with contents current file had at the
32 moment of coverage collection. The buffer in that tab:
33
34 * has sign column set to show covered and missed lines;
35 * has location list filled with list of uncovered lines;
36 * has folds set on ranges that are covered;
37 * has cursor set near its position in the original buffer;
38 * displays file coverage information on command-line (once).
39
40 ==============================================================================
41 3. Usage *uncov-usage*
42
43 :Uncov [buildid] *uncov-:Uncov* *:Uncov*
44
45 In non-uncov buffer, loads coverage of current file in a buffer of a new tab
46 page. When already in uncov buffer, reloads coverage of a file in current
47 buffer, but possibly from a different build.
48
49 Without argument latest build (@@) is used.
50
51 :UncovInfo *uncov-:UncovInfo* *:UncovInfo*
52
53 Loads coverage of current file in a buffer of a new tab page.
54 The command is local to buffers created by this plugin.
55
56 ------------------------------------------------------------------------------
57 vim:tw=78:ts=8:ft=help:norl:
File pack/apps/opt/uncov/plugin/uncov.vim added (mode: 100644) (index 0000000..8aa5c2d)
1 " Vim plugin for querying coverage information from uncov command-line tool.
2
3 " Maintainer: xaizek <xaizek@posteo.net>
4 " Last Change: 2020 January 10
5 " License: Same terms as Vim itself (see `help license`)
6
7 """"""""""""""""""""""""""""""""""""""""""""""""""""""""
8
9 if exists('loaded_uncov')
10 finish
11 endif
12 let loaded_uncov = 1
13
14 command! -nargs=? Uncov call uncov#ShowCoverage(0, <f-args>)
15
16 " vim: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab :
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/dotvim

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/dotvim

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master