diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index daa56458f..469aa9852 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -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)) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index f5ffe7a61..bb34789af 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -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) diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index ab97478a8..efc5c1982 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -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 ()