Function: eglot-format
eglot-format is an interactive and byte-compiled function defined in
eglot.el.gz.
Signature
(eglot-format &optional BEG END ON-TYPE-FORMAT)
Documentation
Format region BEG END.
If either BEG or END is nil, format entire buffer. Interactively, format active region, or entire buffer if region is not active.
If non-nil, ON-TYPE-FORMAT is a character just inserted at BEG for which LSP on-type-formatting should be requested.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot-format (&optional beg end on-type-format)
"Format region BEG END.
If either BEG or END is nil, format entire buffer.
Interactively, format active region, or entire buffer if region
is not active.
If non-nil, ON-TYPE-FORMAT is a character just inserted at BEG
for which LSP on-type-formatting should be requested."
(interactive (and (region-active-p) (list (region-beginning) (region-end))))
(pcase-let ((`(,method ,cap ,args)
(cond
((and beg on-type-format)
`(:textDocument/onTypeFormatting
:documentOnTypeFormattingProvider
,`(:position ,(eglot--pos-to-lsp-position beg)
:ch ,(string on-type-format))))
((and beg end)
`(:textDocument/rangeFormatting
:documentRangeFormattingProvider
(:range ,(eglot-region-range beg end))))
(t
'(:textDocument/formatting :documentFormattingProvider nil)))))
(eglot-server-capable-or-lose cap)
(eglot--apply-text-edits
(eglot--request
(eglot--current-server-or-lose)
method
(cl-list*
:textDocument (eglot--TextDocumentIdentifier)
:options (list :tabSize tab-width
:insertSpaces (if indent-tabs-mode :json-false t)
:insertFinalNewline (if require-final-newline t :json-false)
:trimFinalNewlines (if delete-trailing-lines t :json-false))
args))
nil
on-type-format)))