Merge pull request #3249 from sei40kr/eglot-improve

tools/lsp: improve eglot support
This commit is contained in:
Henrik Lissner 2020-07-22 20:41:22 -04:00 committed by GitHub
commit 2a325167f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 22 deletions

View file

@ -34,8 +34,10 @@
:desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region :desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region
:desc "Evaluate & replace region" "E" #'+eval/region-and-replace :desc "Evaluate & replace region" "E" #'+eval/region-and-replace
:desc "Format buffer/region" "f" #'+format/region-or-buffer :desc "Format buffer/region" "f" #'+format/region-or-buffer
:desc "Find implementations" "i" #'+lookup/implementations
:desc "Jump to documentation" "k" #'+lookup/documentation :desc "Jump to documentation" "k" #'+lookup/documentation
:desc "Send to repl" "s" #'+eval/send-region-to-repl :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 whitespace" "w" #'delete-trailing-whitespace
:desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines
:desc "List errors" "x" #'flymake-show-diagnostics-buffer :desc "List errors" "x" #'flymake-show-diagnostics-buffer
@ -43,7 +45,7 @@
:desc "List errors" "x" #'flycheck-list-errors) :desc "List errors" "x" #'flycheck-list-errors)
(:when (and (featurep! :tools lsp) (not (featurep! :tools lsp +eglot))) (:when (and (featurep! :tools lsp) (not (featurep! :tools lsp +eglot)))
:desc "LSP Code actions" "a" #'lsp-execute-code-action :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 :desc "LSP Rename" "r" #'lsp-rename
(:after lsp-mode (:after lsp-mode
:desc "LSP" "l" lsp-command-map) :desc "LSP" "l" lsp-command-map)
@ -55,10 +57,8 @@
:desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol)) :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol))
(:when (featurep! :tools lsp +eglot) (:when (featurep! :tools lsp +eglot)
:desc "LSP Execute code action" "a" #'eglot-code-actions :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 Rename" "r" #'eglot-rename
:desc "LSP Find declaration" "j" #'eglot-find-declaration :desc "LSP Find declaration" "j" #'eglot-find-declaration))
:desc "LSP Find implementation" "J" #'eglot-find-implementation))
;;; <leader> f --- file ;;; <leader> f --- file
(:prefix-map ("f" . "file") (:prefix-map ("f" . "file")

View file

@ -344,9 +344,9 @@
;;; <leader> c --- code ;;; <leader> c --- code
(:prefix-map ("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 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) (:when (featurep! :completion ivy)
:desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol :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) :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol)
@ -358,10 +358,8 @@
:desc "LSP" "l" lsp-command-map)) :desc "LSP" "l" lsp-command-map))
(:when (featurep! :tools lsp +eglot) (:when (featurep! :tools lsp +eglot)
:desc "LSP Execute code action" "a" #'eglot-code-actions :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 Rename" "r" #'eglot-rename
:desc "LSP Find declaration" "j" #'eglot-find-declaration :desc "LSP Find declaration" "j" #'eglot-find-declaration)
:desc "LSP Find implementation" "J" #'eglot-find-implementation)
:desc "Compile" "c" #'compile :desc "Compile" "c" #'compile
:desc "Recompile" "C" #'recompile :desc "Recompile" "C" #'recompile
:desc "Jump to definition" "d" #'+lookup/definition :desc "Jump to definition" "d" #'+lookup/definition
@ -369,8 +367,10 @@
:desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region :desc "Evaluate buffer/region" "e" #'+eval/buffer-or-region
:desc "Evaluate & replace region" "E" #'+eval:replace-region :desc "Evaluate & replace region" "E" #'+eval:replace-region
:desc "Format buffer/region" "f" #'+format/region-or-buffer :desc "Format buffer/region" "f" #'+format/region-or-buffer
:desc "Find implementations" "i" #'+lookup/implementations
:desc "Jump to documentation" "k" #'+lookup/documentation :desc "Jump to documentation" "k" #'+lookup/documentation
:desc "Send to repl" "s" #'+eval/send-region-to-repl :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 whitespace" "w" #'delete-trailing-whitespace
:desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines :desc "Delete trailing newlines" "W" #'doom/delete-trailing-newlines
:desc "List errors" "x" #'flymake-show-diagnostics-buffer :desc "List errors" "x" #'flymake-show-diagnostics-buffer

View file

@ -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'." "Reformat the current buffer using LSP or `format-all-buffer'."
(interactive) (interactive)
(call-interactively (call-interactively
(if (and +format-with-lsp (cond ((and +format-with-lsp
(bound-and-true-p lsp-mode) (bound-and-true-p lsp-mode)
(lsp-feature? "textDocument/formatting")) (lsp-feature? "textDocument/formatting"))
#'lsp-format-buffer #'lsp-format-buffer)
#'format-all-buffer))) ((and +format-with-lsp
(bound-and-true-p eglot--managed-mode)
(eglot--server-capable :documentFormattingProvider))
#'eglot-format-buffer)
(t #'format-all-buffer))))
;;;###autoload ;;;###autoload
(defun +format/region (beg end) (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 contains a syntax error in isolation. It is mostly useful for formatting
snippets or single lines." snippets or single lines."
(interactive "rP") (interactive "rP")
(if (and +format-with-lsp (cond ((and +format-with-lsp
(bound-and-true-p lsp-mode) (bound-and-true-p lsp-mode)
(lsp-feature? "textDocument/rangeFormatting")) (lsp-feature? "textDocument/rangeFormatting"))
(call-interactively #'lsp-format-region) (call-interactively #'lsp-format-region))
(save-restriction ((and +format-with-lsp
(narrow-to-region beg end) (bound-and-true-p eglot--managed-mode)
(let ((+format-region-p t)) (eglot--server-capable :documentRangeFormattingProvider))
(+format/buffer))))) (call-interactively #'eglot-format))
(t (save-restriction
(narrow-to-region beg end)
(let ((+format-region-p t))
(+format/buffer))))))
;;;###autoload ;;;###autoload
(defun +format/region-or-buffer () (defun +format/region-or-buffer ()

View file

@ -17,6 +17,8 @@
:config :config
(set-popup-rule! "^\\*eglot-help" :size 0.35 :quit t :select t) (set-popup-rule! "^\\*eglot-help" :size 0.35 :quit t :select t)
(set-lookup-handlers! 'eglot--managed-mode (set-lookup-handlers! 'eglot--managed-mode
:implementations #'eglot-find-implementation
:type-definition #'eglot-find-typeDefinition
:documentation #'+eglot/documentation-lookup-handler) :documentation #'+eglot/documentation-lookup-handler)
(when (featurep! :checkers syntax) (when (featurep! :checkers syntax)
(after! flycheck (after! flycheck