Commit 8b69cc62 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Handle "complete_request" messages.

* guix-jupyter-kernel.scm (reply-complete-request): New procedure.
(dispatch-route): Add it.
parent e9192924
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
(srfi srfi-1) (srfi srfi-1)
(srfi srfi-13) (srfi srfi-13)
(srfi srfi-19) (srfi srfi-19)
(srfi srfi-26)
(srfi srfi-71) (srfi srfi-71)
(rnrs bytevectors) (rnrs bytevectors)
(ice-9 match) (ice-9 match)
...@@ -295,6 +296,66 @@ to execute:" ...@@ -295,6 +296,66 @@ to execute:"
count) count)
state)))))) state))))))
(define (reply-complete-request kernel kind message state)
"Reply to a \"complete_request\" message--i.e., a completion request.
Return STATE."
(define (environment-from-magic line)
(match (string-tokenize line)
((";;guix" "environment" name) name)
(_ #f)))
(define (send-completion-reply matches start end)
(format/log "sending completion reply with ~a matches~%"
(length matches))
(send-message kernel
(reply message "complete_reply"
`(("matches" . ,(list->vector matches))
("cursor_start" . ,start)
("cursor_end" . ,end)
("metadata" . ())
("status" . "ok"))))
#:recipient (message-sender message)))
(let* ((content (json-string->scm (message-content message)))
(code (assoc-ref content "code"))
(cursor (assoc-ref content "cursor_pos"))
(line-end (or (string-index code #\newline)
(string-length code)))
(first (string-take code line-end)))
(if (and (string-prefix? ";;guix" (string-trim first))
(<= cursor line-end))
;; This is a completion request on a ";;guix" magic.
(match (string-split (string-take first cursor) #\space)
((";;guix" command)
(send-completion-reply '("environment")
(- cursor (string-length command))
((";;guix" "environment" prefix)
(match (proxy-state-proxied state)
(((names . _) ...)
(send-completion-reply (filter (cut string-prefix? prefix <>)
(- cursor (string-length prefix))
(format/log "ignoring completion request~%")
;; Pass the completion request to one of the proxied kernels.
(match (or (environment-from-magic first)
(proxy-state-default-environment state))
((? string? environment)
(let ((proxied (lookup-proxied environment state)))
(format/log "forwarding completion request to \
environment ~s (PID ~s)~%"
environment (kernel-pid proxied))
(send-message proxied message #:kernel-socket kind)))
(format/log "unknown target kernel for completion request~%")))))
(define (shutdown kernel kind message state) (define (shutdown kernel kind message state)
(format/log "shutting down ~a containers~%" (format/log "shutting down ~a containers~%"
(proxy-state-proxied-number state)) (proxy-state-proxied-number state))
...@@ -308,6 +369,7 @@ to execute:" ...@@ -308,6 +369,7 @@ to execute:"
`(("kernel_info_request" . ,reply-kernel-info-request) `(("kernel_info_request" . ,reply-kernel-info-request)
("execute_request" . ,reply-execute-request) ("execute_request" . ,reply-execute-request)
("shutdown_request" . ,shutdown) ("shutdown_request" . ,shutdown)
("complete_request" . ,reply-complete-request)
("comm_info_request" . ,ignore-request))) ("comm_info_request" . ,ignore-request)))
;; ;;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment