Function: eglot-code-actions
eglot-code-actions is an interactive and byte-compiled function
defined in eglot.el.gz.
Signature
(eglot-code-actions BEG &optional END ACTION-KIND INTERACTIVE)
Documentation
Find LSP code actions of type ACTION-KIND between BEG and END.
Interactively, offer to execute them. If ACTION-KIND is nil, consider all kinds of actions. Interactively, default BEG and END to region's bounds else BEG is point and END is nil, which results in a request for code actions at point. With prefix argument, prompt for ACTION-KIND.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot-code-actions (beg &optional end action-kind interactive)
"Find LSP code actions of type ACTION-KIND between BEG and END.
Interactively, offer to execute them.
If ACTION-KIND is nil, consider all kinds of actions.
Interactively, default BEG and END to region's bounds else BEG is
point and END is nil, which results in a request for code actions
at point. With prefix argument, prompt for ACTION-KIND."
(interactive
`(,@(eglot--code-action-bounds)
,(and current-prefix-arg
(completing-read "[eglot] Action kind: "
'("quickfix" "refactor.extract" "refactor.inline"
"refactor.rewrite" "source.organizeImports")))
t))
(eglot-server-capable-or-lose :codeActionProvider)
(let* ((server (eglot--current-server-or-lose))
(actions
(eglot--request
server
:textDocument/codeAction
(list :textDocument (eglot--TextDocumentIdentifier)
:range (list :start (eglot--pos-to-lsp-position beg)
:end (eglot--pos-to-lsp-position end))
:context
`(:diagnostics
[,@(cl-loop for diag in (flymake-diagnostics beg end)
when (cdr (assoc 'eglot-lsp-diag
(eglot--diag-data diag)))
collect it)]
,@(when action-kind `(:only [,action-kind]))))))
;; Redo filtering, in case the `:only' didn't go through.
(actions (cl-loop for a across actions
when (or (not action-kind)
;; github#847
(string-prefix-p action-kind (plist-get a :kind)))
collect a)))
(if interactive
(eglot--read-execute-code-action actions server action-kind)
actions)))