Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add ccls/cquery (language server) to c-c++ layer #10134
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.
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 https://github.com/jacobdufault/cquery/wiki/Emacs 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 https://melpa.org/#/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 https://melpa.org/#/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
A brief list of what can be improved
If you speak Chinese, I've written an article introducing cquery and my configuration http://maskray.me/blog/2017-12-03-c++-language-server-cquery
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 was referenced
Jan 18, 2018
referenced this issue
Jan 28, 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;
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.
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.
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: https://github.com/MaskRay/ccls/wiki/Build#link-against-clangllvm-libraries-compiled-from-source
Caution: C++17 and Clang C++ API are tough to tame on old distributions.