From 841eacc77d15268477a6a5809e9b1e3d98c18dff Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Aug 2020 17:44:58 -0400 Subject: [PATCH] tools/lsp: lazy load c l keybind Fixes a issue where folks would try to rebind c, only to get a non-prefix key error about c l. --- modules/config/default/+emacs-bindings.el | 3 +- modules/config/default/+evil-bindings.el | 61 ++++++++++----------- modules/config/default/autoload/deferred.el | 20 +++++++ modules/tools/lsp/+lsp.el | 6 -- 4 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 modules/config/default/autoload/deferred.el diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index c021748ce..2c121927e 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -47,8 +47,7 @@ :desc "LSP Code actions" "a" #'lsp-execute-code-action :desc "LSP Organize imports" "o" #'lsp-organize-imports :desc "LSP Rename" "r" #'lsp-rename - (:after lsp-mode - :desc "LSP" "l" lsp-command-map) + :desc "LSP" "l" #'+default/lsp-command-map (: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) diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index c6fd84dc7..c96659de4 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -337,37 +337,36 @@ ;;; c --- code (:prefix-map ("c" . "code") (:when (and (featurep! :tools lsp) (not (featurep! :tools lsp +eglot))) - :desc "LSP Execute code action" "a" #'lsp-execute-code-action - :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) - (:when (featurep! :completion helm) - :desc "Jump to symbol in current workspace" "j" #'helm-lsp-workspace-symbol - :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol) - :desc "LSP Rename" "r" #'lsp-rename - (:after lsp-mode - :desc "LSP" "l" lsp-command-map)) - (:when (featurep! :tools lsp +eglot) - :desc "LSP Execute code action" "a" #'eglot-code-actions - :desc "LSP Rename" "r" #'eglot-rename - :desc "LSP Find declaration" "j" #'eglot-find-declaration) - :desc "Compile" "c" #'compile - :desc "Recompile" "C" #'recompile - :desc "Jump to definition" "d" #'+lookup/definition - :desc "Jump to references" "D" #'+lookup/references - :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 - (:when (featurep! :checkers syntax) - :desc "List errors" "x" #'flycheck-list-errors)) + :desc "LSP Execute code action" "a" #'lsp-execute-code-action + :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) + (:when (featurep! :completion helm) + :desc "Jump to symbol in current workspace" "j" #'helm-lsp-workspace-symbol + :desc "Jump to symbol in any workspace" "J" #'helm-lsp-global-workspace-symbol) + :desc "LSP" "l" #'+default/lsp-command-map + :desc "LSP Rename" "r" #'lsp-rename) + (:when (featurep! :tools lsp +eglot) + :desc "LSP Execute code action" "a" #'eglot-code-actions + :desc "LSP Rename" "r" #'eglot-rename + :desc "LSP Find declaration" "j" #'eglot-find-declaration) + :desc "Compile" "c" #'compile + :desc "Recompile" "C" #'recompile + :desc "Jump to definition" "d" #'+lookup/definition + :desc "Jump to references" "D" #'+lookup/references + :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 + (:when (featurep! :checkers syntax) + :desc "List errors" "x" #'flycheck-list-errors)) ;;; f --- file (:prefix-map ("f" . "file") diff --git a/modules/config/default/autoload/deferred.el b/modules/config/default/autoload/deferred.el new file mode 100644 index 000000000..41686e449 --- /dev/null +++ b/modules/config/default/autoload/deferred.el @@ -0,0 +1,20 @@ +;;; config/default/autoload/deferred.el -*- lexical-binding: t; -*- + +;; TODO generalize this +;;;###autoload +(defun +default/lsp-command-map () + "Lazily invoke `lsp-command-map'." + (interactive) + (require 'lsp-mode) + (map! :leader "c l" lsp-command-map) + (dolist (leader-key (list doom-leader-key doom-leader-alt-key)) + (let ((lsp-keymap-prefix (concat leader-key " c l"))) + (lsp-enable-which-key-integration))) + (setq prefix-arg current-prefix-arg + unread-command-events + (mapcar (lambda (e) (cons t e)) + (vconcat (when evil-this-operator + (where-is-internal evil-this-operator + evil-normal-state-map + t)) + (this-command-keys))))) diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index 8954d925c..a9f98e379 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -62,12 +62,6 @@ should be a deliberate act (as is flipping this variable).") :type-definition #'lsp-find-type-definition :references #'lsp-find-references) - ;; REVIEW The ' c l' prefix is hardcoded here, unfortunately. - (when (featurep! :config default +bindings) - (dolist (leader-key (list doom-leader-key doom-leader-alt-key)) - (let ((lsp-keymap-prefix (concat leader-key " c l"))) - (lsp-enable-which-key-integration)))) - (when lsp-auto-configure (mapc (lambda (package) (require package nil t)) (cl-remove-if #'featurep lsp-client-packages)))