From 0b480a6aad06a8528ed7e8ee23ef4c013080b018 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 13 Oct 2020 21:26:38 -0400 Subject: [PATCH] lang/cc: refactor ccls config 1. Unset ccls-sem-highlight-method if lsp-enable-semantic-highlighting is nil (perhaps this should be reported upstream). 2. Fix load-order. Take `(use-package X :after Y :config Z)` for example. Z will be evaluated after Y loads, not after X loads. To customize Z you'd need to do `(after! Y ...)`. This is counter-intuitive. By removing `:after Y` and explicitly loading X when Y loads in :init, you can customize Z with `(after! X ...)` again. 3. Tie ccls-code-lens-mode to lsp-lens-mode, so lsp-lens-enable is respected. --- modules/lang/cc/config.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index e1bdc9943..d73ae4380 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -271,16 +271,22 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e (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 - (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) + ;; Disable `ccls-sem-highlight-method' if `lsp-enable-semantic-highlighting' + ;; is nil. Otherwise, it appears ccls bypasses it. + (setq-hook! 'lsp-before-initialize-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"))