27
27
if ! exists (' s:coverage_states' )
28
28
let s: coverage_states = [' covered' , ' uncovered' , ' partial' ]
29
29
endif
30
+ let s: highlights_defined = 0
30
31
31
32
" }}}
32
33
@@ -46,17 +47,15 @@ endfunction
46
47
" Defines highlighting rules for coverage colors and defines text signs for each
47
48
" coverage state, as defined via plugin flags. See |coverage-config|.
48
49
function ! s: DefineHighlighting () abort
49
- if ! hlexists (' coverage_covered' )
50
- for l: state in s: coverage_states
51
- execute ' highlight coverage_' . l: state .
50
+ for l: state in s: coverage_states
51
+ execute ' highlight coverage_' . l: state .
52
52
\ ' ctermbg=' . s: plugin .Flag (l: state . ' _ctermbg' ) .
53
53
\ ' ctermfg=' . s: plugin .Flag (l: state . ' _ctermfg' ) .
54
54
\ ' guibg=' . s: plugin .Flag (l: state . ' _guibg' ) .
55
55
\ ' guifg=' . s: plugin .Flag (l: state . ' _guifg' )
56
- execute ' sign define sign_' . l: state . ' text=' .
56
+ execute ' sign define sign_' . l: state . ' text=' .
57
57
\ s: plugin .Flag (l: state . ' _text' ) . ' texthl=coverage_' . l: state
58
- endfor
59
- endif
58
+ endfor
60
59
endfunction
61
60
62
61
@@ -67,7 +66,9 @@ endfunction
67
66
" @default show_stats=1
68
67
function ! s: RenderFromCache (filename, ... ) abort
69
68
let l: show_stats = maktaba#ensure#IsBool (get (a: , 1 , 1 ))
70
- call s: DefineHighlighting ()
69
+ if ! s: highlights_defined
70
+ call s: DefineHighlighting ()
71
+ endif
71
72
if (has_key (s: cache , a: filename ))
72
73
let l: data = s: cache [a: filename ]
73
74
for l: state in s: coverage_states
@@ -314,4 +315,12 @@ function! coverage#EnsureProvider(provider) abort
314
315
endif
315
316
endfunction
316
317
318
+
319
+ " "
320
+ " Re-define highlights after the colorscheme was changed.
321
+ augroup coverage_highlights
322
+ au !
323
+ autocmd ColorScheme * if s: defined_highlights | call s: DefineHighlighting () | endif
324
+ augroup END
325
+
317
326
" }}}
0 commit comments