Skip to content

Commit f0466a2

Browse files
committed
Add optional candidates limit arg, remove unused item from result
+ Add options argument to `haskell-process-get-repl-completions` setting completion candidates limit + Remove unused item from resulting candidates list. This item is not completion itself but unused part of input string (see issue #776 for more details).
1 parent 281883d commit f0466a2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

haskell-process.el

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,30 @@ This uses `accept-process-output' internally."
286286
(haskell-process-queue-flush process)
287287
(car-safe (haskell-command-state cmd))))
288288

289-
(defun haskell-process-get-repl-completions (process inputstr)
290-
"Perform `:complete repl ...' query for INPUTSTR using PROCESS."
291-
(let* ((reqstr (concat ":complete repl "
289+
(defun haskell-process-get-repl-completions (process inputstr &optional limit)
290+
"Perform `:complete repl ...' query for INPUTSTR using PROCESS.
291+
Give optional LIMIT arg to limit completion candidates count,
292+
zero, negative values, and nil means all possible completions.
293+
Returns NIL when no completions found."
294+
(let* ((mlimit (if (and limit (> limit 0))
295+
(concat " " (number-to-string limit) " ")
296+
" "))
297+
(reqstr (concat ":complete repl"
298+
mlimit
292299
(haskell-string-literal-encode inputstr)))
293300
(rawstr (haskell-process-queue-sync-request process reqstr)))
301+
;; TODO use haskell-utils-parse-repl-response
294302
(if (string-prefix-p "unknown command " rawstr)
295303
(error "GHCi lacks `:complete' support (try installing 7.8 or ghci-ng)")
296304
(let* ((s1 (split-string rawstr "\r?\n" t))
297305
(cs (mapcar #'haskell-string-literal-decode (cdr s1)))
298-
(h0 (car s1))) ;; "<cnt1> <cnt2> <quoted-str>"
306+
(h0 (car s1))) ;; "<limit count> <all count> <unused string>"
299307
(unless (string-match "\\`\\([0-9]+\\) \\([0-9]+\\) \\(\".*\"\\)\\'" h0)
300308
(error "Invalid `:complete' response"))
301-
(let ((cnt1 (match-string 1 h0))
302-
(h1 (haskell-string-literal-decode (match-string 3 h0))))
309+
(let ((cnt1 (match-string 1 h0)))
303310
(unless (= (string-to-number cnt1) (length cs))
304311
(error "Lengths inconsistent in `:complete' reponse"))
305-
(cons h1 cs))))))
312+
cs)))))
306313

307314
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308315
;; Accessing the process

0 commit comments

Comments
 (0)