Skip to content

Commit e644b7a

Browse files
committed
Rename and rewrite REPL based completion funciton
Make use of implemented simple completion funciton. Complete keywords.
1 parent 6dff9d0 commit e644b7a

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

haskell-completions.el

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -307,35 +307,36 @@ GHC's options, and language extensions, but not identifiers."
307307
(let ((prefix (haskell-completions-grab-prefix)))
308308
(haskell-completions--simple-completions prefix)))
309309

310-
(defun haskell-completions-sync-completions-at-point ()
310+
(defun haskell-completions-sync-repl-completion-at-point ()
311311
"A `completion-at-point' function using the current haskell process.
312312
Returns nil if no completions available."
313313
(let ((prefix-data (haskell-completions-grab-prefix)))
314314
(when prefix-data
315315
(cl-destructuring-bind (beg end pfx typ) prefix-data
316-
(let ((imp (eql typ 'haskell-completions-module-name-prefix))
317-
lst)
318-
(setq lst
319-
(cl-case typ
320-
;; non-interactive completions first
321-
('haskell-completions-pragma-name-prefix
322-
haskell-completions--pragma-names)
323-
('haskell-completions-ghc-option-prefix
324-
haskell-ghc-supported-options)
325-
('haskell-completions-language-extension-prefix
326-
haskell-ghc-supported-extensions)
327-
(otherwise
328-
(when (and
329-
(not (eql typ 'haskell-completions-general-prefix))
330-
(haskell-session-maybe)
331-
(not
332-
(haskell-process-cmd (haskell-interactive-process))))
333-
;; if REPL is available and not busy try to query it
334-
;; for completions list in case of module name or
335-
;; identifier prefixes
336-
(haskell-completions-sync-complete-repl pfx imp)))))
337-
(when lst
338-
(list beg end lst)))))))
316+
(when (not (eql typ 'haskell-completions-general-prefix))
317+
;; do not complete things in comments
318+
(if (cl-member
319+
typ
320+
'(haskell-completions-pragma-name-prefix
321+
haskell-completions-ghc-option-prefix
322+
haskell-completions-language-extension-prefix))
323+
;; provide simple completions
324+
(haskell-completions--simple-completions prefix-data)
325+
;; only two cases left: haskell-completions-module-name-prefix
326+
;; and haskell-completions-identifier-prefix
327+
(let* ((is-import (eql typ 'haskell-completions-module-name-prefix))
328+
(candidates
329+
(when (and (haskell-session-maybe)
330+
(not (haskell-process-cmd
331+
(haskell-interactive-process))))
332+
;; if REPL is available and not busy try to query it for
333+
;; completions list in case of module name or identifier
334+
;; prefixes
335+
(haskell-completions-sync-complete-repl pfx is-import))))
336+
;; append candidates with keywords
337+
(list beg end (append
338+
candidates
339+
haskell-completions--keywords)))))))))
339340

340341
(defun haskell-completions-sync-complete-repl (prefix &optional import)
341342
"Return completion list for given PREFIX querying REPL synchronously.

haskell.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@
6767
:lighter " Interactive"
6868
:keymap interactive-haskell-mode-map
6969
(add-hook 'completion-at-point-functions
70-
#'haskell-completions-sync-completions-at-point
70+
#'haskell-completions-sync-repl-completion-at-point
7171
nil
7272
t))
7373

7474
(make-obsolete 'haskell-process-completions-at-point
75-
'haskell-completions-sync-completions-at-point
75+
'haskell-completions-sync-repl-completion-at-point
7676
"June 19, 2015")
7777
(defun haskell-process-completions-at-point ()
7878
"A completion-at-point function using the current haskell process."

0 commit comments

Comments
 (0)