Function: dape--repl-completion-at-point
dape--repl-completion-at-point is a natively compiled function defined
in dape.el.
Signature
(dape--repl-completion-at-point)
Documentation
Completion at point function for dape-repl-mode.
Source Code
;; Defined in /nix/store/1fiaif8pifqj2jh65rbg3fkhg3i56q42-emacs-packages-deps/share/emacs/site-lisp/elpa/dape-0.27.1/dape.el
(defun dape--repl-completion-at-point ()
"Completion at point function for `dape-repl-mode'."
(when-let* ((conn (or (dape--live-connection 'stopped t)
(dape--live-connection 'last t)))
((dape--capable-p conn :supportsCompletionsRequest)))
(let* ((line-start (comint-line-beginning-position))
(str (buffer-substring-no-properties line-start (point-max)))
(column (1+ (- (point) line-start)))
(bounds (or (bounds-of-thing-at-point 'word)
(cons (point) (point))))
(trigger-chars
(or (thread-first conn
(dape--capabilities)
;; completionTriggerCharacters is an
;; unofficial array of string to trigger
;; completion on.
(plist-get :completionTriggerCharacters)
(append nil))
'(".")))
(collection
(when (and (derived-mode-p 'dape-repl-mode)
;; Add `dape-repl-commands' if completion
;; starts at beginning of prompt line.
(eql (comint-line-beginning-position) (car bounds)))
(cl-loop
with alist = (append dape-repl-commands
(when dape-repl-use-shorthand
(dape--repl-shorthand-alist)))
for (name . cmd) in alist
for anno = (propertize (symbol-name cmd)
'face 'font-lock-builtin-face)
collect `( ,name . ,(concat " " anno)))))
done)
(dape--with-request-bind
((&key targets &allow-other-keys) _error)
(dape-request
conn :completions
`( :text ,str
:column ,column
,@(when (dape--stopped-threads conn)
`(:frameId
,(plist-get (dape--current-stack-frame conn) :id)))))
(setf collection
(append
collection
(mapcar
(lambda (target)
(cons
(substring
(or (plist-get target :text) (plist-get target :label))
(when-let* ((start (plist-get target :start))
(offset (- (car bounds) line-start))
;; XXX Assume server sends both start
;; and length (vscode convention) or
;; bail. Seems successful in
;; identifying misbehaving servers
;; (e.g. jdtls).
((plist-get target :length))
((< start offset)))
;; XXX Adapter gets line but Emacs completion is
;; given `word' bounds, cut prefix off candidate
;; such that it matches the bounds.
(- offset start)))
(concat
(when-let* ((type (plist-get target :type)))
(concat " " (propertize type 'face 'font-lock-type-face)))
(when-let* ((detail (plist-get target :detail)))
(concat " " (propertize detail 'face 'font-lock-doc-face))))))
targets))
done t))
(while-no-input
(while (not done) (accept-process-output nil 0 1)))
(list (car bounds) (cdr bounds) collection
:annotation-function
(lambda (str) (cdr (assoc (substring-no-properties str) collection)))
:company-prefix-length
(save-excursion
(goto-char (car bounds))
(looking-back (regexp-opt trigger-chars) line-start))))))