Skip to content

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

@MaskRay

Description

@MaskRay

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.

https://github.com/MaskRay/ccls libclang + Clang C++
https://github.com/cquery-project/cquery 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 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

See also:
cquery.el: https://github.com/cquery-project/emacs-cquery/blob/master/cquery.el
lsp-mode https://github.com/emacs-lsp/lsp-mode
lsp-ui https://github.com/emacs-lsp/lsp-ui

A brief list of what can be improved

rainbow semantic highlighting
comments
semantic highlighting
completion
approximate workspace/symbol search

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions