Skip to content

New synchronous completion function #732

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

Merged
merged 2 commits into from
Jun 19, 2015
Merged
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
53 changes: 53 additions & 0 deletions haskell-completions.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
;;; Code:

(require 'haskell-mode)
(require 'haskell-process)
(require 'haskell-interactive-mode)

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


(defun haskell-completions-sync-completions-at-point ()
"A `completion-at-point' function using the current haskell process.
Returns nil if no completions available."
(let ((prefix-data (haskell-completions-grab-prefix)))
(when prefix-data
(cl-destructuring-bind (beg end pfx typ) prefix-data
(let ((imp (eql typ 'haskell-completions-module-name-prefix))
lst)
(setq lst
(cl-case typ
;; non-interactive completions first
('haskell-completions-pragma-name-prefix
haskell-completions-pragma-names)
('haskell-completions-ghc-option-prefix
haskell-ghc-supported-options)
('haskell-completions-language-extension-prefix
haskell-ghc-supported-extensions)
(otherwise
(when (and
(not (eql typ 'haskell-completions-general-prefix))
(haskell-session-maybe)
(not
(haskell-process-cmd (haskell-interactive-process))))
;; if REPL is available and not busy try to query it
;; for completions list in case of module name or
;; identifier prefixes
(haskell-completions-sync-complete-repl pfx imp)))))
(when (or (equal '("") lst)
(eql nil lst))
;; complete things using dabbrev
(setq lst (haskell-completions-dabbrev-completions pfx)))
(when lst
(list beg end lst)))))))

(defun haskell-completions-sync-complete-repl (prefix &optional import)
"Return completion list for given PREFIX quering REPL synchronously.
When optional IMPORT argument is non-nil complete PREFIX
prepending \"import \" keyword (useful for module names). This
function is supposed for internal use."
(haskell-process-get-repl-completions
(haskell-interactive-process)
(if import
(concat "import " prefix)
prefix)))

(defun haskell-completions-dabbrev-completions (prefix)
"Return completion list for PREFIX using dabbrev facility.
This function is supposed for internal use."
(dabbrev--reset-global-variables)
(dabbrev--find-all-expansions prefix nil))

(provide 'haskell-completions)
;;; haskell-completions.el ends here