Allow per-implementation callbacks to be registered that provide extra a...

...rguments based on the full path of the buffer file.  Immediate use is GHC/Haskell to add the path to the .cabal file via -I


The following code, in a typical project, gets rid of warnings that modules (in the file next to the one you're viewing, etc) are not available.  It could probably be expanded, after finding the .cabal file, to stripping other GHC options from it

(defun get-possible-dir-containing-cabal (dir)
  (when dir
    (let* ((check-dir (apply #'concatenate 'string (loop for elt in dir append (list elt "/"))))
           (found (directory-files check-dir t "^.+\\.[Cc][Aa][Bb][Aa][Ll]")))
      (if found
          (list check-dir)
        (get-possible-dir-containing-cabal (butlast dir))))))

(defun get-ghc-args-knowing-full-file-path (file)
  (loop for dir in (get-possible-dir-containing-cabal (split-string (file-name-directory file) "\\/")) collect
        (concatenate 'string "-i" dir)))

(flycheck-mode-add-argsource
 'haskell-ghc
 #'get-ghc-args-knowing-full-file-path)