xaizek / uncov (License: AGPLv3+) (since 2018-12-07)
Uncov(er) is a tool that collects and processes code coverage reports.
Commit 46c5ee1b676fcbf500566226e3eea609d7834c6a

Move functions to autoload/
Author: xaizek
Author date (UTC): 2020-01-10 21:10
Committer name: xaizek
Committer date (UTC): 2020-01-10 21:10
Parent(s): f6288b4a26934b92fa93ff2872f687347159681f
Signing key: 99DC5E4DB05F6BE2
Tree: e92fc41dfecca07fb1e0c82fd4d694ab4a38e70d
File Lines added Lines deleted
data/vim/autoload/uncov.vim 1 21
data/vim/plugin/uncov.vim 1 161
File data/vim/autoload/uncov.vim copied from file data/vim/plugin/uncov.vim (similarity 89%) (mode: 100644) (index e8744ba..c72ec43)
6 6
7 7 """""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""
8 8
9 if exists('loaded_uncov')
10 finish
11 endif
12 let loaded_uncov = 1
13
14 augroup Uncov
15 autocmd! ColorScheme *
16 \ highlight UncovCovered ctermbg=darkgreen guibg=darkgreen
17 \| highlight UncovMissed ctermbg=darkred guibg=darkred
18 augroup end
19 doautocmd Uncov ColorScheme
20
21 " mind that text is set to unbreakable space
22 sign define UncovCovered text=  texthl=UncovCovered
23 sign define UncovMissed text=  texthl=UncovMissed
24
25 function! s:ShowCoverage(reload, ...) abort
9 function! uncov#ShowCoverage(reload, ...) abort
26 10 let l:buildid = '@@' let l:buildid = '@@'
27 11 if a:0 > 0 if a:0 > 0
28 12 if a:1 !~ '^@-\?\d\+\|@@$' if a:1 !~ '^@-\?\d\+\|@@$'
 
... ... function! s:PrintCoverageInfo() abort
181 165 echomsg printf('Coverage: %3.2f%% (%d/%d)', 100.0*l:coverage, echomsg printf('Coverage: %3.2f%% (%d/%d)', 100.0*l:coverage,
182 166 \ l:covered, l:relevant) \ l:covered, l:relevant)
183 167 endfunction endfunction
184
185 command! -nargs=? Uncov call s:ShowCoverage(0, <f-args>)
186
187 " vim: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab :
File data/vim/plugin/uncov.vim changed (mode: 100644) (index e8744ba..6792e1a)
... ... doautocmd Uncov ColorScheme
22 22 sign define UncovCovered text=  texthl=UncovCovered sign define UncovCovered text=  texthl=UncovCovered
23 23 sign define UncovMissed text=  texthl=UncovMissed sign define UncovMissed text=  texthl=UncovMissed
24 24
25 function! s:ShowCoverage(reload, ...) abort
26 let l:buildid = '@@'
27 if a:0 > 0
28 if a:1 !~ '^@-\?\d\+\|@@$'
29 echohl ErrorMsg | echo 'Wrong argument:' a:1 | echohl None
30 return
31 endif
32 let l:buildid = a:1
33 endif
34
35 if a:reload
36 let l:repo = b:uncovRepo
37 let l:relFilePath = b:uncovRelFilePath
38 else
39 let l:repo = fugitive#repo()
40 let l:relFilePath = FugitivePath(@%, '')
41 endif
42
43 call s:MakeBuffer(l:repo, l:relFilePath, l:buildid, a:reload)
44 endfunction
45
46 function! s:MakeBuffer(repo, relFilePath, buildid, reload) abort
47 let l:coverageInfo = systemlist('uncov '.a:repo.dir().' get '.a:buildid.' /'
48 \.shellescape(a:relFilePath))
49 if v:shell_error != 0
50 let l:errorMsg = 'uncov error: '.join(l:coverageInfo, '\n')
51 echohl ErrorMsg | echo l:errorMsg | echohl None
52 return
53 endif
54 let l:commit = l:coverageInfo[0]
55
56 let l:gitArgs = ['show', l:commit.':'.a:relFilePath]
57 let l:cmd = call(a:repo.git_command, l:gitArgs, a:repo)
58 let l:fileLines = systemlist(l:cmd)
59 if v:shell_error != 0
60 let l:errorMsg = 'git error: '.join(l:fileLines, '\n')
61 echohl ErrorMsg | echo l:errorMsg | echohl None
62 return
63 endif
64
65 let l:cursPos = getcurpos()
66
67 if a:reload
68 enew
69 else
70 tabedit
71 endif
72
73 let b:uncovRepo = a:repo
74 let b:uncovRelFilePath = a:relFilePath
75
76 let l:coverage = l:coverageInfo[1:]
77 let [l:loclist, b:uncovCovered, b:uncoRelevant] =
78 \ s:ParseCoverage(l:coverage, l:fileLines)
79
80 " XXX: insert buildid here?
81 execute 'silent!' 'file' escape('uncov:'.a:relFilePath, ' \%')
82 call setline(1, l:fileLines)
83 setlocal buftype=nofile bufhidden=wipe noswapfile nomodified nomodifiable
84
85 execute 'doautocmd BufRead' a:relFilePath
86 execute 'doautocmd BufEnter' a:relFilePath
87
88 call cursor(l:cursPos[1:])
89 call setloclist(0, l:loclist)
90 call s:FoldCovered(l:coverage)
91
92 " make sure line under the cursor is not folded
93 silent! normal! zO
94
95 command -buffer UncovInfo call s:PrintCoverageInfo()
96 command -buffer -nargs=? Uncov call s:ShowCoverage(1, <f-args>)
97
98 UncovInfo
99 endfunction
100
101 function! s:ParseCoverage(coverage, fileLines) abort
102 let l:loclist = []
103 let l:bufnr = bufnr('%')
104
105 let l:lineNo = 1
106 let l:relevant = 0
107 let l:covered = 0
108 for l:hits in a:coverage
109 let l:hits = str2nr(l:hits)
110 if l:hits != -1
111 let l:group = (l:hits == 0) ? 'UncovMissed' : 'UncovCovered'
112 execute 'sign place' l:lineNo
113 \ 'line='.l:lineNo
114 \ 'name='.l:group
115 \ 'buffer='.l:bufnr
116 if l:hits == 0
117 let l:loclist += [{
118 \ 'bufnr': l:bufnr,
119 \ 'lnum': l:lineNo,
120 \ 'text': '(not covered) '.a:fileLines[l:lineNo - 1] }]
121 else
122 let l:covered += 1
123 endif
124 let l:relevant += 1
125 endif
126
127 let l:lineNo += 1
128 endfor
129
130 return [l:loclist, l:covered, l:relevant]
131 endfunction
132
133 function! s:FoldCovered(coverage) abort
134 let l:nLines = line('$')
135
136 let l:lineNo = 1
137 let l:toFold = 0
138 for l:hits in a:coverage
139 if str2nr(l:hits) == 0
140 if l:toFold > 3
141 let l:startContext = (l:toFold == l:lineNo - 1 ? 0 : 1)
142 execute (l:lineNo - (l:toFold - l:startContext)).','
143 \.(l:lineNo - 1 - 1)
144 \.'fold'
145 endif
146
147 let l:toFold = 0
148 else
149 let l:toFold += 1
150 endif
151
152 let l:lineNo += 1
153
154 " handle case when coverage information contains more lines than the
155 " file gracefully by adjusting line number and number of lines to fold
156 " to do not go past the end of the buffer
157 if l:lineNo > l:nLines + 1
158 let l:lineNo -= 1
159 if l:toFold > 0
160 let l:toFold -= 1
161 endif
162 endif
163 endfor
164
165 if l:toFold > 3
166 let l:startContext = (l:toFold == len(a:coverage) ? 0 : 1)
167 execute (l:lineNo - (l:toFold - l:startContext)).','
168 \.(l:lineNo - 1)
169 \.'fold'
170 endif
171 endfunction
172
173 function! s:PrintCoverageInfo() abort
174 " redraw is to avoid message disappearing (see `:help :echo-redraw`)
175 redraw
176
177 let l:covered = b:uncovCovered
178 let l:relevant = b:uncoRelevant
179
180 let l:coverage = l:relevant != 0 ? 1.0*l:covered/l:relevant : 1.0
181 echomsg printf('Coverage: %3.2f%% (%d/%d)', 100.0*l:coverage,
182 \ l:covered, l:relevant)
183 endfunction
184
185 command! -nargs=? Uncov call s:ShowCoverage(0, <f-args>)
25 command! -nargs=? Uncov call uncov#ShowCoverage(0, <f-args>)
186 26
187 27 " vim: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab : " 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/uncov

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

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