-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 lsp (cquery and ccls) backend support to c-c++ layer #11242
Conversation
5cb6114
to
dcae0cc
Compare
@myrgy You might take a look when you get a chance? @sdwolfz I've derived the backend selection/configuration logic from some of the recent examples you suggested (mostly some useful discussion in the python layer PR) @MaskRay, @sebastiencs either of you have any enlightenment to offer on the |
I think there should be an universal backend variable. This would prevent conflicts in between backends as the variable accepts only one symbol. |
@Compro-Prasad That's my own view too - just want to get confirmation from maintainers that that's acceptable before making the change. |
@cormacc , Thanks a lot for outstanding work! |
Some comments related to variables, docs and formatting. I have not tested it locally yet. |
@cormacc , works fine for me. (y) |
dcae0cc
to
1873303
Compare
Amended the commit incorporating all the requested changes (I think). @myrgy Your suggestion addressed the rainbow semantic highlighting issue -- I was trying to |
layers/+lang/c-c++/config.el
Outdated
initialized. `c-c++-lsp-project-whitelist' is checked first, then this, | ||
if no pattern matches the project root, lsp-c-c++ will be initialized.") | ||
|
||
(defvar c-c++-lsp-sem-highlight-method 'font-lock |
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.
I would suggest removing this option and refer users to ccls/cquery wiki pages. Some people think semantic highlighting distracting.
layers/+lang/c-c++/funcs.el
Outdated
(spacemacs//c-c++-lsp-call-function "spacemacs//c-c++-lsp-" "-customise-lsp-ui-peek") | ||
|
||
(defun c-c++/callers () (interactive) (lsp-ui-peek-find-custom 'callers (spacemacs//c-c++-lsp-string "$" "/callers"))) | ||
(defun c-c++/derived () (interactive) (lsp-ui-peek-find-custom 'derived (spacemacs//c-c++-lsp-string "$" "/derived"))) |
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.
$ccls/derived
$cquery/derived
have both been removed. Users should instead use lsp-goto-implementation
ccls has a flattened $ccls/inheritanceHierarchy
to provide multi-level information but I think it is too implementation-specific and does not worth the common configuration. https://github.com/MaskRay/ccls/wiki/Emacs#ccls-cross-reference-extension
(defun ccls/derived ()
(interactive)
(lsp-ui-peek-find-custom 'derived "$ccls/inheritanceHierarchy"
(append (lsp--text-document-position-params) '(:flat t :level 3 :derived t))))
I was thinking of merging #10454 before this layer, hope it won't cause to much trouble for this PR. |
1873303
to
499649a
Compare
Rebased |
Works fine for me! |
I think I might have found a bug. I'm using cquery as backend, and when doing (c-c++ :variables
c-c++-default-mode-for-headers 'c++-mode
c-c++-backend 'lsp-cquery) Edit: upon further investigation, it seems (add-to-list 'projectile-globally-ignored-directories
(if c-c++-lsp-cache-dir c-c++-lsp-cache-dir '(".cquery_cached_index" ".ccls-cache"))) Is not the correct way of doing it:
|
499649a
to
fb150a9
Compare
Thanks @rcoacci - yesterdays amendment resulted in appending a list to projectile-globally-ignored-directories rather than individual strings. Fixed/amended/pushed |
Another thing: emacs is hanging a lot when the using the layer, it seems related to the server being busy (indexing probably, |
@rcoacci Can't comment there I'm afraid. My use to date has been almost entirely on an embedded C project, which has about 1300 source files, but very few external dependencies. Performance satisfactory here. Some discussion here that may be of some use to you jacobdufault/cquery#278 |
layers/+lang/c-c++/README.org
Outdated
To enable the rainbow semantic highlighting colour theme, set =c-c++-lsp-sem-highlight-rainbow= to =t=. | ||
|
||
***** Additional configuration options | ||
Both supported backends store their index cache in a subdirectory of the project dir by default. This can be overridden by |
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.
This doesn't seem correct. The default behavior of the layer is to use a subdirectory of spacemacs cache dir as index cache.
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.
Good catch - thanks. Changed the default config based on feedback from sdwolfz and forgot to update the README. Corrected / commit amended
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.
I don't think it is the right way to do it. The stuff in .cache is from .emacs.d and not from local project. It is nice to have an option but I don't think it is mandatory to do it.
@cormacc I'm willing to blame my project config for now. If I remove the compile_commands.json from the project, it seems to work better. |
fb150a9
to
f89d121
Compare
@rcoacci Give ccls a try? It leverages some preamble optimization which should accelerate diagnostics,completion a bit (libclang cannot use this trick). I've also just pushed a commit to optimize indexing when the current file is opened. Completion and diagnostics are done in two separate threads (in both ccls and cquery). In ccls, the preamble (the #include part of your main source file) is shared by the two threads. For a simple project that you don't want to save cache to the disk, and if you want to re-index for every change (cautious: it may hurt performance), use the following initialization options: {
"cacheDirectory": "",
"index": {"onChange": true}
} In Emacs: (setq ccls-cache-dir "")
(setq ccls-extra-init-params '(:index (:onChange t))) There is another ccls-specific feature semantic navigation for which I do not recommend adding default key bindings. |
Is there a way to disable lsp-ui-peek features/keybindings and only use xref-* interfaces provided by lsp-mode ? Right now I am adding lsp-ui to dotspacemacs-excluded-packages. But things like xref-find-definitions and all don't have any key binding. |
Wow. What a PR. @sdwolfz what do you think about it? |
I'm trying to find the time to review this properly and merge, but I'm optimistic about it. |
@sdwolfz I've rebased the blocking #11351 on develop if you want to take a look at that first. Think it should be a pretty safe merge as the changes are in default core keybinding functions I contributed myself and no other layers are using. I'll rebase and push a new commit of this PR once that one gets resolved either way. |
layers/+lang/c-c++/README.org
Outdated
|
||
***** Additional configuration options | ||
Both lsp backends are configured to store their index cache in a subdirectory of =.emacs.d/cache=. This can be overridden by | ||
specifying an explicit =lsp-c-c++-cache-dir=. Setting this value to a relative path will cause the index cache to be placed in a |
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.
Hi, lsp-c-c++-cache-dir
should be c-c++-lsp-cache-dir
because
;; c-c++-lsp-backend variables
(defvar c-c++-lsp-cache-dir nil
"Cache directory. Absolute and relative paths supported.")
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 iromise -- corrected
a4032ed
to
0635b4f
Compare
@myrgy I've pushed an updated version of this based on #11351 that I've been sitting on for a while - you might let me know if it resolves the ccls issues you were patching around locally if you get a chance to evaluate? I haven't had any issues in the last few weeks, though admittedly have been doing more python and planning/scoping than C in that period... |
@cormacc , thank you! I'll give a try on thursday |
0635b4f
to
b671053
Compare
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.
@cormacc I have the current version in productive development since yesterday and so far it is working properly. Replaces my own local ccls integration and I am more than happy with your current solution.
layers/+lang/c-c++/README.org
Outdated
(setq-default dotspacemacs-configuration-layers | ||
'((c-c++ :variables | ||
c-c++-adopt-subprojects t | ||
c-c++-backend 'ccls |
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.
Above the backend variable reads 'lsp-ccls
, here just 'ccls
.
c-c++-backend 'ccls | |
c-c++-backend 'lsp-ccls |
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 svenihoney - updated the readme. @sdwolfz , you happy enough to use the 'Apply suggestion' feature as a general rule? Looks very convenient for this sort of change (oversights in the README). I'd imagine it probably results in a new commit though rather than an amendment (which appears to be the recommended approach in the beginner's guide to PRs)? Regardless, went with the traditional git commit --amend
, git push --force
in this instance, pending enlightenment :)
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.
It's a nice feature but I would like to have as few commits as possible at the end. So if they are small fixups then I'd preffer they be squashed anyway.
b671053
to
1cfd3ff
Compare
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.
Looks good, I'll merge it this evening. Thanks everybody for the effort, and sorry it took so long to review.
1cfd3ff
to
37f658b
Compare
@cormacc Looks like you need to rebase on top of the current develop. |
<<Amendment 1 01/09/2018>> Incorporated initial feedback from multiple sources (PR discussion) <<Amendment 2 04/09/2018>> Incorporated feedback from MaskRay. Fixed projectile post-config hooks. Added `c-c++-adopt-subprojects' layer option. <<Amendment 3 07/09/18>> Corrected cache section in README to describe new cache defaults introduced by Amendment 2. <<Amendment 4 13/09/18>> Corrected config var names in readme. Rebased on current develop branch tip. <<Amendment 5 14/09/18>> Minor adaptations for compatibility with upstream ccls changes. <<Amendment 6 21/09/18>> Bindings updated for consistency with lsp layer lsp-navigation config variable. <<Amendment 7 1/11/18>> Rebased <<Amendment 8 06/11/18>> Incorporated readme correction from svenihoney. <<Amendment 9 06/11/18>> Updated c-c++/refresh-index wrapper for ccls function renamed upstream. Moved 2 bindings from 'l' to 'b' to reflect updated lsp-layer mnemonic
37f658b
to
be587cc
Compare
@cormacc , I gave a try - seems to work fine for me 👍. (ccls) |
@JAremko the |
'((c-c++ :variables c-c++-backend `lsp-cquery))) ;or 'lsp-ccls | ||
#+END_SRC | ||
|
||
N.B. The [[../../+tools/lsp/README.org][LSP layer]] will be loaded automatically if either backend is selected. |
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.
@sdwolfz Should be [[file:../../+tools/lsp/README.org][LSP layer]]
Actually the current one is also valid but we a bit strict about it. Mb too strict 🤔
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.
I'll add it to autofixes.
Thank you ❤️! There was a problem with the Cherry-picked into develop branch, you can safely delete your branch. |
Great! Thanks @sdwolfz |
Sorry, I am kinda new to all of this LSP thing. How can I setup it easily for my spacemacs? |
@vityafx Please open an issue if you find something missing or open a PR if you have a solution or discuss about this somewhere else. |
N.B. This PR should be considered as on hold pending acceptance/rejection of #11351 . The current commit
is functional for evaluation purposes, however the keybinding logic will be updated to reflect the navigation style preferences in #11351 if that gets merged.includes the lsp layer changes to facilitate evaluation in the interimMigrated the cquery and ccls work from a separate
lsp-c-c++
layer to the existingc-c++
layer.Enabled by adding the following to your spacemacs dotfile.
More detailed information has been added to the README.
The
clang-format-
keybindings will be added automatically if either lsp backend is selected.This is just to get the ball rolling -- appears to work as the previous
lsp-c-c++
layer based on some quick and dirty testing with both cquery and ccls backends.The rough edges I'm aware of so far...
Settingc-c++-lsp-sem-highlight-rainbow
tot
results in an error. The macros<cquery/ccls>-use-default-rainbow-sem-highlight
don't seem to be in scope when the layer is loaded, though they're provided by their respective packages -- suggestions welcome. This did work in some earlier incarnation of thelsp-c-c++
layer, but had stopped doing so before this most recent bit of integration. No idea whether it's something I've done or an upstream change affecting scope of package macros.Fixed based on myrgy's suggestion
RTags is enabled by the existing mechanism of settingc-c++-enable-rtags-support
tot
. It would be neater to setc-c++-backend
to'rtags
instead, but I don't know what the policy is on changing layer configuration mechanisms. Again, guidance welcome. The existing config var may benil
t
or'no-completion
. If moving to usingc-c++-backend
desirable, would it be preferable to(a) allow values of
'rtags
and'rtags-no-completion
, or(b) just
rtags
and add a newc-c++-rtags-completion
variable with a default value oft
?RTags now enabled using the new
c-c++-backend
config.el variable. Completion enabled by default, disabled by setting newc-c-++-enable-rtags-completion
config.el variable tonil