8 ms·
Cquery: highly-scalable, low-latency language server for C++
- snowAbstraction 9y agoIs this like https://github.com/Andersbakken/rtags https://github.com/Andersbakken/rtags but for vscode? Any key differences?
- jchw 9y agoFor one thing, it sounds like it implements the Language Server protocol, which will make it usable for other IDEs and text editors with support for this protocol (a quickly growing list.) Not aware of Rtags but I'll assume it's similar to the omnipresent C tags but with an actual C++ parser. If that's the case, in theory cquery is a lot more powerful; it would include the symbol indexing of Rtags but also code refactoring tools ("fixits",) fully aware context-sensitive auto-complete, ability to detect dead code (i.e. #if 0 or #ifndef _WIN32) and support for the type hierarchy. Some of that stuff is definitely not supported by LSP so I imagine it's custom stuff for VSCode only. All in all, it sounds like it would provide most of the IDE experience to VS Code. The only annoying part would be that you'll have to extract the compile flags from your build system yourself, but that's not usually too big of a deal.
- snowAbstraction 9y agortags is also using libclang for parsing, fixits, etc. Here is a demo of rtags can do with a proper emacs setup: CppCon 2015: Atila Neves "Emacs as a C++ IDE" https://youtu.be/5FQwQ0QWBTU https://youtu.be/5FQwQ0QWBTU
- jchw 9y agoedit: Comment above has updated with more information, making this reply redundant. :)
- to3m 9y agoOne interesting thing that rtags does is provide a gcc/clang wrapper script. You make symlinks to it called cc/c++/gcc/g++/etc. in a folder that's in PATH ahead of wherever gcc/clang proper live. When invoked, the script submits an appropriate tags job to the rtags server, complete with compile flags actually used, then passes the command line on to the appropriate tool so that the compile actually gets done. So quite often you won't need to do anything. (If you use CMake, you will have to rebuild your Ninja/make files after first setting this up.) I didn't find rtags perfect. There were a few files that it simply never seemed to create tags for, and the rtags setup is complicated enough that I couldn't quickly figure out why, so I just put up with it. But when it works, it works very well... (This sort of thing seems to be par for the course with this kind of tool. I've seen a number of people complain about how terrible Visual Studio's code browsing is, for example, but it's been a long time since I've had a problem with it...)
- sient 9y ago> All in all, it sounds like it would provide most of the IDE experience to VS Code. The only annoying part would be that you'll have to extract the compile flags from your build system yourself, but that's not usually too big of a deal. This can be done similar to what rtags does (hooking into gcc/clang invocations). Alternatively if you use ninja this relatively simple by generating a compile_commands.json file. ninja -C out/Release -t compdb cxx cc > compile_commands.json My eventual plan is to automate compile_commands.json generation if using ninja, so cquery is install and go.
- sient 9y agoI tried using rtags before developing cquery, but found it did not perform well enough for Chrome when doing a huge number of semantic operations (I was hacking in support for code lens). I spent some time trying to figure out if it code be fixed but I believe it would have been too large of an architectural change. - cquery interacts with an editor via the language server protocol, letting it work with any editor with relatively minimal work - cquery handles larger repositories better (ie, indexing all of Chrome takes 20-30 minutes on a high-end workstation) - cquery responds to semantic requests within 10ms or so There are some other differences but those are related to the features implemented, ie, cquery supports code lens. I'm not sure how code completion is in rtags, but I've spent a fair amount of time making it work as fast as possible in cquery. There is quite a bit of caching built on-top of the clang API which often makes it feel instantaneous.
- qyron 9y agoI've been happy user of ycmd+rtags tandem for a couple of years. A killer feature of rtags me is its ability to run server on remote machine (of course source code must be mirrored too). This allows me to do develop on my weak 4-core laptop and offload indexing to fast 32-core workstation. Regarding indexing time, all of these tools seem to parse source code using either libclang (C API) or "native" C++ API (RecursiveASTVisitor etc.), so IMHO any difference in indexing time between rtags and cquery should come from such factors as number of parsing threads, database for storing tags, caching etc. Anyway I'm really excited about cquery and even consider moving to VSCode just because of it (being a long-term VIM user). Reliable "Find references" feature is (IMHO) a must-have functionality for large codebases and currently (thanks to cquery and rtags) is supported much better in modern C++ than in other system languages (such as Go and Rust).
- sient 9y ago> A killer feature of rtags me is its ability to run server on remote machine (of course source code must be mirrored too). I have a similar use case in mind, so I'm planning on trying to get this working by writing a simple script that proxies language server messages over SSH/TCP. Ideally it should work with any language server. > Regarding indexing time, all of these tools seem to parse source code using either libclang (C API) or "native" C++ API (RecursiveASTVisitor etc.), so IMHO any difference in indexing time between rtags and cquery should come from such factors as number of parsing threads, database for storing tags, caching etc. Yea, it is amazing how big of a difference the architecture around indexing makes - any sort of global lock/shared state really hurts performance. I spent a significant amount of time finding the right architecture to make each index job as independent as possible. Most of the design decisions in cquery are oriented towards either latency or throughput at the cost of things like memory and total system load (I've since reduced memory usage, but at one point cquery used 30gb after indexing Chrome - now it is around 5gb). > Anyway I'm really excited about cquery and even consider moving to VSCode just because of it (being a long-term VIM user). Reliable "Find references" feature is (IMHO) a must-have functionality for large codebases and currently (thanks to cquery and rtags) is supported much better in modern C++ than in other system languages (such as Go and Rust). I'd like to see cquery support in vim as well using a vim LSP implementation :). But yes, I agree with you - cquery makes me want to continue using C++ over Rust simply because the tooling works a lot better.
- photonios 9y agoI can only applaud this effort!
- speps 9y agoIs there one similar to this but that doesn't require your code to compile under Clang? I have plenty of projects at home that don't instantly work under Clang. So far, I've never seen any C++ language server that doesn't rely on Clang unfortunately.
- orbifold 9y agoUnlikely because GCC deliberately made it hard to reach into its internals for a long time. The only other implementation is the one by Microsoft based (presumably) on their C++ compiler.
- feanaro 9y agoWhat are the usual culprits that prevent it from working under clang?
- jhasse 9y agoClang doesn't support template<class ...Args> void foo(int x = 0, Args&&... args) for example (default argument before variadic templates args).
- lfowles 9y agoWow, I was going to guess that was illegal anyways, but cppref validates that behavior[0]. 0: http://en.cppreference.com/w/cpp/language/default_arguments http://en.cppreference.com/w/cpp/language/default_arguments
- snowAbstraction 9y agoI remember an old project to use the Eclipse CDT C++ support via vim instead of in the Eclipse IDE: http://eclim.org/index.html http://eclim.org/index.html I think there is/was some attempt to do it for emacs as well.
- emmelaich 9y agoThere is a LSP in progress for clang C/C++. https://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clangd/ https://reviews.llvm.org/diffusion/L/browse/clang-tools-extr...
- krylon 9y agoWow! I consider myself lucky that I practically do not have to deal with C++, but if I were a C++ kind of person, right now I would deeply appreciate how much hard work goes into a tool like this. [1] In order to be any good, it has to be even more clever than the compiler, at least in a few ways. And I have a hunch that in the field of programming languages that are used these days, C++ is probably not the easiest one to write such an analyzer for. ;-) TL;DR - Respect! I can only - but vividly - imagine how hard it must be to create a tool like this. [1] I have mixed feelings regarding C++, because I have only used it in tiny doses. I treat the language the same way I would treat a bear, if one suddenly appeared: Keep my distance, avoid any sudden motions, but also, under no circumstances, dare I turn my back on it because of the slight chance that it might come after me eventually. I do not actively dislike C++, I just have not found the time to learn it, and I get the impression that if I really want to learn it, it will take much more time than I can currently afford to invest. Maybe some day it will come to pass (that will be a good day also to finally read Moby Dick all the way through from end to end.)
- phaedrus 9y agoSome advice if you do decide to learn C++: there has been a steady stream of improvements in standard C++ the past 8 years (C++11-17), and some (Bjarne Stroustroup, Herb Sutter, others) promote it as a better starting point for beginners under the name 'Modern C++'. From: https://msdn.microsoft.com/en-us/library/hh279654.aspx https://msdn.microsoft.com/en-us/library/hh279654.aspx "[...] Over the years, features have been added to the language, together with highly-tested standard libraries of data structures and algorithms. It's these additions that have made the modern C++ style possible. Modern C++ emphasizes: Stack-based scope instead of heap or static global scope. Auto type inference instead of explicit type names. Smart pointers instead of raw pointers. std::string and std::wstring types (see <string>) instead of raw char[] arrays. Standard template library (STL) containers like vector, list, and map instead of raw arrays or custom containers. See <vector>, <list>, and <map>. STL algorithms instead of manually coded ones. Exceptions, to report and handle error conditions. Lock-free inter-thread communication using STL std::atomic<> (see <atomic>) instead of other inter-thread communication mechanisms. Inline lambda functions instead of small functions implemented separately. Range-based for loops [...]"
- tinganho 9y agoHow does this compare with Microsoft's https://github.com/Microsoft/vscode-cpptools https://github.com/Microsoft/vscode-cpptools?
- jhasse 9y agoWow! I've just tested this and it's awesome. Much better than the C/C++ extension, since it's more robust (no false-positives for go-to-definition), faster and has more features (e.g. refactoring, better auto-complete, ...). It basically turns VS Code into the best C++ IDE possible for me.
- makapuf 9y agoIt's not really linked to VSCode, is it ? i was under the impression that by example Sublime integration for LSP was possible.
- iainmerrick 9y agoYep, the idea is that the same protocol can work with any editor: https://langserver.org https://langserver.org
- jdlyga 9y agoThis looks nice. Reminds me a lot of the Clang Code Model that I use with QtCreator.
- sient 9y agoAuthor here! Wasn't quite ready to post to HN yet since cquery is still in development, and I plan to eventually publish on the vscode marketplace so using cquery should be as simple as using the existing C/C++ extension. Let me know if you have any questions.
- misterHN 9y agoIs there a "hello, world" example for cquery?
- systems 9y agoAny plans for Cmake support?
- sient 9y agoIn what sense? cmake can generate compile_commands.json so projects built using cmake are supported.
- izym 9y agoDoes this support Objective-C++? If not, do you have any plans to implement support for it?
- sient 9y agoI have not tested it, but it should be a relatively straightforward to get working. Feel free to file an issue on github.
- archgoon 9y agoHi! I see you're using compile_commands.json. How are you handling header files? I've found that header files present problems for compile_commands since a number of tools using compiler_commands (like bear) only look at the compiler commands for .c files, and don't notice that the header files should be added as well. I know that some tools, like YCM, attempt to intelligently map a header file to it's associated .cpp/.cc/.c file to guess what the compiler commands are, but this doesn't always work. What is the state of generating compiler_commands.json for Chromium? I remember running into this issue a few years back.
- jdright 9y agoRun away from Jonathan Blow, as of today he was full rant mode on language server and similar stuff including on people that think this is a acceptable stuff, notably Hacker News audience. FYI, I 150% disagree with his useless rants.
- iainmerrick 9y agoI saw that on Twitter but I couldn't figure out what his actual complaint was. I think I'd probably disagree but I'm still interested in knowing.
- cgag 9y agoThat doing all of this stuff via rpcs vs function calls is crazy I believe.
- iainmerrick 9y agoHe's not totally wrong, but casting it as a 100% clear-cut decision -- with the RPC version as the obviously bad, "highly damaging" choice -- is just wilfully stupid and dishonest. It's clearly a tradeoff.
- pjmlp 9y agoSpecially from security point of view. There is a reason why most of us learned our lesson and moved plugins out-of-process. Performance can still be achieved via shared memory, exposing much less data from the host process.
- emmelaich 9y agoNot only via rpc but json over rpc, because latency. He has a point but there's nothing to stop you bringing some of this in-process or caching aggressively.
- Too 9y agoMaybe if your code lives in a small bubble with everybody using the same IDE but definitely not for larger projects. For huge projects you want the build/index performance from a fast build server rather than a laptop, buildi environment inside a docker container, IDE in windows and build in linux, free choice of IDE rather than tighlty tied plugins. Though i fully agree that json might not be the best packaging.
- blaket 9y agoWhat's the word on using this with emacs?
- sient 9y agoEventually this will be supported with lsp-mode. If you check https://gitter.im/cquery-project/Lobby https://gitter.im/cquery-project/Lobby @topisani made good progress here quickly and already has cquery up and running.
- snowAbstraction 9y agoSearch for the discussion about rtags. It does something similar for emacs using libclang.
- rombix 9y agoThis project seems to be very similar to clangd. It is also similar to YouCompleteMe, though YCM does not support LSP yet. How does Cquery compare to those projects in terms of features? In particular, should it be considered as an alternative to clangd? Could it make sense to combine efforts between clangd and Cquery?
- sient 9y agoAt the moment, clangd and ycm are very similar projects; they are very limited compared to cquery. clangd and ycm support code completion, diagnostics, fixits, and goto declaration (but not definition), whereas cquery supports references, derived types, callers, etc. Basically, if the feature requires knowledge across multiple translation units, clangd/ycm do not support it. cquery is designed to support very large projects, so it makes very specific design decisions w.r.t. the data model, indexing pipeline, and multithreading model. I hope clangd can match the performance - but so far every project I've seen simply does not run nearly fast enough on a code-base the size of Chrome/ChromeOS.
- rombix 9y agoThanks for the explanations! In the meantime I tried it out with VSCode on my MacBook. Works like a charm! Awesome job!!!
- yalph 9y agoUse c++ on a daily basis. I think the direction the language is going is really really troublesome. It was a mistake to follow the boost’s lead. At this point language is more or less a clusterfuck. While python peeps are saving the world here on this dark side of the world we wrestle with move semantics. Simplicity and beauty of C is long gone.
- sobellian 9y agoI used to use C++ a lot for a mixture of reasons. I avoid it like the plague now, because I'm not confident that anyone completely understands the semantics of a non-trivial C++ program. Even if I did, the cognitive overhead of this stuff detracts from real programming.
- yalph 9y ago> Even if I did, the cognitive overhead of this stuff detracts from real programming. You are absolutely right.And why the standard comittee dont see this is beyond me.
- kraghen 9y agoI have a suspicion that all non-trivial C++ programs contain undefined behaviour (e.g. not checking for or preventing overflow at every arithmetic operation involving signed integers), so trying to understand the semantics of these programs is kind of a moot point. On the other hand, if anyone tried to formalise the semantics of C++ and prove some kind of soundness theorem they would probably find that the language definition is technically inconsistent. Paraphrasing Feynman, if you think you understand C++ then you don't understand C++.
- fhood 9y agoAlso use c++ on a daily basis. It is a dark place, full of nooks and crannies inhabited by venomous insects that only get more dangerous with age. Also you cant declare a variable without constructing it or making it a raw pointer. Which. is. bullshit. Edit: also, the memory issue for these types of services is a huge problem for me, since I am usually working on multiple projects at once, and when combined with all 32 of my chrome tabs, my work laptop starts to indicate some unhappiness.
- pollow 9y agoLooks pretty, I wonder how it different from ycmd?
- sient 9y agoSee https://news.ycombinator.com/item?id=15725119 https://news.ycombinator.com/item?id=15725119