Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions haskell-cabal.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))

Expand Down
2 changes: 1 addition & 1 deletion haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions tests/haskell-cabal-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@
(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
(file-name-directory
(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
Expand Down