Add error handling to VimwikiSearch per issue #420

- Create function wrapper around lvimgrep for input checking, pattern
   quoting, and error handling.
 - Add Vader tests for VimwikiSearch.
 - Change syntax loading from try/catch to explicit file check (to
   prevent Vader test bug).
 - Update doc/vimwiki.txt for changes.
 - Change test script to run Vader tests separately
This commit is contained in:
Dave Gauer
2019-10-12 18:31:43 -04:00
parent ba84981b5a
commit ad95e3463f
9 changed files with 185 additions and 12 deletions

View File

@ -1068,12 +1068,18 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
" let b:skip_set_iskeyword = 1
let is_keyword = &iskeyword
try
" keep going even if syntax file is not found
" Check for the existence of syntax files in the runtime path before
" attempting to include them.
" https://vi.stackexchange.com/a/10354
" Previously, this used a try/catch block to intercept any errors thrown
" when attempting to include files. The error(s) interferred with running
" with Vader tests (specifically, testing VimwikiSearch).
if !empty(globpath(&rtp, 'syntax/'.a:filetype.'.vim'))
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
endif
if !empty(globpath(&rtp, 'after/syntax/'.a:filetype.'.vim'))
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
endif
let &iskeyword = is_keyword
@ -2279,6 +2285,35 @@ function! vimwiki#base#read_caption(file)
endfunction
" For commands VimwikiSearch and VWS
function vimwiki#base#search(search_pattern)
if empty(a:search_pattern)
echomsg 'Vimwiki Error: No search pattern given.'
return
endif
let pattern = a:search_pattern
" If the pattern does not start with a '/', then we'll assume that a
" literal search is intended and enclose and escape it:
if match(pattern, '^/') == -1
let pattern = '/'.escape(pattern, '\').'/'
endif
let path = fnameescape(vimwiki#vars#get_wikilocal('path'))
let ext = vimwiki#vars#get_wikilocal('ext')
let cmd = "lvimgrep ".pattern." ".path.'**/*'.ext
" Catch E480 error from lvimgrep if there's no match and present
" a friendlier error message.
try
execute cmd
catch
echomsg "VimwikiSearch: No match found."
endtry
endfunction
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
for s:syn in s:vimwiki_get_known_syntaxes()