-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#+TITLE: cquery layer | ||
|
||
* Table of Contents :TOC_4_gh:noexport: | ||
- [[#description][Description]] | ||
- [[#features][Features:]] | ||
- [[#external-dependencies][External Dependencies]] | ||
- [[#cquery-server][cquery server]] | ||
- [[#configuration][Configuration]] | ||
- [[#basic][Basic]] | ||
- [[#setting-path-to-cquery-executable][Setting path to cquery executable]] | ||
- [[#additional-configuration-options][Additional configuration options]] | ||
- [[#keybindings][Keybindings]] | ||
- [[#goto-find][goto (find)]] | ||
- [[#hierarchy][hierarchy]] | ||
|
||
* Description | ||
This layer extends the [[../lsp/README.org][LSP layer]] to add [[https://github.com/cquery-project/cquery][cquery]] support. | ||
|
||
** Features: | ||
- Cross references (definitions, references, base/derived classes/methods, type instances, ...) | ||
- Diagnostics | ||
- Completion with =company-lsp= | ||
- Semantic highlighting | ||
- See more on [[https://github.com/cquery-project/cquery/wiki/Emacs]] | ||
- Cross-platform - cquery functional on Windows, Linux and OSX. | ||
|
||
* External Dependencies | ||
** cquery server | ||
Install the =cquery= server. [[https://github.com/cquery-project/cquery/wiki/Getting-started][Instructions]]. | ||
|
||
|
||
* Configuration | ||
** Basic | ||
Add =cquery= to the =dotspacemacs-configuration-layers= list in =~/.spacemacs=. | ||
|
||
** Setting path to cquery executable | ||
The basic configuration above should work if the cquery executable folder is present in your path. If not, you can set the path explicitly. | ||
#+BEGIN_SRC emacs-lisp | ||
(cquery :variables cquery-executable "/path/to/bin/cquery") | ||
#+END_SRC | ||
If you need to expand =~= in the path, you can use =file-truename= like | ||
#+BEGIN_SRC emacs-lisp | ||
(cquery :variables cquery-executable (file-truename "~/bin/cquery")) | ||
#+END_SRC | ||
|
||
** Additional configuration options | ||
cquery needs to know where to store index cache (=cquery-cache-dir=). | ||
There are other 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. | ||
|
||
* Keybindings | ||
** goto (find) | ||
In addition to the LSP layer defaults (see [[../lsp/README.org][LSP layer README]]), this layer defines the following bindings under the ~m g~: | ||
|
||
| binding | function | | ||
|---------+-------------------------------| | ||
| ~m g &~ | find references (address) | | ||
| ~m g R~ | find references (read) | | ||
| ~m g W~ | find references (write) | | ||
| ~m g c~ | find callers | | ||
| ~m g t~ | text-document/type-definition | | ||
| ~m g v~ | vars | | ||
|
||
** hierarchy | ||
The layer binds the following hierarchy-related functions under ~m h~: | ||
|
||
| binding | function | | ||
|---------+-------------------------------| | ||
| ~m h b~ | base class(es) | | ||
| ~m h d~ | derived class(es) | | ||
| ~m h c~ | call hierarchy | | ||
| ~m h C~ | call hierarchy (inv) | | ||
| ~m h i~ | inheritance heirarchy | | ||
This comment has been minimized.
Sorry, something went wrong. |
||
| ~m h I~ | inheritance hierarhcy (inv) | | ||
This comment has been minimized.
Sorry, something went wrong. |
||
| ~m h m~ | member hierarchy | | ||
| ~m h M~ | member hierarchy (inv) | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(defvar cquery-extra-init-params '(:cacheFormat "msgpack") | ||
"Extra initialisation parameters to pass to cquery. See | ||
https://github.com/cquery-project/cquery/blob/master/src/config.h for details.") | ||
|
||
(defvar cquery-project-whitelist nil | ||
"A list of project directory patterns for which cquery should be | ||
initialized. This overrides `cquery-project-blacklist'.") | ||
|
||
(defvar cquery-project-blacklist nil | ||
"A list of project root patterns for which cquery shouldn't be | ||
initialized. `cquery-project-whitelist' is checked first, then this, | ||
if no pattern matches the project root, cquery will be initialized.") | ||
|
||
(defvar cquery-sem-highlight-method 'font-lock | ||
"TODO don't know what this does yet") | ||
|
||
(defvar cquery-executable "cquery" | ||
"Path to cquery executable (default value assumes it's in the path)") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
;; >>> Lifted from MaskRay's cquery layer | ||
(require 'cl-lib) | ||
(require 'subr-x) | ||
|
||
(defun cquery//enable () | ||
(condition-case nil | ||
(lsp-cquery-enable) | ||
(user-error nil))) | ||
|
||
|
||
(defun cquery/customise-lsp-ui-peek () | ||
(defun text-document/type-definition () (interactive) (lsp-ui-peek-find-custom 'type "textDocument/typeDefinition")) | ||
(defun cquery/base () (interactive) (lsp-ui-peek-find-custom 'base "$cquery/base")) | ||
(defun cquery/callers () (interactive) (lsp-ui-peek-find-custom 'callers "$cquery/callers")) | ||
(defun cquery/derived () (interactive) (lsp-ui-peek-find-custom 'derived "$cquery/derived")) | ||
(defun cquery/vars () (interactive) (lsp-ui-peek-find-custom 'vars "$cquery/vars")) | ||
(defun cquery/random () (interactive) (lsp-ui-peek-find-custom 'random "$cquery/random")) | ||
|
||
(defun cquery/references-address () | ||
(interactive) | ||
(lsp-ui-peek-find-custom | ||
'address "textDocument/references" | ||
(plist-put (lsp--text-document-position-params) :context | ||
'(:role 128)))) | ||
|
||
(defun cquery/references-read () | ||
(interactive) | ||
(lsp-ui-peek-find-custom | ||
'read "textDocument/references" | ||
(plist-put (lsp--text-document-position-params) :context | ||
'(:role 8)))) | ||
|
||
(defun cquery/references-write () | ||
(interactive) | ||
(lsp-ui-peek-find-custom | ||
'write "textDocument/references" | ||
(plist-put (lsp--text-document-position-params) :context | ||
'(:role 16)))) | ||
|
||
) | ||
|
||
(defun cquery/define-keys-for-mode (mode) | ||
"Define key bindings for the specific MODE." | ||
|
||
;; lsp layer uses =,l,t,r as prefixes for format, lsp, toggle and refactor -- extend these | ||
(spacemacs/declare-prefix-for-mode mode "mh" "heirarchy") | ||
This comment has been minimized.
Sorry, something went wrong. |
||
(spacemacs/set-leader-keys-for-major-mode mode | ||
;; heirarchy | ||
This comment has been minimized.
Sorry, something went wrong. |
||
"hb" #'cquery/base | ||
"hd" #'cquery/derived | ||
"hc" #'cquery-call-hierarchy | ||
"hC" (lambda () (interactive) (cquery-call-hierarchy t)) | ||
"hi" #'cquery-inheritance-hierarchy | ||
"hI" (lambda () (interactive) (cquery-inheritance-hierarchy t)) | ||
"hm" #'cquery-member-hierarchy | ||
"hM" (lambda () (interactive) (cquery-member-hierarchy t)) | ||
;; lsp/peek | ||
"g&" #'cquery/references-address | ||
"gR" #'cquery/references-read | ||
"gW" #'cquery/references-write | ||
"gc" #'cquery/callers | ||
"gt" #'text-document/type-definition | ||
"gv" #'cquery/vars | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(configuration-layer/declare-layers '(lsp c-c++)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(defconst cquery-packages | ||
'( | ||
cquery | ||
company-lsp | ||
projectile | ||
)) | ||
|
||
;; See also https://github.com/cquery-project/cquery/wiki/Emacs | ||
(defun cquery/init-cquery () | ||
(use-package cquery | ||
:defer t | ||
:commands lsp-cquery-enable | ||
:init | ||
(add-hook 'c-mode-common-hook #'cquery//enable) | ||
:config | ||
(dolist (mode c-c++-modes) | ||
(spacemacs/lsp-append-jump-handlers mode) | ||
(spacemacs/lsp-bind-keys-for-mode mode) | ||
(cquery/define-keys-for-mode mode) | ||
(spacemacs/set-leader-keys-for-major-mode mode | ||
;; format | ||
"=c" 'spacemacs/clang-format-region-or-buffer | ||
"=f" 'spacemacs/clang-format-function | ||
;; goto | ||
"gf" 'find-file-at-point | ||
"gF" 'ffap-other-window | ||
) | ||
) | ||
;; overlay is slow | ||
;; Use https://github.com/emacs-mirror/emacs/commits/feature/noverlay | ||
(cquery-use-default-rainbow-sem-highlight) | ||
(evil-set-initial-state 'cquery-tree-mode 'emacs) | ||
|
||
(cquery/customise-lsp-ui-peek) | ||
(setq-default flycheck-disabled-checkers '(c/c++-clang c/c++-gcc)) ;; in flycheck.el | ||
|
||
;;evil-record-macro keybinding clobbers q in cquery-tree-mode-map for some reason? | ||
(evil-make-overriding-map cquery-tree-mode-map) | ||
|
||
)) | ||
|
||
(defun cquery/post-init-company-lsp () | ||
(spacemacs|add-company-backends :backends company-lsp :modes c-mode-common)) | ||
|
||
(defun cquery/pre-init-projectile () | ||
(spacemacs|use-package-add-hook | ||
:post-init | ||
(add-to-list 'projectile-globally-ignored-directories ".cquery_cached_index") | ||
) | ||
) |
5 comments
on commit b8ae1bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While testing this excellent commit, I found some tricky words.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Kypert. Amended commit here:
f68507b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Currently trying this too. So far so good with an 80M compile_commands.json file. How does one hook it into ivy or helm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly what you mean, I just added this layer to dotspacemacs-configuration-layers:
(cquery :variables cquery-executable "/path/to/cquery")
Then, in my project I also made sure that compile_commands.json is located in project root. In my case I just made a link compile_commands.json -> build/compile_commands.json
.
On another topic, I get an lsp-cquery stack trace when trying to open up a project using tramp. Any of you tried that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future references.
I get an lsp-cquery stack trace when trying to open up a project using tramp
Spelling: heirarchy -> hierarchy