Skip to content

Commit a814671

Browse files
committed
Merge pull request #732 from geraldus/ac-improvements
New synchronous completion function
2 parents 999164c + 5415e29 commit a814671

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

haskell-completions.el

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
;;; Code:
3838

3939
(require 'haskell-mode)
40+
(require 'haskell-process)
41+
(require 'haskell-interactive-mode)
4042

4143
(defvar haskell-completions-pragma-names
4244
(list "DEPRECATED"
@@ -219,5 +221,56 @@ result only if prefix length is not less than MINLEN."
219221
(prefix prefix)))))
220222

221223

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+
258+
(defun haskell-completions-sync-complete-repl (prefix &optional import)
259+
"Return completion list for given PREFIX quering REPL synchronously.
260+
When optional IMPORT argument is non-nil complete PREFIX
261+
prepending \"import \" keyword (useful for module names). This
262+
function is supposed for internal use."
263+
(haskell-process-get-repl-completions
264+
(haskell-interactive-process)
265+
(if import
266+
(concat "import " prefix)
267+
prefix)))
268+
269+
(defun haskell-completions-dabbrev-completions (prefix)
270+
"Return completion list for PREFIX using dabbrev facility.
271+
This function is supposed for internal use."
272+
(dabbrev--reset-global-variables)
273+
(dabbrev--find-all-expansions prefix nil))
274+
222275
(provide 'haskell-completions)
223276
;;; haskell-completions.el ends here

0 commit comments

Comments
 (0)