diff --git a/autoload/ale/handlers/haskell.vim b/autoload/ale/handlers/haskell.vim index bac5f4ae..9c8d0586 100644 --- a/autoload/ale/handlers/haskell.vim +++ b/autoload/ale/handlers/haskell.vim @@ -1,11 +1,24 @@ " Author: w0rp " Description: Error handling for the format GHC outputs. +" Remember the directory used for temporary files for Vim. +let s:temp_dir = fnamemodify(tempname(), ':h') +" Build part of a regular expression for matching ALE temporary filenames. +let s:temp_regex_prefix = +\ '\M' +\ . substitute(s:temp_dir, '\\', '\\\\', 'g') +\ . '\.\{-}' + function! ale#handlers#haskell#HandleGHCFormat(buffer, lines) abort " Look for lines like the following. " "Appoint/Lib.hs:8:1: warning: "Appoint/Lib.hs:8:1: + let l:basename = expand('#' . a:buffer . ':t') + " Build a complete regular expression for replacing temporary filenames + " in Haskell error messages with the basename for this file. + let l:temp_filename_regex = s:temp_regex_prefix . l:basename + let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+):(.*)?$' let l:output = [] @@ -51,6 +64,9 @@ function! ale#handlers#haskell#HandleGHCFormat(buffer, lines) abort let l:type = 'E' endif + " Replace temporary filenames in problem messages with the basename + let l:text = substitute(l:text, l:temp_filename_regex, l:basename, 'g') + call add(l:output, { \ 'lnum': l:match[2] + 0, \ 'col': l:match[3] + 0, diff --git a/test/handler/test_ghc_mod_handler.vader b/test/handler/test_ghc_mod_handler.vader index b8d09a54..bed5b13c 100644 --- a/test/handler/test_ghc_mod_handler.vader +++ b/test/handler/test_ghc_mod_handler.vader @@ -21,10 +21,17 @@ Execute(HandleGhcFormat should handle ghc-mod problems): \ 'type': 'W', \ 'text': 'Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ', \ }, + \ { + \ 'lnum': 28, + \ 'col': 28, + \ 'type': 'W', + \ 'text': 'Defaulting the following constraints to type ‘Integer’ (Num a0) arising from the literal ‘3’ at check2.hs:28:28 (Eq a0) arising from a use of ‘lookup’ at check2.hs:28:21-28 • In the first argument of ‘lookup’, namely ‘3’ In the expression: lookup 3 In the second argument of ‘fmap’, namely ‘(lookup 3 $ zip [1, 2, 3] [4, 5, 6])''’' + \ }, \ ], \ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [ \ 'check2.hs:2:1:Failed to load interface for ‘Missing’Use -v to see a list of the files searched for.', \ 'check2.hs:2:1: Suggestion: Use camelCaseFound: my_variable = ...Why not: myVariable = ...', \ 'check2.hs:6:1: Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ', \ 'xxx.hs:6:1: Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ', + \ printf("check2.hs:28:28: Warning: Defaulting the following constraints to type ‘Integer’ (Num a0) arising from the literal ‘3’ at %s/check2.hs:28:28 (Eq a0) arising from a use of ‘lookup’ at %s/check2.hs:28:21-28 • In the first argument of ‘lookup’, namely ‘3’ In the expression: lookup 3 In the second argument of ‘fmap’, namely ‘(lookup 3 $ zip [1, 2, 3] [4, 5, 6])'’", tempname(), tempname()), \ ])