Add ccls-specific configuration

Most of these changes come from MaskRay's private configuration found
here :
c078dfad34/home/.config/doom/modules/private/my-cc/config.el

- Limit ccls threads to be maximum half the available core count on
  Linux and MacOS
- Add wrappers to call ccls LSP extensions
- Enable ccls-code-lens-mode
- Set initial state to emacs when navigating ccls-tree
- Use 'font-lock for semantic highlighting, making the speed choice
  according to variable's docstring

- config tweaks to eglot
  InitializationOptions aren't handled this way. An example of handling
  ccls init options is provided on joaotavora/eglot#545, hoping that a fix
  gets merged upstream instead of having to handle ccls specifics in Doom
  only
This commit is contained in:
Gerry Agbobada 2020-09-01 20:26:56 +02:00
parent f6aa50e1bc
commit cec81ac2cc
No known key found for this signature in database
GPG key ID: 53F94866E84818F6
2 changed files with 125 additions and 6 deletions

View file

@ -230,7 +230,26 @@ 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" (λ! (ccls-navigate "U"))
:n "C-j" (λ! (ccls-navigate "R"))
:n "C-k" (λ! (ccls-navigate "L"))
:n "C-l" (λ! (ccls-navigate "D"))
(:localleader
:desc "Preprocess file" :n "lp" #'ccls-preprocess-file
:desc "Reset cache and reload CCLS" :n "lf" #'ccls-reload)
(:after lsp-ui-peek
(:localleader
:desc "Callers list" :n "c" #'+ccls/caller
:desc "Callees list" :n "C" #'+ccls/callee
:desc "References (address)" :n "a" #'+ccls/references-address
:desc "References (not call)" :n "f" #'+ccls/references-not-call
:desc "References (Macro)" :n "m" #'+ccls/references-macro
:desc "References (Read)" :n "r" #'+ccls/references-read
:desc "References (Write)" :n "w" #'+ccls/references-write))))
(when (featurep! :tools lsp +eglot)
;; Map eglot specific helper
@ -249,7 +268,6 @@ 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)
@ -260,9 +278,20 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e
(add-to-list 'projectile-project-root-files-bottom-up ".ccls-root")
(add-to-list 'projectile-project-root-files-top-down-recurring "compile_commands.json"))
:config
(add-hook 'lsp-after-open-hook #'ccls-code-lens-mode)
(set-evil-initial-state! 'ccls-tree-mode 'emacs)
(setq ccls-sem-highlight-method 'font-lock)
(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"))))))))