New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ccls/cquery (language server) to c-c++ layer #10134

MaskRay opened this Issue Jan 11, 2018 · 16 comments


None yet

MaskRay commented Jan 11, 2018

tl;dr Jump to the bottom to see the demo.

"cquery is a highly-scalable, low-latency language server for C/C++/Objective-C". There are uses on indexing Chromium, LLVM projects, and Linux kernel. It provides similar features with venerable rtags, like finding definitions/references. libclang + Clang C++ libclang

You can take this issue as a "seeking for help". There are many pieces need customizing (cquery.el lsp-mode lsp-ui) to provide a kinda satisfying code assistant UI. spacemacs is used by many and to me a suitable place to combine these efforts. I leave some notes at but my elisp-fu is incapable to create a robust layer.

I'd also like to know if there is interest to incorporate lsp-mode through which we can provide a unified interface for C++, Rust and many other languages. I have used rls (Rust) and cquery (C++) and many features can and should be shared and be provided by a common library (lsp-mode lsp-ui). cquery.el provides a LSP plugin for cquery and it also has some extensions not included in LSP:

;; emacs-ccls
(ccls-xref-find-custom "$ccls/base")
(ccls-xref-find-custom "$ccls/callers")
;; No "$ccls/derived", use lsp-goto-implementation from  lsp-mode instead
(ccls-xref-find-custom "$ccls/vars")

;; Alternatively, use lsp-ui-peek interface
(lsp-ui-peek-find-custom 'base "$ccls/base")
(lsp-ui-peek-find-custom 'callers "$ccls/callers")

;; ...... emacs-cquery
;; the cquery counterparts are similar
(cquery-xref-find-custom "$cquery/base")
(cquery-xref-find-custom "$cquery/callers")
(cquery-xref-find-custom "$cquery/derived")
(cquery-xref-find-custom "$cquery/vars")

;; Alternatively, use lsp-ui-peek interface
(lsp-ui-peek-find-custom 'base "$cquery/base")
(lsp-ui-peek-find-custom 'callers "$cquery/callers")
;; ......

There are still useful features that are missing or can be improved in cquery.el. And it is also nice to learn from users using other code assistants to know what can be improved generally about cquery.

I might be biased regarding rtags because I am a contributor of cquery. What bothered me a lot when I was using rtags was its query performance Andersbakken/rtags#1007

See also:

A brief list of what can be improved

rainbow semantic highlighting
semantic highlighting
approximate workspace/symbol search

If you speak Chinese, I've written an article introducing cquery and my configuration


This comment has been minimized.

MaskRay commented Jan 11, 2018

Adding a bunch of people who may be interested in better Emacs user experience of C/C++ or general LSP support.

@scturtle @jiegec @topisani @danielmartin @DeltaEvo @acowley

Sorry if that bothers you...

For integration of lsp-mode lsp-ui, please contact @vibhavp @sebastiencs

cquery @jacobdufault


This comment has been minimized.

danielmartin commented Jan 11, 2018

I don't particularly use Spacemacs, only vanilla GNU Emacs, so I don't know what the requirements are for including a package in a particular layer. I think cquery.el is already pretty stable and provides a lot of functionality so it can be a good candidate for inclusion. Also, with cquery everything is in one place, and it implements a well-known protocol. Without LSP it is typical to have to install several specialized packages to have an IDE experience (rtags for code navigation and irony-mode/ycm for code completion, for example).


This comment has been minimized.

sebastiencs commented Jan 12, 2018

I'm not using spacemacs either but if you're willing to integrate lsp-ui I can help :)
An integration with lsp-rust would be nice too @bkchr


This comment has been minimized.

bkchr commented Jan 12, 2018

I currently maintain my rust language server layer here:
It would be nice if the interface could be unified across languages, but I don't have any idea up to now.


This comment has been minimized.

scturtle commented Jan 12, 2018

If you want to have a try, I have a personal lsp-cquery layer with some customizations.

Agree with @bkchr. If there is a lsp layer with common configurations, it would be easier to integrate lsp client into each language layer.


This comment has been minimized.

MaskRay commented Jan 13, 2018

I have also cleaned my lsp-mode/lsp-ui based config. The cquery specific stuff is very simple now.

# cquery cache files
% du -sh .vscode/cquery_cached_index 
96M     .vscode/cquery_cached_index
ray @ hacking >>= ~/Dev/Bin/radare2 

# rtags cache files
% du -sh ~/.cache/rtags/_home_ray_Dev_Bin_radare2_
600M    /home/ray/.cache/rtags/_home_ray_Dev_Bin_radare2_

This comment has been minimized.

MaskRay commented Jan 22, 2018


This comment has been minimized.

cormacc commented Mar 15, 2018

@MaskRay I spent a few hours on a train journey today comparing your cquery and my-code layers with the existing c-c++ layer, paying attention to how ycmd and rtags are integrated in the latter. Have refactored some of the functionality into a reasonably coherent set of additions to the lsp layer with some of the common keybindings, a new cquery layer and some minimal additions to the c-c++ layer in a new branch forked from spacemacs/develop.

Think it's fairly close, but certainly not suitable for a a single PR -- not sure if it's of any use to you, or where to go with it from here, but it's here;


This comment has been minimized.

MaskRay commented Mar 15, 2018

Awesome work! I left some notes. I hope you can make it a PR to supersede mine.


This comment has been minimized.

myrgy commented Mar 21, 2018

from here: #10236

Reworked some of MaskRay's config into a a new PR for the lsp layer, here:

And an attempt at a cquery layer here:

I'll raise a new PR for the cquery layer if the lsp-layer one gets merged (it builds on it).


This comment has been minimized.

arefasvadi commented Apr 26, 2018

I am not an elisp or spacemacs guru, but I think your solution is closest to what I want (cmake support, auto-completion,...). I previously managed to get rtags working, but it's too slow!
I have cloned the "new-cquery-layer" branch from your forked repo. Can I ask your configuraions for .spacemacs file!
Currently I have enabled the following layers:

  1. cquery
  2. cmake with cmake-enable-cmake-ide-support
  3. c++ with variables for cmake-ide-support, enable-clang-support, enable-c++11 support.
  4. lsp

I do not see options for major mode (SPC m j or SPC m h) for cquery layer, or (SPC m T) for lsp. Also I get a lot of errors from flycheck that I guess raised by cquery.


This comment has been minimized.

cormacc commented Apr 26, 2018

Simplest thing is to just include cquery layer. It should include c-c±± and lsp layers automatically -- they're declared as dependencies in the cquery layers.el

Here's my config -- I include lsp layer explicitly to override some defaults...

I enable cmake layer as well, but just for CMAKELISTS syntax support. i.e. without enabling cmake-ide support, as that has some functionality that overlaps/conflicts.

Though it would be nice at some stage to use cmake-ide to pick up changes to cmakelists.txt and regenerate compile_commands.json, using a persistent build pool directory, and configure query to look there rather than in the project root. Assuming you can disable the rest of the cmake-ide functionality (rtags etc.). Not useful enough for any of my current projects to tackle it just now though --- sounds like it would take a while to figure out :) I just regenerate compile_commands.json manually every now and then.

       ;; lsp  and c-c++ layers implicitly loaded by cquery layer...
       (lsp :variables
         ;; ... though loading lsp layer explicitly here to override some defaults
         lsp-ui-peek-expand-by-default t)

This comment has been minimized.

MaskRay commented May 13, 2018

Time passes, I no longer use cquery and have a different plan. I made a fork on Apr 1 (sarcastically!) and renovated it with improvement of import pipeline last weekend and clang+llvm C++ API this weekend. It has only 3 git submodules and the removal of loguru is also in the works. If you are curious enough and intend to give it a try:

If you have at least 16GB memory and are brave enough to compile clang+llvm from source:

Caution: C++17 and Clang C++ API are tough to tame on old distributions.


This comment has been minimized.

balta2ar commented May 14, 2018

no longer use cquery and have a different plan

Why? And what's the plan?

@MaskRay MaskRay changed the title from Add cquery (language server) to c-c++ layer to Add ccls/cquery (language server) to c-c++ layer Jun 9, 2018


This comment has been minimized.

myrgy commented Nov 13, 2018

Since #11242 was merged we can close that issue


This comment has been minimized.


sdwolfz commented Nov 13, 2018

Yes, thanks everybody for participating in this. It was a huge piece of work ❤️!

@sdwolfz sdwolfz closed this Nov 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment