diff --git a/haskell-cabal.el b/haskell-cabal.el index 3a1c17f03..af4964bc3 100644 --- a/haskell-cabal.el +++ b/haskell-cabal.el @@ -468,27 +468,41 @@ OTHER-WINDOW use `find-file-other-window'." (defun haskell-cabal-section-data-start-column (section) (plist-get section :data-start-column)) -(defun haskell-cabal-enum-targets () - "Enumerate .cabal targets." - (let ((cabal-file (haskell-cabal-find-file))) +(defun haskell-cabal-map-component-type (component-type) + "Map from cabal file COMPONENT-TYPE to build command component-type." + (let ((component-type (downcase component-type))) + (cond ((equal component-type "executable") "exe") + ((equal component-type "test-suite") "test") + ((equal component-type "benchmark") "bench")))) + +(defun haskell-cabal-enum-targets (&optional process-type) + "Enumerate .cabal targets. PROCESS-TYPE determines the format of the returned target." + (let ((cabal-file (haskell-cabal-find-file)) + (process-type (if process-type process-type 'ghci))) (when (and cabal-file (file-readable-p cabal-file)) (with-temp-buffer (insert-file-contents cabal-file) (haskell-cabal-mode) (goto-char (point-min)) (let ((matches) - (projectName (haskell-cabal--get-field "name"))) + (package-name (haskell-cabal--get-field "name"))) (haskell-cabal-next-section) (while (not (eobp)) (if (haskell-cabal-source-section-p (haskell-cabal-section)) - (let ((val (car (split-string - (haskell-cabal-section-value - (haskell-cabal-section)))))) + (let* ((section (haskell-cabal-section)) + (component-type (haskell-cabal-section-name section)) + (val (car (split-string + (haskell-cabal-section-value section))))) (if (or (string= val "") (string= val "{") (not val)) - (push projectName matches) - (push val matches)))) + (push package-name matches) + (push (concat (when (eq 'stack-ghci process-type) + (concat package-name ":")) + (haskell-cabal-map-component-type component-type) + ":" + val) + matches)))) (haskell-cabal-next-section)) (reverse matches)))))) diff --git a/haskell-commands.el b/haskell-commands.el index 6ffd938d0..8ac937dee 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -770,7 +770,7 @@ inferior GHCi process." (interactive (list (completing-read "New build target: " - (haskell-cabal-enum-targets) + (haskell-cabal-enum-targets (haskell-process-type)) nil nil nil diff --git a/tests/haskell-cabal-tests.el b/tests/haskell-cabal-tests.el index 8fbb3987d..947445d7e 100644 --- a/tests/haskell-cabal-tests.el +++ b/tests/haskell-cabal-tests.el @@ -5,7 +5,7 @@ (require 'haskell-cabal) (ert-deftest haskell-cabal-enum-targets-1 () - "Test enumerating .cabal targets." + "Test enumerating .cabal targets for use by cabal-install." (with-temp-buffer (haskell-cabal-mode) (let ((scriptDir @@ -13,9 +13,21 @@ (or (symbol-file 'haskell-cabal-enum-targets-1) (buffer-file-name))))) (setq default-directory (expand-file-name "test-data" scriptDir))) - (should (equal '("Test" "test-1" "bench-1" "bin-1") + (should (equal '("Test" "test:test-1" "bench:bench-1" "exe:bin-1") (haskell-cabal-enum-targets))))) +(ert-deftest haskell-cabal-enum-targets-2 () + "Test enumerating .cabal targets for use by stack." + (with-temp-buffer + (haskell-cabal-mode) + (let ((scriptDir + (file-name-directory + (or (symbol-file 'haskell-cabal-enum-targets-2) + (buffer-file-name))))) + (setq default-directory (expand-file-name "test-data" scriptDir))) + (should (equal '("Test" "Test:test:test-1" "Test:bench:bench-1" "Test:exe:bin-1") + (haskell-cabal-enum-targets 'stack-ghci))))) + (ert-deftest haskell-cabal-get-field-1 () (with-temp-buffer (let ((scriptDir