Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 2c1c0d0

Browse files
committed
Safety checks for ghc-mod.
1 parent 4c2dcf2 commit 2c1c0d0

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

syntax_checkers/haskell/ghc-mod.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ if exists('g:loaded_syntastic_haskell_ghc_mod_checker')
1515
endif
1616
let g:loaded_syntastic_haskell_ghc_mod_checker = 1
1717

18+
let s:ghc_mod_new = -1
19+
1820
function! SyntaxCheckers_haskell_ghc_mod_IsAvailable()
19-
return executable('ghc-mod')
21+
" We need either a Vim version that can handle NULs in system() output,
22+
" or a ghc-mod version that has the --boundary option.
23+
let s:ghc_mod_new = executable('ghc-mod') ? s:GhcModNew() : -1
24+
return (s:ghc_mod_new >= 0) && (v:version >= 704 || s:ghc_mod_new)
2025
endfunction
2126

2227
function! SyntaxCheckers_haskell_ghc_mod_GetLocList()
2328
let makeprg = syntastic#makeprg#build({
24-
\ 'exe': 'ghc-mod check',
29+
\ 'exe': 'ghc-mod check' . (s:ghc_mod_new ? ' --boundary=""' : ''),
2530
\ 'filetype': 'haskell',
2631
\ 'subchecker': 'ghc_mod' })
2732

@@ -41,6 +46,17 @@ function! SyntaxCheckers_haskell_ghc_mod_GetLocList()
4146
\ 'postprocess': ['compressWhitespace'] })
4247
endfunction
4348

49+
function! s:GhcModNew()
50+
try
51+
let ghc_mod_version = filter(split(system('ghc-mod'), '\n'), 'v:val =~# ''\m^ghc-mod version''')[0]
52+
let ret = syntastic#util#versionIsAtLeast(syntastic#util#parseVersion(ghc_mod_version), [2, 1, 2])
53+
catch /^Vim\%((\a\+)\)\=:E684/
54+
call syntastic#util#error("checker haskell/ghc_mod: can't parse version string (abnormal termination?)")
55+
let ret = -1
56+
endtry
57+
return ret
58+
endfunction
59+
4460
call g:SyntasticRegistry.CreateAndRegisterChecker({
4561
\ 'filetype': 'haskell',
4662
\ 'name': 'ghc_mod'})

0 commit comments

Comments
 (0)