Skip to content

Commit 4a78aac

Browse files
authored
query type information asynchronous to make eldoc nice (#93)
1 parent 771b238 commit 4a78aac

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

psc-ide.el

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@ in a buffer"
217217
(defun psc-ide-show-type (expand)
218218
"Show type of the symbol under cursor."
219219
(interactive "P")
220-
(let ((ident (psc-ide-ident-at-point)))
221-
(-if-let (type-description (psc-ide-show-type-impl ident expand))
222-
(message "%s" (psc-ide-string-fontified type-description))
223-
(message "Know nothing about type of `%s'." ident))))
220+
(psc-ide-show-type-impl (psc-ide-ident-at-point) t expand))
224221

225222
(defun psc-ide-goto-definition ()
226223
"Go to definition of the symbol under cursor."
@@ -303,9 +300,7 @@ nicely displayed inside a compilation buffer."
303300

304301
(defun psc-ide-show-type-eldoc ()
305302
"Show type of the symbol under cursor, but be quiet about failures"
306-
(let ((ident (psc-ide-ident-at-point)))
307-
(-when-let (type-description (psc-ide-show-type-impl ident))
308-
(message "%s" (psc-ide-string-fontified type-description)))))
303+
(psc-ide-show-type-impl (psc-ide-ident-at-point)))
309304

310305
(defun psc-ide-case-split-impl (type)
311306
"Case Split on identifier under cursor"
@@ -549,18 +544,22 @@ passes it into the callback"
549544
(forward-char (1- column)))
550545
(message (format "No position information for %s" search)))))))
551546

552-
(defun psc-ide-show-type-impl (search &optional expand)
553-
"Returns a string that describes the type of SEARCH.
554-
Returns NIL if the type of SEARCH is not found."
555-
(let* ((resp (psc-ide-send-sync
556-
(psc-ide-build-type-command search)))
557-
(result (psc-ide-unwrap-result resp)))
558-
(when (not (zerop (length result)))
559-
(let* ((completion (aref result 0))
560-
(type (cdr (assoc (if expand 'expandedType 'type) completion)))
561-
(module (cdr (assoc 'module completion)))
562-
(identifier (cdr (assoc 'identifier completion))))
563-
(s-concat module "." identifier " :: \n " type)))))
547+
(defun psc-ide-show-type-impl (search &optional warn expand)
548+
"Prints a message that describes the type of SEARCH.
549+
If the type of SEARCH is not found it prints a warning depending
550+
on whether WARN is true."
551+
(let ((handler
552+
(lambda (resp)
553+
(let ((result (psc-ide-unwrap-result resp)))
554+
(if (not (zerop (length result)))
555+
(let-alist (aref result 0)
556+
(message (psc-ide-string-fontified
557+
(format "%s.%s ::\n %s"
558+
.module
559+
.identifier
560+
(if expand .expandedType .type)))))
561+
(when warn (message "Know nothing about type of `%s'." search)))))))
562+
(psc-ide-send (psc-ide-build-type-command search) handler)))
564563

565564
(defun psc-ide-build-type-command (search)
566565
"Builds a type command from SEARCH."

test/psc-ide-test.el

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ import Halogen.HTML.Events.Indexed as P
2727
(psc-ide-test-example-with-buffer
2828
(lambda () (psc-ide-parse-imports-in-buffer))))
2929

30-
(ert-deftest psc-ide-show-type-impl-test ()
31-
(with-mock
32-
(mock (psc-ide-send-sync *) => (json-read-from-string "{\"result\":[{\"type\":\"Show-Type\",\"module\":\"Module\",\"identifier\":\"something\"}],\"resultType\":\"success\"}\n"))
33-
(should (string= "Module.something :: \n Show-Type"
34-
(psc-ide-show-type-impl "something"))))
35-
36-
(with-mock
37-
(mock (psc-ide-send-sync *) => (json-read-from-string "{\"result\":[],\"resultType\":\"success\"}\n"))
38-
(should (not (psc-ide-show-type-impl "something")))))
39-
40-
4130
;; Module import parsing tests
4231

4332
(ert-deftest test-get-import-matches-in-buffer-should-return-all-imports ()

0 commit comments

Comments
 (0)