Skip to content

Commit

Permalink
Add +tools/cquery layer
Browse files Browse the repository at this point in the history
https://github.com/cquery-project/cquery is a low-latency language server supporting multi-million line C++ code-bases, powered by libclang.

Please refer to https://github.com/cquery-project/cquery/wiki/Emacs
  • Loading branch information
MaskRay committed Feb 19, 2018
1 parent 81a931f commit 1705e5c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
47 changes: 47 additions & 0 deletions layers/+tools/cquery/README.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#+TITLE: cquery layer

* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#cquery-server][cquery server]]
- [[#layer][Layer]]
- [[#configuration][Configuration]]

* Description
This layer adds [[https://github.com/cquery-project/cquery][cquery]] support.

** Features:
- Cross references (definitions, references, base/derived classes/methods, type instances, ...)
- Workspace symbol search
- Workspace-wide symbol rename
- Diagnostics
- Completion with =company-lsp=
- Rainbow semantic highlighting
- Signature help and documentation
- Code lens
- See more on [[https://github.com/cquery-project/cquery/wiki/Emacs]]

Some features are implemented on the server side but not available in the Emacs plugin, e.g. type hierarchy, member hierarchy, call tree.

* Install
** cquery server
Install the =cquery= server. [[https://github.com/cquery-project/cquery/wiki/Getting-started][Instructions]].

** Layer
1) Add =cquery= to the =dotspacemacs-configuration-layers= list in =~/.spacemacs=.
2)
#+BEGIN_SRC emacs-lisp
(setq cquery-executable "/path/to/bin/cquery")
#+END_SRC emacs-lisp
If you need to expand =~= in the path, you can use =file-truename= like
#+BEGIN_SRC emacs-lisp
(setq cquery-executable (file-truename "~/cquery/build/release/bin/cquery"))
#+END_SRC

* Configuration
cquery needs to know where to store index cache (=cquery-cache-dir=), which defaults to =.cquery_cached_index= in the project root.
You may change it to an absolute path to have cache from different projects reside in the same directory.

Many behaviors do not have correponding elisp variables and should be tuned via initialization options, such as the number of indexer threads, cache serialization format. They have good default values.
Refer to [[https://github.com/cquery-project/cquery/wiki/Initialization-options][Initialization options]] and set =cquery-extra-init-params= for more customization.
2 changes: 2 additions & 0 deletions layers/+tools/cquery/config.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;; See https://github.com/cquery-project/cquery/wiki/Initialization-options
(defvar cquery-extra-init-params '(:cacheFormat "msgpack"))
8 changes: 8 additions & 0 deletions layers/+tools/cquery/funcs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(require 'cl-lib)

(defun cquery//enable ()
(when
(and buffer-file-name
(or (locate-dominating-file default-directory "compile_commands.json")
(locate-dominating-file default-directory ".cquery")))
(lsp-cquery-enable)))
1 change: 1 addition & 0 deletions layers/+tools/cquery/layers.el
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(configuration-layer/declare-layer 'lsp)
10 changes: 10 additions & 0 deletions layers/+tools/cquery/packages.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(defconst cquery-packages '((cquery)))

;; See also https://github.com/cquery-project/cquery/wiki/Emacs
(defun cquery/init-cquery ()
(use-package cquery
:defer t
:init
;; Customize `lsp-project-whitelist' `lsp-project-blacklist' to disable auto initialization.
(add-hook 'c-mode-common-hook #'cquery//enable)
))

0 comments on commit 1705e5c

Please sign in to comment.