Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPTIONS and LANGUAGE completion using ghci #444

Merged
merged 5 commits into from
Apr 22, 2015
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
12 changes: 12 additions & 0 deletions haskell-customize.el
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ when Data.Map is the candidate.
:group 'shm
:type '(repeat 'string))

(defcustom haskell-ghc-supported-languages
(split-string (shell-command-to-string "ghc --supported-extensions"))
"List of language pragmas supported by the installed version of GHC."
:group 'haskell
:type '(repeat string))

(defcustom haskell-ghc-supported-options
(split-string (shell-command-to-string "ghc --show-options"))
"List of options supported by the installed version of GHC."
:group 'haskell
:type '(repeat string))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Accessor functions

Expand Down
6 changes: 0 additions & 6 deletions haskell-yas.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
:group 'haskell
:prefix "haskell-yas-")

(defcustom haskell-yas-ghc-language-pragmas
(split-string (shell-command-to-string "ghc --supported-extensions"))
"List of language pragmas supported by the installed version of GHC."
:group 'haskell-yas
:type '(repeat string))

(defcustom haskell-yas-completing-function 'ido-completing-read
"Function to use for completing among alternatives."
:group 'haskell-yas
Expand Down
29 changes: 23 additions & 6 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
(defun haskell-process-completions-at-point ()
"A completion-at-point function using the current haskell process."
(when (haskell-session-maybe)
(let ((process (haskell-process)) symbol)
(let ((process (haskell-process)) symbol symbol-bounds)
(cond
;; ghci can complete module names, but it needs the "import "
;; string at the beginning
Expand All @@ -72,11 +72,28 @@
(end (match-end 1)))
(list start end
(haskell-process-get-repl-completions process text))))
((setq symbol (symbol-at-point))
(cl-destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
(let ((completions (haskell-process-get-repl-completions
process (symbol-name symbol))))
(list start end completions))))))))
;; Complete OPTIONS using :complete repl ":set ..."
((and (nth 4 (syntax-ppss))
(save-excursion
(let ((p (point)))
(and (search-backward "{-#" nil t)
(search-forward-regexp "\\_<OPTIONS\\(?:_GHC\\)?\\_>" p t))))
(looking-back (rx symbol-start "-" (* (char alnum ?-)))))
(list (match-beginning 0) (match-end 0) haskell-ghc-supported-options))
;; Complete LANGUAGE :complete repl ":set -X..."
((and (nth 4 (syntax-ppss))
(save-excursion
(let ((p (point)))
(and (search-backward "{-#" nil t)
(search-forward-regexp "\\_<LANGUAGE\\_>" p t))))
(setq symbol-bounds (bounds-of-thing-at-point 'symbol)))
(list (car symbol-bounds) (cdr symbol-bounds)
haskell-ghc-supported-languages))
((setq symbol-bounds (bounds-of-thing-at-point 'symbol))
(cl-destructuring-bind (start . end) symbol-bounds
(list start end
(haskell-process-get-repl-completions
process (buffer-substring-no-properties start end)))))))))

;;;###autoload
(defun haskell-interactive-mode-return ()
Expand Down
2 changes: 1 addition & 1 deletion snippets/haskell-mode/lang-pragma
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# condition: (= (length "lang") (current-column))
# contributor: Luke Hoersten <[email protected]>, John Wiegley
# --
{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-yas-ghc-language-pragmas))` #-}
{-# LANGUAGE `(progn (require 'haskell-yas) (haskell-yas-complete "Extension: " haskell-ghc-supported-languages))` #-}