diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 54c06f90f..573ba5501 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -34,8 +34,10 @@ :desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region :desc "Evaluate & replace region" "E" #'+eval/region-and-replace :desc "Format buffer/region" "f" #'+format/region-or-buffer + :desc "Find implementations" "i" #'+lookup/implementations :desc "Jump to documentation" "k" #'+lookup/documentation :desc "Send to repl" "s" #'+eval/send-region-to-repl + :desc "Find type definition" "t" #'+lookup/type-definition :desc "Delete trailing whitespace" "w" #'delete-trailing-whitespace :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines :desc "List errors" "x" #'flymake-show-diagnostics-buffer @@ -43,7 +45,7 @@ :desc "List errors" "x" #'flycheck-list-errors) (:when (and (featurep! :tools lsp) (not (featurep! :tools lsp +eglot))) :desc "LSP Code actions" "a" #'lsp-execute-code-action - :desc "LSP Organize imports" "i" #'lsp-organize-imports + :desc "LSP Organize imports" "o" #'lsp-organize-imports :desc "LSP Rename" "r" #'lsp-rename (:after lsp-mode :desc "LSP" "l" lsp-command-map) @@ -55,10 +57,8 @@ :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)) + :desc "LSP Find declaration" "j" #'eglot-find-declaration)) ;;; f --- file (:prefix-map ("f" . "file") diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index 143e231df..fbbcb3f59 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -344,9 +344,9 @@ ;;; c --- code (:prefix-map ("c" . "code") - (:unless (featurep! :tools lsp +eglot) + (:when (and (featurep! :tools lsp) (not (featurep! :tools lsp +eglot))) :desc "LSP Execute code action" "a" #'lsp-execute-code-action - :desc "LSP Organize imports" "i" #'lsp-organize-imports + :desc "LSP Organize imports" "o" #'lsp-organize-imports (:when (featurep! :completion ivy) :desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol) @@ -358,10 +358,8 @@ :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) + :desc "LSP Find declaration" "j" #'eglot-find-declaration) :desc "Compile" "c" #'compile :desc "Recompile" "C" #'recompile :desc "Jump to definition" "d" #'+lookup/definition @@ -369,8 +367,10 @@ :desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region :desc "Evaluate & replace region" "E" #'+eval:replace-region :desc "Format buffer/region" "f" #'+format/region-or-buffer + :desc "Find implementations" "i" #'+lookup/implementations :desc "Jump to documentation" "k" #'+lookup/documentation :desc "Send to repl" "s" #'+eval/send-region-to-repl + :desc "Find type definition" "t" #'+lookup/type-definition :desc "Delete trailing whitespace" "w" #'delete-trailing-whitespace :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines :desc "List errors" "x" #'flymake-show-diagnostics-buffer 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 () diff --git a/modules/tools/lsp/+eglot.el b/modules/tools/lsp/+eglot.el index ae37e20d4..9bb4eb92a 100644 --- a/modules/tools/lsp/+eglot.el +++ b/modules/tools/lsp/+eglot.el @@ -17,6 +17,8 @@ :config (set-popup-rule! "^\\*eglot-help" :size 0.35 :quit t :select t) (set-lookup-handlers! 'eglot--managed-mode + :implementations #'eglot-find-implementation + :type-definition #'eglot-find-typeDefinition :documentation #'+eglot/documentation-lookup-handler) (when (featurep! :checkers syntax) (after! flycheck