@@ -873,20 +873,25 @@ from `module-buffer'."
873
873
cabal-file))
874
874
(haskell-cabal-add-dependency package-name version nil t ))))
875
875
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)))))))
890
895
(when module
891
896
(haskell-process-find-file session file)
892
897
(save-excursion
@@ -901,28 +906,24 @@ from `module-buffer'."
901
906
" Given an out of scope identifier, Hoogle for that identifier,
902
907
and if a result comes back, suggest to import that identifier
903
908
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)))
907
910
; ; Skip qualification.
908
911
(if (string-match " ^[A-Za-z0-9_'.]+\\ .\\ (.+\\ )$" i)
909
912
(match-string 1 i)
910
913
i)))
911
914
(modules (haskell-process-hoogle-ident ident)))
912
- (haskell-process-suggest-imports modules ident)))
915
+ (haskell-process-suggest-imports session file modules ident)))
913
916
914
917
(defun haskell-process-suggest-hayoo-imports (session msg file )
915
918
" Given an out of scope identifier, Hayoo for that identifier,
916
919
and if a result comes back, suggest to import that identifier
917
920
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)))
921
922
; ; Skip qualification.
922
923
(if (string-match " ^[A-Za-z0-9_'.]+\\ .\\ (.+\\ )$" i)
923
924
(match-string 1 i)
924
925
i))))
925
- (haskell-process-hayoo-ident ident #'haskell-process-suggest-imports )))
926
+ (haskell-process-hayoo-ident session file ident #'haskell-process-suggest-imports )))
926
927
927
928
928
929
(defun haskell-process-suggest-haskell-docs-imports (session msg file )
@@ -981,19 +982,28 @@ now."
981
982
(split-string (buffer-string )
982
983
" \n " ))))))
983
984
984
- (defun haskell-process-hayoo-ident (ident callback )
985
+ (defun haskell-process-hayoo-ident (session file ident callback )
985
986
" 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
987
991
haskell-process-hayoo-ident--callback callback)
988
992
(url-retrieve
989
993
(format haskell-process-hayoo-query-url ident)
990
994
(lambda (status )
991
995
(re-search-forward " \r ?\n\r ?\n " )
992
996
(let* ((res (json-read-object ))
993
997
(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.
994
1001
(modules-l (cl-mapcar (lambda (r ) (cl-mapcar 'identity (assoc-default 'resultModules r))) results))
995
1002
(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
997
1007
haskell-process-hayoo-ident--ident)))))
998
1008
999
1009
(defun haskell-process-suggest-remove-import (session file import line )
0 commit comments