branch: elpa/haskell-tng-mode commit 73a60f5a1292556f27fb301e0746024426c0b860 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
cache `which hsinspect` per project --- haskell-tng-compile.el | 5 +++++ haskell-tng-extra-projectile.el | 5 ----- haskell-tng-extra-stack.el | 1 + haskell-tng-hsinspect.el | 40 ++++++++++++++++++++-------------------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/haskell-tng-compile.el b/haskell-tng-compile.el index 0fcd3fd..ee8b21e 100644 --- a/haskell-tng-compile.el +++ b/haskell-tng-compile.el @@ -73,6 +73,11 @@ (defvar haskell-tng--compile-dominating-package (rx (| (: (+ any) ".cabal") "package.yaml"))) +;; Not guaranteed to exist for cabal-install, always fall back to +;; dominating-package when searching for the dominating project. +(defvar haskell-tng--compile-dominating-project + (rx (| "cabal.project" "cabal.project.local" "cabal.project.freeze"))) + (defun haskell-tng-compile (&optional edit-command) "`compile' specialised to Haskell: diff --git a/haskell-tng-extra-projectile.el b/haskell-tng-extra-projectile.el index ed6cde9..4fbf108 100644 --- a/haskell-tng-extra-projectile.el +++ b/haskell-tng-extra-projectile.el @@ -12,11 +12,6 @@ ;; TODO fix the haskell-stack detection to also include cabal ;; TODO populate the projectile compile/run/test commands -;; ;; Not guaranteed to exist for cabal-install, always fall back to -;; ;; dominating-package when searching for the dominating project. -;; (defvar haskell-tng--compile-dominating-project -;; (rx (| "cabal.project" "cabal.project.local" "cabal.project.freeze"))) - (make-variable-buffer-local 'projectile-tags-command) (add-hook 'haskell-tng-mode-hook diff --git a/haskell-tng-extra-stack.el b/haskell-tng-extra-stack.el index 810e8b9..ee0ab33 100644 --- a/haskell-tng-extra-stack.el +++ b/haskell-tng-extra-stack.el @@ -13,6 +13,7 @@ (require 'haskell-tng-hsinspect) (setq + haskell-tng--compile-dominating-project (rx "stack.yaml") haskell-tng--hsinspect-which-hsinspect "stack exec --silent which -- hsinspect" haskell-tng--compile-history '("stack build --fast --no-interleaved-output --ghc-options=\"-j\" --no-run-tests" "stack build --fast --no-interleaved-output --ghc-options=\"-j\"")) diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el index 4b72c99..5c7eabe 100644 --- a/haskell-tng-hsinspect.el +++ b/haskell-tng-hsinspect.el @@ -119,48 +119,48 @@ A prefix argument ensures that caches are flushes." (defvar-local haskell-tng--hsinspect-imports nil) (defun haskell-tng--hsinspect-imports (&optional no-work flush-cache) (haskell-tng--hsinspect-cached - (lambda () (haskell-tng--hsinspect "imports" buffer-file-name)) + (lambda () (haskell-tng--hsinspect flush-cache "imports" buffer-file-name)) 'haskell-tng--hsinspect-imports (concat "hsinspect-0.0.7" buffer-file-name "." "imports") no-work flush-cache)) -;; TODO use a package specific variable buffer +;; TODO add a package-wide variable cache (defun haskell-tng--hsinspect-index (&optional flush-cache) (when-let (ghcflags-dir (locate-dominating-file default-directory ".ghc.flags")) (haskell-tng--hsinspect-cached-disk - (lambda () (haskell-tng--hsinspect "index")) + (lambda () (haskell-tng--hsinspect flush-cache "index")) (concat "hsinspect-0.0.7" (expand-file-name ghcflags-dir) "index") nil flush-cache))) -;; FIXME use a project-wide cache -(defvar-local haskell-tng--hsinspect-exe nil) +;; TODO add a project-wide variable cache (defvar haskell-tng--hsinspect-which-hsinspect "cabal exec -v0 which -- hsinspect") -(defun haskell-tng--hsinspect-exe () +(defun haskell-tng--hsinspect-exe (&optional flush-cache) "The binary to use for `hsinspect'" - (or - haskell-tng--hsinspect-exe - (setq - haskell-tng--hsinspect-exe - (let ((which (string-trim (shell-command-to-string haskell-tng--hsinspect-which-hsinspect)))) - (if (file-exists-p which) - which - ;; TODO don't do this, prefer an error message - "hsinspect"))))) - -(defun haskell-tng--hsinspect (&rest params) + (when-let (package-dir (or + (haskell-tng--util-locate-dominating-file + haskell-tng--compile-dominating-project) + (haskell-tng--util-locate-dominating-file + haskell-tng--compile-dominating-package))) + (haskell-tng--hsinspect-cached-disk + (lambda () (string-trim (shell-command-to-string haskell-tng--hsinspect-which-hsinspect))) + (concat "which" (expand-file-name package-dir) "hsinspect") + nil + flush-cache))) + +(defun haskell-tng--hsinspect (flush-cache &rest params) (ignore-errors (kill-buffer "*hsinspect*")) (when-let ((ghcflags (haskell-tng--hsinspect-ghcflags)) - ;; TODO search for the .cabal file and then delete .ghc.version support - (default-directory (locate-dominating-file default-directory ".ghc.version"))) + (default-directory (haskell-tng--util-locate-dominating-file + haskell-tng--compile-dominating-package))) (if (/= 0 (let ((process-environment (cons "GHC_ENVIRONMENT=-" process-environment))) (apply #'call-process - (haskell-tng--hsinspect-exe) + (haskell-tng--hsinspect-exe flush-cache) nil "*hsinspect*" nil (append params '("--") ghcflags)))) (user-error "`hsinspect' failed. See the *hsinspect* buffer for more information")