cquery
C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more
Top Related Projects
C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
clangd language server
Official repository for the Microsoft C/C++ extension for VS Code.
Bear is a tool that generates a compilation database for clang tooling.
A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
A code-completion engine for Vim
Quick Overview
cquery is a highly-scalable, low-latency language server for C/C++/Objective-C. It is designed to provide IDE-like features such as code completion, navigation, and diagnostics to any editor that supports the Language Server Protocol (LSP). cquery aims to be fast and efficient, even for large codebases.
Pros
- Extremely fast indexing and querying, especially for large projects
- Low memory footprint compared to other language servers
- Supports a wide range of C++ language features, including templates and macros
- Integrates well with various editors through the Language Server Protocol
Cons
- Development has been discontinued, with the last update in 2019
- May have compatibility issues with newer C++ standards and compiler versions
- Setup and configuration can be complex for beginners
- Limited documentation and community support due to discontinued development
Getting Started
To get started with cquery, follow these steps:
-
Clone the repository:
git clone https://github.com/jacobdufault/cquery.git cd cquery
-
Build cquery:
mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=release -DCMAKE_EXPORT_COMPILE_COMMANDS=YES make -j8 make install
-
Configure your editor to use cquery as the language server for C/C++ files. The exact steps depend on your editor, but generally involve specifying the path to the cquery executable and any necessary configuration options.
-
Create a
.cquery
file in your project root with compilation flags:%clang %c -std=c11 %cpp -std=c++14 -I/path/to/your/include/directory
-
Open a C/C++ file in your configured editor and start using cquery's features.
Note: Since cquery is no longer actively maintained, consider using alternatives like clangd or ccls for more up-to-date C/C++ language server support.
Competitor Comparisons
C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Pros of ccls
- Actively maintained and regularly updated
- Better performance and lower memory usage
- Supports more languages, including Objective-C and Objective-C++
Cons of ccls
- Steeper learning curve for configuration
- Less extensive documentation compared to cquery
Code Comparison
ccls:
#include <clang/Tooling/CompilationDatabase.h>
#include <clang/Tooling/Tooling.h>
#include <llvm/Support/CommandLine.h>
int main(int argc, const char** argv) {
// ccls-specific initialization code
}
cquery:
#include <clang-c/Index.h>
#include <llvm/Support/CommandLine.h>
#include <rapidjson/document.h>
int main(int argc, char** argv) {
// cquery-specific initialization code
clangd language server
Pros of clangd
- Actively maintained and developed by the LLVM community
- Broader language support, including C, C++, Objective-C, and CUDA
- Better integration with other LLVM tools and libraries
Cons of clangd
- Can be slower for large projects compared to cquery
- May require more configuration for optimal performance
- Less focus on low-latency code completion
Code Comparison
cquery:
void IndexFile::serialize(std::string& output) {
flatbuffers::FlatBufferBuilder builder;
auto root = Serialize(builder);
builder.Finish(root);
output.assign(
reinterpret_cast<const char*>(builder.GetBufferPointer()),
builder.GetSize());
}
clangd:
void IndexFileOut::serialize(raw_ostream &OS) const {
using namespace llvm::yaml;
Output Out(OS);
Out << *this;
}
Both projects aim to provide language server capabilities for C-family languages, but they differ in their approach and focus. clangd benefits from being part of the larger LLVM ecosystem, while cquery was designed with a strong emphasis on performance for large codebases. However, cquery is no longer actively maintained, which gives clangd an advantage in terms of ongoing development and support.
Official repository for the Microsoft C/C++ extension for VS Code.
Pros of vscode-cpptools
- Actively maintained by Microsoft with frequent updates
- Seamless integration with Visual Studio Code
- Extensive documentation and community support
Cons of vscode-cpptools
- Heavier resource usage, especially for large projects
- Can be slower in indexing and providing IntelliSense
Code comparison
vscode-cpptools:
#include <vector>
#include <string>
std::vector<std::string> example() {
return {"Hello", "World"};
}
cquery:
#include <vector>
#include <string>
std::vector<std::string> example() {
return {"Hello", "World"};
}
Additional notes
cquery is a lightweight, fast C/C++ language server with low memory usage, while vscode-cpptools is a more comprehensive extension for Visual Studio Code. cquery focuses on performance and minimal resource consumption, making it suitable for large codebases. However, it's worth noting that cquery development has been discontinued, which may impact its long-term viability.
vscode-cpptools offers a broader range of features, including debugging capabilities and IntelliSense, making it a more all-in-one solution for C/C++ development in Visual Studio Code. The choice between the two depends on project requirements, system resources, and personal preferences.
Bear is a tool that generates a compilation database for clang tooling.
Pros of Bear
- Language-agnostic tool for generating compilation databases
- Supports multiple build systems (Make, CMake, etc.)
- Lightweight and easy to integrate into existing workflows
Cons of Bear
- Requires running the build process to generate compilation database
- May not capture all compilation commands in complex build systems
- Limited to compilation database generation, not a full-fledged language server
Code comparison
Bear (compilation command interception):
def capture(command, cwd, verbose):
environment = setup_environment(verbose)
return subprocess.call(command, cwd=cwd, env=environment)
cquery (indexing and query handling):
void IndexFile(const std::string& path,
const std::vector<std::string>& args,
bool is_interactive,
const std::string& contents) {
// Indexing logic
}
Bear focuses on intercepting compilation commands, while cquery provides more comprehensive language server functionality for C/C++ projects. Bear is more versatile across languages but limited in scope, whereas cquery offers deeper integration and features specifically for C/C++ development environments.
A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
Pros of rtags
- More mature project with longer development history
- Supports integration with popular editors like Emacs and Vim
- Offers a client-server architecture for better performance in large projects
Cons of rtags
- Requires more setup and configuration compared to cquery
- Can be slower for initial indexing of large codebases
- Less active development in recent years
Code comparison
rtags:
class RTags {
public:
static void init();
static void shutdown();
static std::shared_ptr<Project> findProject(const Path &path);
};
cquery:
struct Config {
std::string projectRoot;
std::vector<std::string> extraClangArguments;
bool index = {true};
};
struct ClangIndex {
ClangIndex(Config config);
void index(const std::string& path);
};
The code snippets show that rtags focuses on project management and initialization, while cquery emphasizes configuration and indexing. rtags uses a static class approach, whereas cquery employs structs for configuration and indexing.
Both projects aim to provide C/C++ language services, but their implementations and focus areas differ slightly. rtags offers a more established ecosystem with editor integrations, while cquery aims for simplicity and ease of use.
A code-completion engine for Vim
Pros of YouCompleteMe
- More comprehensive language support, including Python, JavaScript, and Rust
- Integrates well with Vim and offers a seamless editing experience
- Active development and large community support
Cons of YouCompleteMe
- Can be complex to set up and configure
- Higher resource usage, which may impact performance on older systems
Code Comparison
YouCompleteMe configuration in .vimrc:
let g:ycm_auto_trigger = 1
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_complete_in_comments = 1
cquery configuration in .vimrc:
let g:LanguageClient_serverCommands = {
\ 'cpp': ['cquery', '--log-file=/tmp/cq.log'],
\ 'c': ['cquery', '--log-file=/tmp/cq.log'],
\ }
While both projects aim to provide code completion and analysis, YouCompleteMe offers a more comprehensive solution with broader language support. However, cquery focuses specifically on C/C++ and may provide better performance for these languages. The choice between the two depends on the user's specific needs and the languages they work with most frequently.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Archived
cquery is no longer under development. clangd and ccls are both good replacements.
cquery
cquery is a highly-scalable, low-latency language server for C/C++/Objective-C. It is tested and designed for large code bases like Chromium. cquery provides accurate and fast semantic analysis without interrupting workflow.
cquery implements almost the entire language server protocol and provides some extra features to boot:
- code completion (with both signature help and snippets)
- finding definition/references
- call (caller/callee) hierarchy, inheritance (base/derived) hierarchy
- symbol rename
- document symbols and approximate search of workspace symbol
- hover information
- diagnostics
- code actions (clang FixIts)
- preprocessor skipped regions
- #include auto-complete, undefined type include insertion, include quick-jump (goto definition, document links)
- auto-implement functions without a definition
- semantic highlighting, including support for rainbow semantic highlighting
>>> Getting started (CLICK HERE) <<<
Limitations
cquery is able to respond to queries quickly because it caches a huge amount of information. When a request comes in, cquery just looks it up in the cache without running many computations. As a result, there's a large memory overhead. For example, a full index of Chrome will take about 10gb of memory. If you exclude v8, webkit, and third_party, it goes down to about 6.5gb.
License
MIT
Top Related Projects
C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
clangd language server
Official repository for the Microsoft C/C++ extension for VS Code.
Bear is a tool that generates a compilation database for clang tooling.
A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
A code-completion engine for Vim
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot