Skip to content

Commit 797d5b4

Browse files
committed
Be safer when handling types during completion
* jupyter-client.el (jupyter-completion-construct-candidates): Don't allow a potential call to `max` with zero arguments. Consider the potential that there may not be types for all matches. In this case, the type information displayed will be wrong for some matches and not appear for others. In the type information there is available the actual match that it is supposed to be associated with which could be used to assign the type information to the exact match.
1 parent c672610 commit 797d5b4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

jupyter-client.el

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,16 @@ supplied by the kernel."
15191519
(aset matches i (car (last (split-string match "\\.")))))))
15201520
(when buf (kill-buffer buf))))
15211521
;; When a type is supplied add it as an annotation
1522-
(when-let* ((types (plist-get metadata :_jupyter_types_experimental)))
1523-
(let ((max-len (apply #'max (mapcar #'length matches))))
1522+
(when-let* ((types (plist-get metadata :_jupyter_types_experimental))
1523+
(lengths (mapcar #'length matches)))
1524+
(let ((max-len (apply #'max lengths)))
15241525
(cl-loop
1525-
for i from 0 below (length matches)
1526+
for i from 0 below
1527+
;; For safety, ensure the lengths are the same which is
1528+
;; usually the case, but sometimes a kernel may not return
1529+
;; lists of the same length. Seen for example in IJulia.
1530+
(min (length matches) (length types))
1531+
;; These are typically in the same order.
15261532
for match = (aref matches i)
15271533
for meta = (aref types i)
15281534
do (let* ((prefix (make-string (1+ (- max-len (length match))) ?\s))
@@ -1532,6 +1538,9 @@ supplied by the kernel."
15321538
0 1 'docsig
15331539
(concat (get-text-property 0 'docsig match) sig) match)
15341540
(put-text-property 0 1 'annot annot match)))))
1541+
;; FIXME To get rid of this conversion use `json-array-type', be
1542+
;; sure to change places where it is assumed that there are
1543+
;; vectors.
15351544
(append matches nil)))
15361545

15371546
;;;;; Completion at point interface

0 commit comments

Comments
 (0)