|
37 | 37 | ;;; Code:
|
38 | 38 |
|
39 | 39 | (require 'haskell-mode)
|
| 40 | +(require 'haskell-process) |
| 41 | +(require 'haskell-interactive-mode) |
40 | 42 |
|
41 | 43 | (defvar haskell-completions-pragma-names
|
42 | 44 | (list "DEPRECATED"
|
@@ -219,5 +221,56 @@ result only if prefix length is not less than MINLEN."
|
219 | 221 | (prefix prefix)))))
|
220 | 222 |
|
221 | 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 | + |
| 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 | + |
222 | 275 | (provide 'haskell-completions)
|
223 | 276 | ;;; haskell-completions.el ends here
|
0 commit comments