Minor edits.

This commit is contained in:
Derek Taylor
2020-11-05 13:27:52 -06:00
parent 8fbacc6392
commit 35112d3f8c
170 changed files with 1304 additions and 756 deletions

View File

@@ -129,7 +129,7 @@ simpler."
;; Eglot specific helper, courtesy of MaskRay
;;;###autoload
(defun +cc/eglot-ccls-inheritance-hierarchy (&optional derived)
(defun +cc/eglot-ccls-show-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."
@@ -224,3 +224,95 @@ header files."
(`c-mode 'ffap-c-path)
(`c++-mode 'ffap-c++-path))
(expand-file-name dir project-root)))))
;;
;;; CCLS specific helpers
;; ccls-show-vars ccls-show-base ccls-show-derived ccls-show-members have a
;; parameter while others are interactive.
;;
;; (+cc/ccls-show-base 1) direct bases
;; (+cc/ccls-show-derived 1) direct derived
;; (+cc/ccls-show-member 2) => 2 (Type) => nested classes / types in a namespace
;; (+cc/ccls-show-member 3) => 3 (Func) => member functions / functions in a namespace
;; (+cc/ccls-show-member 0) => member variables / variables in a namespace
;; (+cc/ccls-show-vars 1) => field
;; (+cc/ccls-show-vars 2) => local variable
;; (+cc/ccls-show-vars 3) => field or local variable. 3 = 1 | 2
;; (+cc/ccls-show-vars 4) => parameter
;;;###autoload
(defun +cc/ccls-show-callee ()
"Show callees of symbol under point."
(interactive)
(lsp-ui-peek-find-custom "$ccls/call" '(:callee t)))
;;;###autoload
(defun +cc/ccls-show-caller ()
"Show callers of symbol under point."
(interactive)
(lsp-ui-peek-find-custom "$ccls/call"))
;;;###autoload
(defun +cc/ccls-show-vars (kind)
"Show variables of type KIND as symbol under point.
1 -> field
2 -> local variable
3 -> field or local variables. 3 = 1 | 2.
4 -> parameter"
(lsp-ui-peek-find-custom "$ccls/vars" `(:kind ,kind)))
;;;###autoload
(defun +cc/ccls-show-base (levels)
"Show bases of class under point up to LEVELS levels (1 for direct bases)."
(lsp-ui-peek-find-custom "$ccls/inheritance" `(:levels ,levels)))
;;;###autoload
(defun +cc/ccls-show-derived (levels)
"Show derived classes from class under point down to LEVELS levels (1 for direct derived)."
(lsp-ui-peek-find-custom "$ccls/inheritance" `(:levels ,levels :derived t)))
;;;###autoload
(defun +cc/ccls-show-member (kind)
"Show member elements of kind KIND for class/namespace under point.
0 -> member variables/ variables in a namespace
2 -> nested classes / types in a namespace
3 -> member functions / functions in a namespace"
(lsp-ui-peek-find-custom "$ccls/member" `(:kind ,kind)))
;; The meaning of :role corresponds to https://github.com/maskray/ccls/blob/master/src/symbol.h
;;;###autoload
(defun +cc/ccls-show-references-address ()
"References w/ Role::Address bit (e.g. variables explicitly being taken addresses)"
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 128)))
;;;###autoload
(defun +cc/ccls-show-references-macro ()
"References w/ Role::Dynamic bit (macro expansions)"
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 64)))
;;;###autoload
(defun +cc/ccls-show-references-not-call ()
"References w/o Role::Call bit (e.g. where functions are taken addresses)"
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :excludeRole 32)))
;;;###autoload
(defun +cc/ccls-show-references-read ()
"References w/ Role::Read"
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 8)))
;;;###autoload
(defun +cc/ccls-show-references-write ()
"References w/ Role::Write"
(interactive)
(lsp-ui-peek-find-custom "textDocument/references"
(plist-put (lsp--text-document-position-params) :role 16)))

View File

@@ -230,14 +230,33 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e
(add-hook! '(c-mode-local-vars-hook
c++-mode-local-vars-hook
objc-mode-local-vars-hook)
#'lsp!)
#'lsp!)
(map! :after ccls
:map (c-mode-map c++-mode-map)
:n "C-h" (cmd! (ccls-navigate "U"))
:n "C-j" (cmd! (ccls-navigate "R"))
:n "C-k" (cmd! (ccls-navigate "L"))
:n "C-l" (cmd! (ccls-navigate "D"))
(:localleader
:desc "Preprocess file" "lp" #'ccls-preprocess-file
:desc "Reload cache & CCLS" "lf" #'ccls-reload)
(:after lsp-ui-peek
(:localleader
:desc "Callers list" "c" #'+cc/ccls-show-caller
:desc "Callees list" "C" #'+cc/ccls-show-callee
:desc "References (address)" "a" #'+cc/ccls-show-references-address
:desc "References (not call)" "f" #'+cc/ccls-show-references-not-call
:desc "References (Macro)" "m" #'+cc/ccls-show-references-macro
:desc "References (Read)" "r" #'+cc/ccls-show-references-read
:desc "References (Write)" "w" #'+cc/ccls-show-references-write)))
(when (featurep! :tools lsp +eglot)
;; Map eglot specific helper
(map! :localleader
:after cc-mode
:map c++-mode-map
:n :desc "Show type inheritance hierarchy" "ct" #'+cc/eglot-ccls-inheritance-hierarchy)
:desc "Show type inheritance hierarchy" "ct" #'+cc/eglot-ccls-inheritance-hierarchy)
;; NOTE : This setting is untested yet
(after! eglot
@@ -249,20 +268,37 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e
"-isystem/usr/local/include"]
:resourceDir (cdr (doom-call-process "clang" "-print-resource-dir"))))))))))))
(use-package! ccls
:when (featurep! +lsp)
:unless (featurep! :tools lsp +eglot)
:after lsp-mode
:hook (lsp-lens-mode . ccls-code-lens-mode)
:init
(defvar ccls-sem-highlight-method 'font-lock)
(after! projectile
(add-to-list 'projectile-globally-ignored-directories ".ccls-cache")
(add-to-list 'projectile-project-root-files-bottom-up ".ccls-root")
(add-to-list 'projectile-project-root-files-top-down-recurring "compile_commands.json"))
;; Avoid using `:after' because it ties the :config below to when `lsp-mode'
;; loads, rather than `ccls' loads.
(after! lsp-mode (require 'ccls))
:config
(set-evil-initial-state! 'ccls-tree-mode 'emacs)
;; Disable `ccls-sem-highlight-method' if `lsp-enable-semantic-highlighting'
;; is nil. Otherwise, it appears ccls bypasses it.
(setq-hook! 'lsp-configure-hook
ccls-sem-highlight-method (if lsp-enable-semantic-highlighting
ccls-sem-highlight-method))
(when (or IS-MAC IS-LINUX)
(let ((cpu-count-command (cond (IS-MAC '("sysctl" "-n" "hw.ncpu"))
(IS-LINUX '("nproc"))
(t (error "unreachable code")))))
(setq ccls-initialization-options
`(:index (:trackDependency 1
:threads ,(max 1 (/ (string-to-number (cdr (apply #'doom-call-process cpu-count-command))) 2)))))))
(when IS-MAC
(setq ccls-initialization-options
`(: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 (cdr (doom-call-process "clang" "-print-resource-dir")))))))
(append ccls-initialization-options
`(: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 (cdr (doom-call-process "clang" "-print-resource-dir"))))))))

View File

@@ -5,7 +5,7 @@
:recipe (:host github :repo "emacsmirror/cmake-mode" :files (:defaults "*"))
:pin "e58c41145a879f0314b2821eada7fd0dc898b6b6")
(package! cuda-mode :pin "9ae9eacfdba3559b5456342d0d03296290df8ff5")
(package! demangle-mode :pin "697c1dbde93f164eac7ea0dc530d7e8b799272d6")
(package! demangle-mode :pin "aaef0bd77a3ea9ce9132e9a53ac021b0f5d33e12")
(package! disaster :pin "10a785facc60d89d78e0d5177985ab1af1741bb4")
(package! modern-cpp-font-lock :pin "865955d0035382a17a7f03add0d00d0bd812b103")
(package! opencl-mode :pin "55cb49c8243e6420961d719faced035bc547c1ef")
@@ -27,7 +27,7 @@
(when (featurep! :completion company)
(package! company-irony :pin "b44711dfce445610c1ffaec4951c6ff3882b216a")
(package! company-irony-c-headers :pin "72c386aeb079fb261d9ec02e39211272f76bbd97")))
(when (package! rtags :pin "b57b36039f6411f23009c4ec0315ca5a7adb6824")
(when (package! rtags :pin "e6c7005bfad5df335ce86378b642ebd33aa66f26")
(when (featurep! :completion ivy)
(package! ivy-rtags))
(when (featurep! :completion helm)