Commit aedb7e6f authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

Handle 'inspect_request' messages.

* guix-jupyter-kernel.scm (environment-from-magic): New procedure, moved
(reply-complete-request)[environment-from-magic]: ... here.  Remove.
(reply-inspect-request): New procedure.
(dispatch-route): Add it.
parent d4f4ee22
......@@ -295,14 +295,14 @@ to execute:"
(define (environment-from-magic line)
(match (string-tokenize line)
((";;guix" "environment" name) name)
(_ #f)))
(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))
......@@ -362,6 +362,38 @@ environment ~s (PID ~s)~%"
(format/log "unknown target kernel for completion request~%")))))
(define (reply-inspect-request kernel kind message state)
"Handle MESSAGE, an \"inspect_request\" message, possibly by forwarding it
to a proxied kernel. Return STATE."
(let* ((request (json->inspect-request (message-content message)))
(code (inspect-request-code request))
(cursor (inspect-request-cursor-position request))
(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))
(format/log "ignoring inspection request on magic line~%")
(send-message kernel
(reply message "inspect_reply"
(inspect-reply (status 'ok) (found? #f)))))))
;; 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 inspection 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)
(format/log "shutting down ~a containers~%"
(proxy-state-proxied-number state))
......@@ -376,6 +408,7 @@ environment ~s (PID ~s)~%"
("execute_request" . ,reply-execute-request)
("shutdown_request" . ,shutdown)
("complete_request" . ,reply-complete-request)
("inspect_request" . ,reply-inspect-request)
("comm_info_request" . ,ignore-request)))
Supports Markdown
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