Skip to content

Commit 3000144

Browse files
committed
Toggle banner without repainting buffer
1 parent fe8658e commit 3000144

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

autoload/OmniSharp/testrunner.vim

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function! OmniSharp#testrunner#Remove() abort
114114
let test = s:utils.findTest()
115115
let test.state = 'hidden'
116116
endif
117-
call s:Paint()
117+
call s:buffer.paint()
118118
endfunction
119119

120120

@@ -207,40 +207,44 @@ function s:Open() abort
207207
let s:runner.bufnr = bufnr()
208208
let &filetype = ft
209209
execute 'file' title
210-
call s:Paint()
210+
call s:buffer.paint()
211211
endfunction
212212

213-
function! s:Repaint() abort
213+
214+
let s:buffer = {}
215+
function! s:buffer.focus() abort
214216
if !has_key(s:runner, 'bufnr') | return | endif
215217
if getbufvar(s:runner.bufnr, '&ft') !=# 'omnisharptest' | return | endif
216218
" If the buffer is listed in a window in the current tab, then focus it
217219
for winnr in range(1, winnr('$'))
218220
if winbufnr(winnr) == s:runner.bufnr
219-
let l:winid = win_getid()
220221
call win_gotoid(win_getid(winnr))
221-
break
222+
return v:true
222223
endif
223224
endfor
224-
call s:Paint()
225-
if exists('l:winid')
226-
call win_gotoid(l:winid)
227-
endif
225+
return v:false
228226
endfunction
229227

230-
function! s:Paint() abort
228+
function! s:buffer.bannerlines() abort
231229
let lines = []
232230
let delimiter = get(g:, 'OmniSharp_testrunner_banner_delimeter', '')
231+
call add(lines, '`' . repeat(delimiter, 80))
232+
call add(lines, '` OmniSharp Test Runner')
233+
call add(lines, '` ' . repeat(delimiter, 76))
234+
call add(lines, '` <F1> Toggle this menu (:help omnisharp-test-runner for more)')
235+
call add(lines, '` <F5> Run test or tests in file under cursor')
236+
call add(lines, '` <F6> Debug test under cursor')
237+
call add(lines, '` <CR> Navigate to test or stack trace')
238+
call add(lines, '`' . repeat(delimiter, 80))
239+
return lines
240+
endfunction
241+
242+
function! s:buffer.paint() abort
233243
if get(g:, 'OmniSharp_testrunner_banner', 1)
234-
call add(lines, repeat(delimiter, 80))
235-
call add(lines, ' OmniSharp Test Runner')
236-
call add(lines, ' ' . repeat(delimiter, 76))
237-
call add(lines, ' <F1> Toggle this menu (:help omnisharp-test-runner for more)')
238-
call add(lines, ' <F5> Run test or tests in file under cursor')
239-
call add(lines, ' <F6> Debug test under cursor')
240-
call add(lines, ' <CR> Navigate to test or stack trace')
241-
call add(lines, repeat(delimiter, 80))
244+
let lines = self.bannerlines()
245+
else
246+
let lines = []
242247
endif
243-
244248
for key in sort(keys(s:tests))
245249
let [assembly, sln] = split(key, ';')
246250
if !s:tests[key].visible | continue | endif
@@ -400,7 +404,12 @@ function! s:UpdateState(bufnr, state, ...) abort
400404
let tests[testname].output = get(opts, 'output', [])
401405
endif
402406
endfor
403-
call s:Repaint()
407+
let l:winid = win_getid()
408+
let l:focused = s:buffer.focus()
409+
call s:buffer.paint()
410+
if l:focused
411+
call win_gotoid(l:winid)
412+
endif
404413
endfunction
405414

406415
function! OmniSharp#testrunner#StateComplete(location) abort
@@ -436,7 +445,17 @@ endfunction
436445

437446
function! OmniSharp#testrunner#ToggleBanner() abort
438447
let g:OmniSharp_testrunner_banner = 1 - get(g:, 'OmniSharp_testrunner_banner', 1)
439-
call s:Paint()
448+
if s:buffer.focus()
449+
let displayed = getline(1) =~# '`'
450+
call setbufvar(s:runner.bufnr, '&modifiable', 1)
451+
if g:OmniSharp_testrunner_banner && !displayed
452+
call appendbufline(s:runner.bufnr, 0, s:buffer.bannerlines())
453+
elseif !g:OmniSharp_testrunner_banner && displayed
454+
call deletebufline(s:runner.bufnr, 1, len(s:buffer.bannerlines()))
455+
endif
456+
call setbufvar(s:runner.bufnr, '&modifiable', 0)
457+
call setbufvar(s:runner.bufnr, '&modified', 0)
458+
endif
440459
endfunction
441460

442461

ftplugin/omnisharptest/OmniSharp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set concealcursor=nv
55
set foldlevel=2
66
set foldmethod=syntax
77
set signcolumn=no
8+
set synmaxcol=3000
89

910
nnoremap <buffer> <Plug>(omnisharp_testrunner_togglebanner) :call OmniSharp#testrunner#ToggleBanner()<CR>
1011
nnoremap <buffer> <Plug>(omnisharp_testrunner_run) :call OmniSharp#testrunner#Run()<CR>

syntax/omnisharptest.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ let s:save_cpo = &cpoptions
66
set cpoptions&vim
77

88
syn region ostBanner start="\%1l" end="\%8l$" contains=ostBannerDelim,ostBannerTitle,ostBannerHelp transparent keepend
9-
syn match ostBannerHelp "^ .*$" contained contains=ostBannerMap,ostBannerLink
10-
syn match ostBannerMap "^ \S\+" contained
9+
syn match ostBannerHelp "^` .*$" contained contains=ostBannerMap,ostBannerLink,ostBannerPrefix
10+
syn match ostBannerMap "^` \S\+" contained contains=ostBannerPrefix
1111
syn match ostBannerLink ":help [[:alnum:]-]\+" contained
12-
syn match ostBannerTitle "\%2l^.\+$" contained
13-
syn match ostBannerDelim "\%1l^.*$" contained
14-
syn match ostBannerDelim "\%3l^.*$" contained
15-
syn match ostBannerDelim "\%8l^.*$" contained
12+
syn match ostBannerTitle "\%2l^`.\+$" contained contains=ostBannerPrefix
13+
syn match ostBannerDelim "\%1l^`.*$" contained contains=ostBannerPrefix
14+
syn match ostBannerDelim "\%3l^`.*$" contained contains=ostBannerPrefix
15+
syn match ostBannerDelim "\%8l^`.*$" contained contains=ostBannerPrefix
16+
syn match ostBannerPrefix "^`" conceal contained
1617

1718
syn match ostProjectKey ";[^;]*;[^;]*;.*" contains=ostSolution,ostAssembly,ostProjectDelimiter,ostProjectError
1819
syn match ostSolution "\%(^;[^;]\+;\)\@<=[^;]\+" contained conceal

0 commit comments

Comments
 (0)