Skip to content

Commit 0acebe2

Browse files
committed
Allow module name completion in import statements
1 parent 406a402 commit 0acebe2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

haskell.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,25 @@
5858
(defun haskell-process-completions-at-point ()
5959
"A completion-at-point function using the current haskell process."
6060
(when (haskell-session-maybe)
61-
(let ((process (haskell-process))
62-
(symbol (symbol-at-point)))
63-
(cl-destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
64-
(let ((completions (haskell-process-get-repl-completions
65-
process
66-
(symbol-name symbol))))
67-
(list start end completions))))))
61+
(let ((process (haskell-process)) symbol)
62+
(cond
63+
;; ghci can complete module names, but it needs the "import "
64+
;; string at the beginning
65+
((looking-back (rx line-start
66+
"import" (1+ space)
67+
(? "qualified" (1+ space))
68+
(group (? (char upper) ; modid
69+
(* (char alnum ?' ?.))))))
70+
(let ((text (match-string-no-properties 0))
71+
(start (match-beginning 1))
72+
(end (match-end 1)))
73+
(list start end
74+
(haskell-process-get-repl-completions process text))))
75+
((setq symbol (symbol-at-point))
76+
(cl-destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
77+
(let ((completions (haskell-process-get-repl-completions
78+
process (symbol-name symbol))))
79+
(list start end completions))))))))
6880

6981
;;;###autoload
7082
(defun haskell-interactive-mode-return ()

0 commit comments

Comments
 (0)