Skip to content

Commit fa7762c

Browse files
Fixed typo and moved suggested-already.
1 parent feeb964 commit fa7762c

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

haskell-process.el

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -873,20 +873,25 @@ from `module-buffer'."
873873
cabal-file))
874874
(haskell-cabal-add-dependency package-name version nil t))))
875875

876-
(defun haskell-process-suggest-imports (imports ident)
877-
"Given a list of IMPORTS, suggest adding them to the import section."
878-
(let ((module (cond ((> (length modules) 1)
879-
(when (y-or-n-p (format "Identifier `%s' not in scope, choose module to import?"
880-
ident))
881-
(haskell-complete-module-read "Module: " modules)))
882-
((= (length modules) 1)
883-
(let ((module (car modules)))
884-
(unless (member module suggested-already)
885-
(haskell-process-set-suggested-imports process (cons module suggested-already))
886-
(when (y-or-n-p (format "Identifier `%s' not in scope, import `%s'?"
887-
ident
888-
module))
889-
module)))))))
876+
(defun haskell-process-suggest-imports (session file modules ident)
877+
"Given a list of MODULES, suggest adding them to the import section."
878+
(cl-assert session)
879+
(cl-assert file)
880+
(cl-assert ident)
881+
(let* ((process (haskell-session-process session))
882+
(suggested-already (haskell-process-suggested-imports process))
883+
(module (cond ((> (length modules) 1)
884+
(when (y-or-n-p (format "Identifier `%s' not in scope, choose module to import?"
885+
ident))
886+
(haskell-complete-module-read "Module: " modules)))
887+
((= (length modules) 1)
888+
(let ((module (car modules)))
889+
(unless (member module suggested-already)
890+
(haskell-process-set-suggested-imports process (cons module suggested-already))
891+
(when (y-or-n-p (format "Identifier `%s' not in scope, import `%s'?"
892+
ident
893+
module))
894+
module)))))))
890895
(when module
891896
(haskell-process-find-file session file)
892897
(save-excursion
@@ -901,28 +906,24 @@ from `module-buffer'."
901906
"Given an out of scope identifier, Hoogle for that identifier,
902907
and if a result comes back, suggest to import that identifier
903908
now."
904-
(let* ((process (haskell-session-process session))
905-
(suggested-already (haskell-process-suggested-imports process))
906-
(ident (let ((i (match-string 1 msg)))
909+
(let* ((ident (let ((i (match-string 1 msg)))
907910
;; Skip qualification.
908911
(if (string-match "^[A-Za-z0-9_'.]+\\.\\(.+\\)$" i)
909912
(match-string 1 i)
910913
i)))
911914
(modules (haskell-process-hoogle-ident ident)))
912-
(haskell-process-suggest-imports modules ident)))
915+
(haskell-process-suggest-imports session file modules ident)))
913916

914917
(defun haskell-process-suggest-hayoo-imports (session msg file)
915918
"Given an out of scope identifier, Hayoo for that identifier,
916919
and if a result comes back, suggest to import that identifier
917920
now."
918-
(let* ((process (haskell-session-process session))
919-
(suggested-already (haskell-process-suggested-imports process))
920-
(ident (let ((i (match-string 1 msg)))
921+
(let* ((ident (let ((i (match-string 1 msg)))
921922
;; Skip qualification.
922923
(if (string-match "^[A-Za-z0-9_'.]+\\.\\(.+\\)$" i)
923924
(match-string 1 i)
924925
i))))
925-
(haskell-process-hayoo-ident ident #'haskell-process-suggest-imports)))
926+
(haskell-process-hayoo-ident session file ident #'haskell-process-suggest-imports)))
926927

927928

928929
(defun haskell-process-suggest-haskell-docs-imports (session msg file)
@@ -981,19 +982,28 @@ now."
981982
(split-string (buffer-string)
982983
"\n"))))))
983984

984-
(defun haskell-process-hayoo-ident (ident callback)
985+
(defun haskell-process-hayoo-ident (session file ident callback)
985986
"Hayoo for IDENT, returns a list of modules asyncronously through CALLBACK."
986-
(setq haskell-process-hayoo-ident--ident ident
987+
;; This is a bit mysterious, but otherwise these are all unset
988+
(setq haskell-process-hayoo-ident--session session
989+
haskell-process-hayoo-ident--file file
990+
haskell-process-hayoo-ident--ident ident
987991
haskell-process-hayoo-ident--callback callback)
988992
(url-retrieve
989993
(format haskell-process-hayoo-query-url ident)
990994
(lambda (status)
991995
(re-search-forward "\r?\n\r?\n")
992996
(let* ((res (json-read-object))
993997
(results (assoc-default 'result res))
998+
;; TODO: gather packages as well, and when we choose a
999+
;; given import, check that we have the package in the
1000+
;; cabal file as well.
9941001
(modules-l (cl-mapcar (lambda (r) (cl-mapcar 'identity (assoc-default 'resultModules r))) results))
9951002
(modules (apply #'append modules-l) ))
996-
(funcall haskell-process-hayoo-ident--callback modules
1003+
(funcall haskell-process-hayoo-ident--callback
1004+
haskell-process-hayoo-ident--session
1005+
haskell-process-hayoo-ident--file
1006+
modules
9971007
haskell-process-hayoo-ident--ident)))))
9981008

9991009
(defun haskell-process-suggest-remove-import (session file import line)

0 commit comments

Comments
 (0)