From 718d9a269018c777bb1176e462bc057401c620df Mon Sep 17 00:00:00 2001 From: Gerry Agbobada Date: Thu, 28 May 2020 11:12:35 +0200 Subject: [PATCH] [review] Changes --- modules/config/default/+emacs-bindings.el | 2 +- modules/lang/cc/config.el | 67 ++++++++++--------- modules/tools/lsp/+eglot.el | 9 +-- .../lsp/{ => autoload}/flycheck-eglot.el | 8 +-- modules/tools/lsp/packages.el | 13 ++-- 5 files changed, 46 insertions(+), 53 deletions(-) rename modules/tools/lsp/{ => autoload}/flycheck-eglot.el (92%) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 646f44209..71e1d1241 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -58,7 +58,7 @@ :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 implementation" "J" #'eglot-find-implementation)) ;;; f --- file (:prefix-map ("f" . "file") diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index 33daf41a3..c8a5ee10e 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -237,41 +237,42 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e (lsp!)))) (when (and (featurep! +lsp) (featurep! :tools lsp +eglot)) - ;; TODO : test this value - ;; IS-MAC custom configuration - (when IS-MAC - (add-to-list 'eglot-workspace-configuration - ((:ccls . ((:clang . ,(list :extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1" - "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" - "-isystem/usr/local/include"] - :resourceDir (string-trim (shell-command-to-string "clang -print-resource-dir"))))))))) - ;; Eglot specific helper, courtesy of MaskRay - (defun eglot-ccls-inheritance-hierarchy (&optional derived) - "Show inheritance hierarchy for the thing at point. + ;; NOTE : This setting is untested yet + (after! eglot + ;; IS-MAC custom configuration + (when IS-MAC + (add-to-list 'eglot-workspace-configuration + ((:ccls . ((:clang . ,(list :extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1" + "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" + "-isystem/usr/local/include"] + :resourceDir (string-trim (shell-command-to-string "clang -print-resource-dir"))))))))) + ;; Eglot specific helper, courtesy of MaskRay + (defun eglot-ccls-inheritance-hierarchy (&optional derived) + "Show inheritance hierarchy for the thing at point. If DERIVED is non-nil (interactively, with prefix argument), show the children of class at point." - (interactive "P") - (if-let* ((res (jsonrpc-request - (eglot--current-server-or-lose) - :$ccls/inheritance - (append (eglot--TextDocumentPositionParams) - `(:derived ,(if derived t :json-false)) - '(:levels 100) '(:hierarchy t)))) - (tree (list (cons 0 res)))) - (with-help-window "*ccls inheritance*" - (with-current-buffer standard-output - (while tree - (pcase-let ((`(,depth . ,node) (pop tree))) - (cl-destructuring-bind (&key uri range) (plist-get node :location) - (insert (make-string depth ?\ ) (plist-get node :name) "\n") - (make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0) - 'action (lambda (_arg) - (interactive) - (find-file (eglot--uri-to-path uri)) - (goto-char (car (eglot--range-region range))))) - (cl-loop for child across (plist-get node :children) - do (push (cons (1+ depth) child) tree))))))) - (eglot--error "Hierarchy unavailable")))) + (interactive "P") + (if-let* ((res (jsonrpc-request + (eglot--current-server-or-lose) + :$ccls/inheritance + (append (eglot--TextDocumentPositionParams) + `(:derived ,(if derived t :json-false)) + '(:levels 100) '(:hierarchy t)))) + (tree (list (cons 0 res)))) + (with-help-window "*ccls inheritance*" + (with-current-buffer standard-output + (while tree + (pcase-let ((`(,depth . ,node) (pop tree))) + (cl-destructuring-bind (&key uri range) (plist-get node :location) + (insert (make-string depth ?\ ) (plist-get node :name) "\n") + (make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0) + 'action (lambda (_arg) + (interactive) + (find-file (eglot--uri-to-path uri)) + (goto-char (car (eglot--range-region range))))) + (cl-loop for child across (plist-get node :children) + do (push (cons (1+ depth) child) tree))))))) + (eglot--error "Hierarchy unavailable"))))) (use-package! ccls :when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot))) diff --git a/modules/tools/lsp/+eglot.el b/modules/tools/lsp/+eglot.el index a8ee9ca96..7c963bed6 100644 --- a/modules/tools/lsp/+eglot.el +++ b/modules/tools/lsp/+eglot.el @@ -14,10 +14,7 @@ :config (set-popup-rule! "^\\*eglot-help" :size 0.35 :quit t :select t) (when (featurep! :checkers syntax) - ;; Eager loading which is okay-ish since we want eglot to feed flycheck as soon as possible. - (load! "flycheck-eglot.el") - (require 'flycheck-eglot)) + (after! flycheck + (load! "flycheck-eglot.el"))) (set-lookup-handlers! 'eglot--managed-mode - :documentation #'+eglot/documentation-lookup-handler - :definition '(xref-find-definitions :async t) - :references '(xref-find-references :async t))) + :documentation #'+eglot/documentation-lookup-handler)) diff --git a/modules/tools/lsp/flycheck-eglot.el b/modules/tools/lsp/autoload/flycheck-eglot.el similarity index 92% rename from modules/tools/lsp/flycheck-eglot.el rename to modules/tools/lsp/autoload/flycheck-eglot.el index d9f174bf1..db7a38e1b 100644 --- a/modules/tools/lsp/flycheck-eglot.el +++ b/modules/tools/lsp/autoload/flycheck-eglot.el @@ -1,7 +1,5 @@ ;;; flycheck-eglot --- Hacky eglot support in flycheck -*- lexical-binding: t; -*- -(require 'flycheck) - ;;; Code: (defun flycheck-eglot--start (checker callback) "Clean up errors when done. @@ -44,7 +42,7 @@ CALLBACK is the function that we need to call when we are done, on all the error (push 'eglot flycheck-checkers) -(defun +doom/eglot-prefer-flycheck-h () +(defun +doom-eglot-prefer-flycheck-h () (when eglot--managed-mode (when-let ((current-checker (flycheck-get-checker-for-buffer))) (unless (equal current-checker 'eglot) @@ -53,8 +51,6 @@ CALLBACK is the function that we need to call when we are done, on all the error (flycheck-mode 1) (flymake-mode -1))) -(add-hook 'eglot--managed-mode-hook #'+doom/eglot-prefer-flycheck-h) +(add-hook 'eglot--managed-mode-hook #'+doom-eglot-prefer-flycheck-h) -(provide 'flycheck-eglot) ;;; flycheck-eglot.el ends here - diff --git a/modules/tools/lsp/packages.el b/modules/tools/lsp/packages.el index b8117fa61..90b673c18 100644 --- a/modules/tools/lsp/packages.el +++ b/modules/tools/lsp/packages.el @@ -3,10 +3,9 @@ (if (featurep! +eglot) (package! eglot :pin "d99a4478a9") - (progn - (package! lsp-mode :pin "81d62d581b21d847783831e6e5ca9d3c63fe9a4d") - (package! lsp-ui :pin "271b47cb33f11915295911f7cf8575f8a82a5e1c") - (when (featurep! :completion ivy) - (package! lsp-ivy :pin "dce58b5509271bbedb53ba9d0278dcb563a43977")) - (when (featurep! :completion helm) - (package! helm-lsp :pin "6b5ce182d7c94c62b55b8f7d0c7e643b2c30e560")))) + (package! lsp-mode :pin "81d62d581b21d847783831e6e5ca9d3c63fe9a4d") + (package! lsp-ui :pin "271b47cb33f11915295911f7cf8575f8a82a5e1c") + (when (featurep! :completion ivy) + (package! lsp-ivy :pin "dce58b5509271bbedb53ba9d0278dcb563a43977")) + (when (featurep! :completion helm) + (package! helm-lsp :pin "6b5ce182d7c94c62b55b8f7d0c7e643b2c30e560")))