@@ -1810,14 +1810,14 @@ candidates can be used for PREFIX."
1810
1810
(or (string= prefix " " )
1811
1811
(not (eq (aref prefix (1- (length prefix))) ?\( ))))))
1812
1812
1813
- (defun jupyter-completion-prefetch (fun )
1813
+ (defun jupyter-completion-prefetch (fun &optional client )
1814
1814
" Get completions for the current completion context.
1815
1815
Run FUN when the completions are available."
1816
1816
(cl-destructuring-bind (code pos)
1817
1817
(jupyter-code-context 'completion )
1818
1818
(let ((req (let ((jupyter-inhibit-handlers t ))
1819
1819
(jupyter-send-complete-request
1820
- jupyter-current-client
1820
+ ( or client jupyter-current-client)
1821
1821
:code code :pos pos))))
1822
1822
(prog1 req
1823
1823
(jupyter-add-callback req :complete-reply fun)))))
@@ -1893,6 +1893,29 @@ Run FUN when the completions are available."
1893
1893
:company-doc-buffer
1894
1894
#'jupyter-completion--company-doc-buffer ))))
1895
1895
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
+
1896
1919
(defun jupyter-completion--company-doc-buffer (arg )
1897
1920
" Send an inspect request for ARG to the kernel.
1898
1921
Use the `company-doc-buffer' to insert the results."
0 commit comments