mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 23:41:38 -05:00
Be less ambiguous when encoding/decoding messages
- Do not handle nil as an empty dictionary when encoding. - Use the default `json-array-type`
This commit is contained in:
parent
554e519bf0
commit
17596ee1c4
4 changed files with 23 additions and 21 deletions
|
@ -336,15 +336,12 @@ the ROUTING-ID of the socket. Return the created socket."
|
||||||
|
|
||||||
(defun jupyter-read-plist (file)
|
(defun jupyter-read-plist (file)
|
||||||
"Read a JSON encoded FILE as a property list."
|
"Read a JSON encoded FILE as a property list."
|
||||||
(let ((json-object-type 'plist)
|
(let ((json-object-type 'plist))
|
||||||
(json-array-type 'list)
|
|
||||||
(json-false nil))
|
|
||||||
(json-read-file file)))
|
(json-read-file file)))
|
||||||
|
|
||||||
(defun jupyter-read-plist-from-string (string)
|
(defun jupyter-read-plist-from-string (string)
|
||||||
(let ((json-object-type 'plist)
|
"Read a property list from a JSON encoded STRING."
|
||||||
;; TODO: See the comment in `jupyter--decode'
|
(let ((json-object-type 'plist))
|
||||||
(json-array-type 'list))
|
|
||||||
(json-read-from-string string)))
|
(json-read-from-string string)))
|
||||||
|
|
||||||
(provide 'jupyter-base)
|
(provide 'jupyter-base)
|
||||||
|
|
|
@ -200,7 +200,7 @@ kernel. Starting a kernel involves the following steps:
|
||||||
(proc (jupyter--start-kernel
|
(proc (jupyter--start-kernel
|
||||||
manager kernel-name (plist-get spec :env)
|
manager kernel-name (plist-get spec :env)
|
||||||
(cl-loop
|
(cl-loop
|
||||||
for arg in (plist-get spec :argv)
|
for arg in (append (plist-get spec :argv) nil)
|
||||||
if (equal arg "{connection_file}")
|
if (equal arg "{connection_file}")
|
||||||
collect conn-file
|
collect conn-file
|
||||||
else if (equal arg "{resource_dir}")
|
else if (equal arg "{resource_dir}")
|
||||||
|
|
|
@ -91,8 +91,7 @@ They are all set to appropriate default values."
|
||||||
(cl-letf (((symbol-function 'json-encode)
|
(cl-letf (((symbol-function 'json-encode)
|
||||||
(lambda (object)
|
(lambda (object)
|
||||||
(cond ((memq object (list t json-null json-false))
|
(cond ((memq object (list t json-null json-false))
|
||||||
(if (eq object json-null) "{}"
|
(json-encode-keyword object))
|
||||||
(json-encode-keyword object)))
|
|
||||||
((stringp object) (json-encode-string object))
|
((stringp object) (json-encode-string object))
|
||||||
((keywordp object)
|
((keywordp object)
|
||||||
;; Handle `jupyter-message-type'
|
;; Handle `jupyter-message-type'
|
||||||
|
@ -107,14 +106,16 @@ They are all set to appropriate default values."
|
||||||
((listp object) (json-encode-list object))
|
((listp object) (json-encode-list object))
|
||||||
(t (signal 'json-error (list object)))))))
|
(t (signal 'json-error (list object)))))))
|
||||||
(encode-coding-string
|
(encode-coding-string
|
||||||
(if (stringp object) object (json-encode-plist object))
|
(cond
|
||||||
|
((stringp object) object)
|
||||||
|
;; FIXME: This seems expensive
|
||||||
|
((json-plist-p object) (json-encode-plist object))
|
||||||
|
(t (json-encode object)))
|
||||||
'utf-8 t)))
|
'utf-8 t)))
|
||||||
|
|
||||||
(defun jupyter--decode (str)
|
(defun jupyter--decode (str)
|
||||||
(setq str (decode-coding-string str 'utf-8))
|
(setq str (decode-coding-string str 'utf-8))
|
||||||
(let* ((json-object-type 'plist)
|
(let* ((json-object-type 'plist)
|
||||||
(json-array-type 'list)
|
|
||||||
(json-false nil)
|
|
||||||
(val (condition-case nil
|
(val (condition-case nil
|
||||||
(json-read-from-string str)
|
(json-read-from-string str)
|
||||||
;; If it can't be read as JSON, assume its just a regular
|
;; If it can't be read as JSON, assume its just a regular
|
||||||
|
@ -233,7 +234,9 @@ They are all set to appropriate default values."
|
||||||
code
|
code
|
||||||
(silent nil)
|
(silent nil)
|
||||||
(store-history t)
|
(store-history t)
|
||||||
(user-expressions nil)
|
;; This needs to be an empty
|
||||||
|
;; dictionary is not specified
|
||||||
|
(user-expressions #s(hash-table))
|
||||||
(allow-stdin t)
|
(allow-stdin t)
|
||||||
(stop-on-error nil))
|
(stop-on-error nil))
|
||||||
(cl-check-type code string)
|
(cl-check-type code string)
|
||||||
|
|
|
@ -957,7 +957,7 @@ lines then truncate it to something less than
|
||||||
(defun jupyter-repl--handle-payload (payload)
|
(defun jupyter-repl--handle-payload (payload)
|
||||||
"Do the client actions in PAYLOAD."
|
"Do the client actions in PAYLOAD."
|
||||||
(cl-loop
|
(cl-loop
|
||||||
for pl in payload
|
for pl across payload
|
||||||
do (pcase (plist-get pl :source)
|
do (pcase (plist-get pl :source)
|
||||||
("page"
|
("page"
|
||||||
(let ((text (plist-get (plist-get pl :data) :text/plain))
|
(let ((text (plist-get (plist-get pl :data) :text/plain))
|
||||||
|
@ -1226,7 +1226,8 @@ REPL buffer."
|
||||||
|
|
||||||
(cl-defmethod jupyter-handle-history-reply ((client jupyter-repl-client) _req history)
|
(cl-defmethod jupyter-handle-history-reply ((client jupyter-repl-client) _req history)
|
||||||
(with-jupyter-repl-buffer client
|
(with-jupyter-repl-buffer client
|
||||||
(cl-loop for (_session _line-number input-output) in history
|
(cl-loop for elem across history
|
||||||
|
for input-output = (aref elem 2)
|
||||||
do (ring-remove+insert+extend jupyter-repl-history input-output))))
|
do (ring-remove+insert+extend jupyter-repl-history input-output))))
|
||||||
|
|
||||||
(cl-defmethod jupyter-handle-is-complete-reply ((client jupyter-repl-client) _req status indent)
|
(cl-defmethod jupyter-handle-is-complete-reply ((client jupyter-repl-client) _req status indent)
|
||||||
|
@ -1480,12 +1481,13 @@ value that PREFIX takes.
|
||||||
|
|
||||||
This function constructs candidates assuming that `company-mode'
|
This function constructs candidates assuming that `company-mode'
|
||||||
is used for completion."
|
is used for completion."
|
||||||
(let ((types (plist-get metadata :_jupyter_types_experimental))
|
(let* ((matches (append matches nil))
|
||||||
(tail matches)
|
(tail matches)
|
||||||
;; TODO: Handle the case when the matches are method signatures in the
|
(types (append (plist-get metadata :_jupyter_types_experimental) nil))
|
||||||
;; Julia kernel. This information would be useful for doing some kind
|
;; TODO: Handle the case when the matches are method signatures in the
|
||||||
;; of eldoc like feature.
|
;; Julia kernel. This information would be useful for doing some kind
|
||||||
(match-prefix-len (- (- end start) (length prefix))))
|
;; of eldoc like feature.
|
||||||
|
(match-prefix-len (- (- end start) (length prefix))))
|
||||||
;; FIXME: How to complete things like 000|? In the python kernel,
|
;; FIXME: How to complete things like 000|? In the python kernel,
|
||||||
;; completions will return matchs to append like and, or, ... but the
|
;; completions will return matchs to append like and, or, ... but the
|
||||||
;; prefix 000 was provided so company will replace 000 with the match if it
|
;; prefix 000 was provided so company will replace 000 with the match if it
|
||||||
|
|
Loading…
Add table
Reference in a new issue