Skip to content

Commit 5415e29

Browse files
committed
Define completion at point function
1 parent 32f93c7 commit 5415e29

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

haskell-completions.el

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,41 @@ result only if prefix length is not less than MINLEN."
220220
prefix))
221221
(prefix prefix)))))
222222

223+
224+
(defun haskell-completions-sync-completions-at-point ()
225+
"A `completion-at-point' function using the current haskell process.
226+
Returns nil if no completions available."
227+
(let ((prefix-data (haskell-completions-grab-prefix)))
228+
(when prefix-data
229+
(cl-destructuring-bind (beg end pfx typ) prefix-data
230+
(let ((imp (eql typ 'haskell-completions-module-name-prefix))
231+
lst)
232+
(setq lst
233+
(cl-case typ
234+
;; non-interactive completions first
235+
('haskell-completions-pragma-name-prefix
236+
haskell-completions-pragma-names)
237+
('haskell-completions-ghc-option-prefix
238+
haskell-ghc-supported-options)
239+
('haskell-completions-language-extension-prefix
240+
haskell-ghc-supported-extensions)
241+
(otherwise
242+
(when (and
243+
(not (eql typ 'haskell-completions-general-prefix))
244+
(haskell-session-maybe)
245+
(not
246+
(haskell-process-cmd (haskell-interactive-process))))
247+
;; if REPL is available and not busy try to query it
248+
;; for completions list in case of module name or
249+
;; identifier prefixes
250+
(haskell-completions-sync-complete-repl pfx imp)))))
251+
(when (or (equal '("") lst)
252+
(eql nil lst))
253+
;; complete things using dabbrev
254+
(setq lst (haskell-completions-dabbrev-completions pfx)))
255+
(when lst
256+
(list beg end lst)))))))
257+
223258
(defun haskell-completions-sync-complete-repl (prefix &optional import)
224259
"Return completion list for given PREFIX quering REPL synchronously.
225260
When optional IMPORT argument is non-nil complete PREFIX

0 commit comments

Comments
 (0)