Skip to content

Commit 72b84b8

Browse files
committed
WIP: completing-read for jupyter-describe
1 parent 362f42d commit 72b84b8

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

jupyter-client.el

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,14 +1810,14 @@ candidates can be used for PREFIX."
18101810
(or (string= prefix "")
18111811
(not (eq (aref prefix (1- (length prefix))) ?\())))))
18121812

1813-
(defun jupyter-completion-prefetch (fun)
1813+
(defun jupyter-completion-prefetch (fun &optional client)
18141814
"Get completions for the current completion context.
18151815
Run FUN when the completions are available."
18161816
(cl-destructuring-bind (code pos)
18171817
(jupyter-code-context 'completion)
18181818
(let ((req (let ((jupyter-inhibit-handlers t))
18191819
(jupyter-send-complete-request
1820-
jupyter-current-client
1820+
(or client jupyter-current-client)
18211821
:code code :pos pos))))
18221822
(prog1 req
18231823
(jupyter-add-callback req :complete-reply fun)))))
@@ -1893,6 +1893,29 @@ Run FUN when the completions are available."
18931893
:company-doc-buffer
18941894
#'jupyter-completion--company-doc-buffer))))
18951895

1896+
(defun jupyter--completing-function (client)
1897+
"Return function for `completion-table-dynamic' using CLIENT.
1898+
Returned function can be used with `completion-table-dynamic' to
1899+
complete results using jupyter CLIENT as backend."
1900+
(lambda (prefix)
1901+
(let* (prefetch-cache
1902+
(req (jupyter-completion-prefetch
1903+
(lambda (msg)
1904+
(setq prefetch-cache msg))
1905+
client)))
1906+
(and req (not (jupyter-request-idle-received-p req))
1907+
(not (eq (jupyter-message-type
1908+
(jupyter-request-last-message req))
1909+
:complete-reply))
1910+
;; Introduce a delay so that we give a chance for the
1911+
;; :complete-reply message to get handled.
1912+
(sit-for 0.1))
1913+
(and prefetch-cache
1914+
(jupyter-with-message-content prefetch-cache
1915+
(status matches metadata)
1916+
(and (equal status "ok")
1917+
(jupyter-completion-construct-candidates matches metadata)))))))
1918+
18961919
(defun jupyter-completion--company-doc-buffer (arg)
18971920
"Send an inspect request for ARG to the kernel.
18981921
Use the `company-doc-buffer' to insert the results."

0 commit comments

Comments
 (0)