@@ -1578,7 +1578,8 @@ current buffer."
1578
1578
(unless sym (setq sym (haskell-ident-at-point)))
1579
1579
; ; if printed before do not print it again
1580
1580
(unless (string= sym (car haskell-doc-last-data))
1581
- (let ((doc (haskell-doc-sym-doc sym)))
1581
+ (let ((doc (or (haskell-doc-current-info--interaction t )
1582
+ (haskell-doc-sym-doc sym))))
1582
1583
(when (and doc (haskell-doc-in-code-p))
1583
1584
; ; In Emacs 19.29 and later, and XEmacs 19.13 and later, all
1584
1585
; ; messages are recorded in a log. Do not put haskell-doc messages
@@ -1595,9 +1596,13 @@ current buffer."
1595
1596
" If non-nil, a previous eldoc message from an async call, that
1596
1597
hasn't been displayed yet." )
1597
1598
1598
- (defun haskell-doc-current-info--interaction ()
1599
+ (defun haskell-doc-current-info--interaction (&optional sync )
1599
1600
" Asynchronous call to `haskell-process-get-type' , suitable for
1600
- use in the eldoc function `haskell-doc-current-info' ."
1601
+ use in the eldoc function `haskell-doc-current-info' .
1602
+
1603
+ If SYNC is non-nil, the call will be synchronous instead, and
1604
+ instead of calling `eldoc-print-current-symbol-info' , the result
1605
+ will be returned directly."
1601
1606
; ; Return nil if nothing is available, or 'async if something might
1602
1607
; ; be available, but asynchronously later. This will call
1603
1608
; ; `eldoc-print-current-symbol-info' later.
@@ -1611,49 +1616,57 @@ use in the eldoc function `haskell-doc-current-info'."
1611
1616
(buffer-substring-no-properties
1612
1617
(region-beginning ) (region-end ))
1613
1618
(thing-at-point 'symbol 'no-properties )))
1614
- (haskell-process-get-type
1615
- sym (lambda (response )
1616
- (setq haskell-doc-current-info--interaction-last
1617
- (cons 'async response))
1618
- (eldoc-print-current-symbol-info )))
1619
- 'async ))))
1620
-
1621
- (defun haskell-process-get-type (expr-string &optional callback )
1619
+ (if sync
1620
+ (haskell-process-get-type sym #'identity t )
1621
+ (haskell-process-get-type
1622
+ sym (lambda (response )
1623
+ (setq haskell-doc-current-info--interaction-last
1624
+ (cons 'async response))
1625
+ (eldoc-print-current-symbol-info )))
1626
+ 'async )))))
1627
+
1628
+ (defun haskell-process-get-type (expr-string &optional callback sync )
1622
1629
" Asynchronously get the type of a given string.
1623
1630
1624
1631
EXPR-STRING should be an expression passed to :type in ghci.
1625
1632
1626
- CALLBACK will be called with a formatted type string."
1633
+ CALLBACK will be called with a formatted type string.
1634
+
1635
+ If SYNC is non-nil, make the call synchronously instead."
1627
1636
(let ((process (haskell-process))
1628
1637
; ; Avoid passing bad strings to ghci
1629
1638
(expr-okay (not (string-match-p " \n " expr-string)))
1630
- (ghci-command (concat " :type " expr-string)))
1639
+ (ghci-command (concat " :type " expr-string))
1640
+ (complete-func
1641
+ (lambda (_ response )
1642
+ ; ; Responses with empty first line are likely errors
1643
+ (if (string-match-p (rx string-start line-end) response)
1644
+ (setq response nil )
1645
+ ; ; Remove a newline at the end
1646
+ (setq response (replace-regexp-in-string " \n \\ '" " " response))
1647
+ ; ; Propertize for eldoc
1648
+ (save-match-data
1649
+ (when (string-match " :: " response)
1650
+ ; ; Highlight type
1651
+ (let ((name (substring response 0 (match-end 0 )))
1652
+ (type (propertize
1653
+ (substring response (match-end 0 ))
1654
+ 'face 'eldoc-highlight-function-argument )))
1655
+ (setq response (concat name type)))))
1656
+ (when haskell-doc-prettify-types
1657
+ (dolist (re '((" ::" . " ∷" ) (" =>" . " ⇒" ) (" ->" . " →" )))
1658
+ (setq response
1659
+ (replace-regexp-in-string (car re) (cdr re) response)))))
1660
+ (when callback (funcall callback response)))))
1631
1661
(when (and process expr-okay)
1632
- (haskell-process-queue-command
1633
- (haskell-process)
1634
- (make-haskell-command
1635
- :go (lambda (_ ) (haskell-process-send-string process ghci-command))
1636
- :complete
1637
- (lambda (_ response )
1638
- ; ; Responses with empty first line are likely errors
1639
- (if (string-match-p (rx string-start line-end) response)
1640
- (setq response nil )
1641
- ; ; Remove a newline at the end
1642
- (setq response (replace-regexp-in-string " \n \\ '" " " response))
1643
- ; ; Propertize for eldoc
1644
- (save-match-data
1645
- (when (string-match " :: " response)
1646
- ; ; Highlight type
1647
- (let ((name (substring response 0 (match-end 0 )))
1648
- (type (propertize
1649
- (substring response (match-end 0 ))
1650
- 'face 'eldoc-highlight-function-argument )))
1651
- (setq response (concat name type)))))
1652
- (when haskell-doc-prettify-types
1653
- (dolist (re '((" ::" . " ∷" ) (" =>" . " ⇒" ) (" ->" . " →" )))
1654
- (setq response
1655
- (replace-regexp-in-string (car re) (cdr re) response)))))
1656
- (when callback (funcall callback response))))))))
1662
+ (if sync
1663
+ (let ((response (haskell-process-queue-sync-request process ghci-command)))
1664
+ (funcall complete-func nil response))
1665
+ (haskell-process-queue-command
1666
+ process
1667
+ (make-haskell-command
1668
+ :go (lambda (_ ) (haskell-process-send-string process ghci-command))
1669
+ :complete complete-func))))))
1657
1670
1658
1671
(defun haskell-doc-sym-doc (sym )
1659
1672
" Show the type of the function near point.
0 commit comments