mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 23:41:38 -05:00
Refactor jupyter-repl-construct-completion-candidates
This commit is contained in:
parent
c0e4383c49
commit
f77e5dc22e
1 changed files with 22 additions and 24 deletions
|
@ -1373,32 +1373,30 @@ is actually sent to the kernel."
|
||||||
'(?w ?_ ?.)))
|
'(?w ?_ ?.)))
|
||||||
""))))))
|
""))))))
|
||||||
|
|
||||||
(defun jupyter-repl-construct-completion-candidates (prefix matches metadata start end)
|
(defun jupyter-repl-construct-completion-candidates
|
||||||
"Construct candidates for `company-mode' completion.
|
(prefix matches metadata start end)
|
||||||
|
"Construct candidates for completion.
|
||||||
PREFIX is the prefix used to start the current completion.
|
PREFIX is the prefix used to start the current completion.
|
||||||
MATCHES are the completion matches returned by the kernel,
|
MATCHES are the completion matches returned by the kernel,
|
||||||
METADATA is any extra data associated with MATCHES and is
|
METADATA is any extra data associated with MATCHES that was
|
||||||
currently used for adding annotations to each candidate. START
|
supplied by the kernel. START and END are the start and end of
|
||||||
and END are the start and end of text that the elements of
|
text that the elements of MATCHES will replace. Note that START
|
||||||
MATCHES should be replace as reported by the kernel. Note that
|
and END are relative to the `jupyter-repl-code-context-at-point'
|
||||||
START and END are relative to the
|
and not to PREFIX. See `jupyter-repl-completion-prefix' for the
|
||||||
`jupyter-repl-code-context-at-point' and not to PREFIX. See
|
value that PREFIX takes.
|
||||||
`jupyter-repl-completion-prefix' for the value that PREFIX
|
|
||||||
takes."
|
This function constructs candidates assuming that `company-mode'
|
||||||
(let ((types (plist-get metadata :_jupyter_types_experimental)))
|
is used for completion."
|
||||||
(let ((matches matches)
|
(let ((types (plist-get metadata :_jupyter_types_experimental))
|
||||||
(prefix (substring prefix 0 (- (length prefix)
|
(tail matches)
|
||||||
(- end start))))
|
(prefix (substring prefix 0 (- (length prefix) (- end start))))
|
||||||
match)
|
(match nil))
|
||||||
(while (setq match (car matches))
|
;; Set the prefix on the match if needed
|
||||||
;; TODO: Maybe set the match property when it doesn't have the prefix,
|
(while (setq match (car tail))
|
||||||
;; indicating that it should replace part of the prefix?
|
|
||||||
(unless (string-prefix-p prefix match)
|
(unless (string-prefix-p prefix match)
|
||||||
;; FIXME: Note that prefix is not the code sent to the kernel in some
|
|
||||||
;; cases, but the symbol behind point
|
|
||||||
(setcar matches (concat prefix (car matches))))
|
(setcar matches (concat prefix (car matches))))
|
||||||
;; (put-text-property 0 1 'match match-start (car matches))
|
(setq tail (cdr tail)))
|
||||||
(setq matches (cdr matches))))
|
;; When a type is supplied add it as an annotation
|
||||||
(when types
|
(when types
|
||||||
(let ((max-len (apply #'max (mapcar #'length matches))))
|
(let ((max-len (apply #'max (mapcar #'length matches))))
|
||||||
(cl-mapc
|
(cl-mapc
|
||||||
|
|
Loading…
Add table
Reference in a new issue