editor/format: Use eglot LSP formatter
This commit is contained in:
parent
d3b1664081
commit
6798966f78
3 changed files with 21 additions and 15 deletions
|
@ -55,7 +55,6 @@
|
|||
:desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol))
|
||||
(:when (featurep! :tools lsp +eglot)
|
||||
:desc "LSP Execute code action" "a" #'eglot-code-actions
|
||||
:desc "LSP Format buffer/region" "F" #'eglot-format
|
||||
:desc "LSP Rename" "r" #'eglot-rename
|
||||
:desc "LSP Find declaration" "j" #'eglot-find-declaration
|
||||
:desc "LSP Find implementation" "J" #'eglot-find-implementation))
|
||||
|
|
|
@ -358,7 +358,6 @@
|
|||
:desc "LSP" "l" lsp-command-map))
|
||||
(:when (featurep! :tools lsp +eglot)
|
||||
:desc "LSP Execute code action" "a" #'eglot-code-actions
|
||||
:desc "LSP Format buffer/region" "F" #'eglot-format
|
||||
:desc "LSP Rename" "r" #'eglot-rename
|
||||
:desc "LSP Find declaration" "j" #'eglot-find-declaration
|
||||
:desc "LSP Find implementation" "J" #'eglot-find-implementation)
|
||||
|
|
|
@ -206,11 +206,15 @@ See `+format/buffer' for the interactive version of this function, and
|
|||
"Reformat the current buffer using LSP or `format-all-buffer'."
|
||||
(interactive)
|
||||
(call-interactively
|
||||
(if (and +format-with-lsp
|
||||
(bound-and-true-p lsp-mode)
|
||||
(lsp-feature? "textDocument/formatting"))
|
||||
#'lsp-format-buffer
|
||||
#'format-all-buffer)))
|
||||
(cond ((and +format-with-lsp
|
||||
(bound-and-true-p lsp-mode)
|
||||
(lsp-feature? "textDocument/formatting"))
|
||||
#'lsp-format-buffer)
|
||||
((and +format-with-lsp
|
||||
(bound-and-true-p eglot--managed-mode)
|
||||
(eglot--server-capable :documentFormattingProvider))
|
||||
#'eglot-format-buffer)
|
||||
(t #'format-all-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +format/region (beg end)
|
||||
|
@ -220,14 +224,18 @@ WARNING: this may not work everywhere. It will throw errors if the region
|
|||
contains a syntax error in isolation. It is mostly useful for formatting
|
||||
snippets or single lines."
|
||||
(interactive "rP")
|
||||
(if (and +format-with-lsp
|
||||
(bound-and-true-p lsp-mode)
|
||||
(lsp-feature? "textDocument/rangeFormatting"))
|
||||
(call-interactively #'lsp-format-region)
|
||||
(save-restriction
|
||||
(narrow-to-region beg end)
|
||||
(let ((+format-region-p t))
|
||||
(+format/buffer)))))
|
||||
(cond ((and +format-with-lsp
|
||||
(bound-and-true-p lsp-mode)
|
||||
(lsp-feature? "textDocument/rangeFormatting"))
|
||||
(call-interactively #'lsp-format-region))
|
||||
((and +format-with-lsp
|
||||
(bound-and-true-p eglot--managed-mode)
|
||||
(eglot--server-capable :documentRangeFormattingProvider))
|
||||
(call-interactively #'eglot-format))
|
||||
(t (save-restriction
|
||||
(narrow-to-region beg end)
|
||||
(let ((+format-region-p t))
|
||||
(+format/buffer))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +format/region-or-buffer ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue