Skip to content
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 +tools/cquery layer #10236

Closed
wants to merge 1 commit into from
Closed

Add +tools/cquery layer #10236

wants to merge 1 commit into from

Conversation

MaskRay
Copy link
Contributor

@MaskRay MaskRay commented Jan 23, 2018

tl;dr https://github.com/cquery-project/cquery/wiki/Emacs
https://www.reddit.com/r/emacs/comments/806mgw/recent_improvement_of_cquery_and_emacscquery/

cquery is a low-latency language server supporting multi-million line C++ code-bases, powered by libclang.

Since current c-c++ layer needs cleanup and I am not an experienced elisp or spacemacs user, I decide to put it into +tools/ instead of +lang/c-c++/. Another reason doing this is that cquery also supports Objective-C as libclang supports it, though probably with many issues because of the lack of Objective-C users 😜 Anyway, I hope more experienced user can move it into +lang/c-c++ or elsewhere that is appropriate.

+tools/cquery depends on +tools/lsp, which is added in another PR #10211

@Jackson-soft
Copy link

good!!

@MaskRay
Copy link
Contributor Author

MaskRay commented Feb 19, 2018

With this PR, basic features work fine:

  • xref-find-definitions and xref-find-references
  • document symbol highlight
  • completion-at-point
  • company-lsp

Some tricky parts. cquery saves a copy of indexed source files (so that it can serve requests when the index is out-of-sync with the source file in editing) in .cquery_cached_index (relative to the project root by default) and these files may be listed by projectile, which is certainly undesired.

Adding the cache directory to projectile-globally-ignored-directories works but if the user customizes cquery-cache-dir, the logic blacklist directory should be changed accordingly.

    (require 'projectile)
    (add-to-list 'projectile-globally-ignored-directories ".cquery_cached_index")

cquery users usually do not use ycmd for completion. However, ycmd is enabled by default in +lang/c-c++/packages.el. I personally use dotspacemacs-excluded-packages '(cmake-ide info+ racer ycmd)

(cquery-use-default-rainbow-sem-highlight) is nice but I do not enable it in this PR because for larger source file the overlay rendering in Emacs may be very slow.

Here is my personal layer https://github.com/MaskRay/Config/blob/master/home/.emacs.d/private/%2Bmy/cquery/packages.el

Some shortcuts are really nice but I do not know where I should bind them.

    (dolist (mode '("c" "c++" "go" "haskell" "javascript" "python" "rust"))
      (let ((handler (intern (format "spacemacs-jump-handlers-%s-mode" mode))))
        (add-to-list handler 'lsp-ui-peek-find-definitions))
      (let ((handler (intern (format "spacemacs-reference-handlers-%s-mode" mode))))
        (add-to-list handler 'lsp-ui-peek-find-references)))

    (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"))

    (spacemacs/set-leader-keys-for-minor-mode 'lsp-mode
      "la" #'lsp-ui-find-workspace-symbol
      "lA" #'lsp-ui-peek-find-workspace-symbol
      "lf" #'lsp-format-buffer
      "ll" #'lsp-ui-sideline-mode
      "lD" #'lsp-ui-doc-mode
      "ln" #'lsp-ui-find-next-reference
      "lp" #'lsp-ui-find-previous-reference
      "lr" #'lsp-rename
      )

    (dolist (mode c-c++-modes)
      (spacemacs/set-leader-keys-for-major-mode mode
        "lb" #'cquery/base
        "lc" #'cquery/callers
        "ld" #'cquery/derived
        "lR" #'cquery-freshen-index
        "lv" #'cquery/vars
        "l SPC" #'cquery/random
       ))

@sdwolfz
Copy link
Collaborator

sdwolfz commented Feb 19, 2018

How does cquery behave when the .cquery_cached_index directory is located in the project directory and you execute git clean -fdx? Does it know to rebuild it or does it glitch out / crash?

@MaskRay
Copy link
Contributor Author

MaskRay commented Feb 19, 2018

How does cquery behave when the .cquery_cached_index directory is located in the project directory and you execute git clean -fdx? Does it know to rebuild it or does it glitch out / crash?

@jacobdufault to answer this question.

@MaskRay
Copy link
Contributor Author

MaskRay commented Feb 26, 2018

I hope someone could pick this up and make +lang/c-c++ layer accept cquery as a backend.


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
@iromise
Copy link

iromise commented Mar 7, 2018

Hope it can be integrated in spacemacs soon.

@cormacc
Copy link
Contributor

cormacc commented Mar 20, 2018

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

And an attempt at a cquery layer here:
cormacc@b8ae1bc

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants