Top Related Projects
A Rust compiler front-end for IDEs
Repository for the Rust Language Server (aka RLS)
Language Server Protocol (LSP) support for vim and neovim.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
async language server protocol plugin for vim and neovim
Quick Overview
Racer is a code completion and navigation tool for Rust. It provides fast and accurate code intelligence, including auto-completion, go-to-definition, and find-references functionality. Racer is designed to be integrated into various text editors and IDEs to enhance the Rust development experience.
Pros
- Fast and efficient code completion for Rust
- Supports multiple text editors and IDEs
- Provides accurate go-to-definition and find-references features
- Actively maintained and regularly updated
Cons
- May occasionally struggle with complex or highly generic code
- Requires manual configuration in some editors
- Can be resource-intensive for large projects
- Limited support for macro-generated code
Code Examples
- Basic auto-completion:
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
map.in // Racer will suggest: insert, into_iter, is_empty, etc.
}
- Go-to-definition:
struct Person {
name: String,
age: u32,
}
fn main() {
let person = Person { // Ctrl+Click on Person to go to its definition
name: String::from("Alice"),
age: 30,
};
}
- Find references:
fn greet(name: &str) {
println!("Hello, {}!", name);
}
fn main() {
greet("World"); // Right-click on greet and select "Find All References"
greet("Rust");
}
Getting Started
To use Racer in your Rust project:
-
Install Racer:
cargo install racer
-
Set up your editor to use Racer. For example, in VS Code:
- Install the "Rust" extension
- Add the following to your
settings.json
:{ "rust-client.engine": "rust-analyzer", "rust-client.racer-completion": true }
-
Ensure you have Rust source code available:
rustup component add rust-src
-
Start coding and enjoy enhanced Rust development with Racer's code intelligence features!
Competitor Comparisons
A Rust compiler front-end for IDEs
Pros of rust-analyzer
- More comprehensive and accurate code analysis
- Faster performance, especially for large projects
- Better integration with Language Server Protocol (LSP)
Cons of rust-analyzer
- Higher resource consumption
- Steeper learning curve for contributors
- More complex setup process
Code Comparison
racer:
fn complete_path(path: &str, pos: usize) -> Vec<Match> {
// Simple path completion logic
}
rust-analyzer:
fn complete_path(
db: &RootDatabase,
position: FilePosition,
completion_context: &CompletionContext,
) -> Option<Vec<CompletionItem>> {
// More sophisticated path completion with context
}
rust-analyzer offers more advanced code analysis and completion capabilities, leveraging a deeper understanding of Rust's type system and semantics. It provides better performance for large codebases and integrates well with modern IDEs through LSP. However, it requires more system resources and can be more challenging to set up and contribute to.
racer, on the other hand, is simpler and lighter, making it easier to install and use in resource-constrained environments. It may be sufficient for smaller projects or quick code navigation tasks. However, it lacks some of the advanced features and accuracy provided by rust-analyzer, especially for complex Rust code.
Repository for the Rust Language Server (aka RLS)
Pros of RLS
- More comprehensive language support, including features like code completion, diagnostics, and refactoring
- Integrated with the Language Server Protocol (LSP), making it compatible with various editors and IDEs
- Officially supported by the Rust project, ensuring long-term maintenance and updates
Cons of RLS
- Can be slower and more resource-intensive, especially for larger projects
- May require additional setup and configuration compared to Racer
- Still in development, with some features not fully implemented or stable
Code Comparison
Racer:
use racer::Session;
let mut session = Session::new();
let matches = session.complete_fully("std::io::B", 11, "dummy.rs", None);
RLS:
use rls_analysis::{AnalysisHost, AnalysisLoader};
let host = AnalysisHost::new(AnalysisLoader::new());
let analysis = host.analysis();
let completions = analysis.completions("file.rs", 10, 5, None, None);
Both tools provide code completion functionality, but RLS offers a more comprehensive analysis through its integration with the Rust compiler. Racer focuses primarily on fast code completion, while RLS provides a broader range of language features and integrations.
Language Server Protocol (LSP) support for vim and neovim.
Pros of LanguageClient-neovim
- Supports multiple programming languages through Language Server Protocol (LSP)
- Provides more advanced features like code actions, symbol renaming, and workspace-wide operations
- Integrates seamlessly with Neovim and other plugins
Cons of LanguageClient-neovim
- Requires more setup and configuration compared to Racer
- May have higher resource usage due to its broader feature set
- Potential for slower performance in large projects
Code Comparison
LanguageClient-neovim configuration:
let g:LanguageClient_serverCommands = {
\ 'rust': ['rustup', 'run', 'stable', 'rls'],
\ }
Racer configuration:
let g:racer_cmd = "/path/to/racer"
let g:racer_experimental_completer = 1
Summary
LanguageClient-neovim offers a more comprehensive language support solution with advanced features, while Racer is more focused on Rust-specific functionality. LanguageClient-neovim requires more setup but provides broader language support, whereas Racer is simpler to configure but limited to Rust. The choice between the two depends on the user's needs for language support and desired feature set.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Pros of coc.nvim
- Supports multiple languages and frameworks, not limited to Rust
- Offers a more comprehensive set of features, including code completion, diagnostics, and refactoring
- Integrates with Language Server Protocol (LSP) for enhanced functionality
Cons of coc.nvim
- Requires Node.js as a dependency, which may not be ideal for all users
- Can be more resource-intensive due to its broader feature set
- May have a steeper learning curve for configuration and customization
Code Comparison
racer:
use racer::Session;
let mut session = Session::new();
let matches = session.complete_fully("std::io::B", 11, "foo.rs", None);
coc.nvim:
call coc#config('languageserver', {
\ 'rust': {
\ 'command': 'rust-analyzer',
\ 'filetypes': ['rust'],
\ 'rootPatterns': ['Cargo.toml']
\ }
\})
Summary
While racer focuses specifically on Rust code completion, coc.nvim offers a more versatile solution for multiple languages. coc.nvim provides a wider range of features and LSP integration but comes with additional dependencies and potential complexity. racer may be simpler to set up for Rust-specific projects, while coc.nvim is better suited for developers working with multiple languages or seeking more advanced IDE-like features in their editor.
async language server protocol plugin for vim and neovim
Pros of vim-lsp
- Language-agnostic: Supports multiple programming languages through Language Server Protocol (LSP)
- Extensible: Can integrate with various LSP servers for different languages
- Active development: Regularly updated with new features and improvements
Cons of vim-lsp
- Requires additional setup: Need to install and configure LSP servers for each language
- Higher resource usage: May consume more system resources due to running separate language servers
Code comparison
vim-lsp configuration:
let g:lsp_settings = {
\ 'rust-analyzer': {
\ 'cmd': ['rust-analyzer'],
\ 'initialization_options': {
\ 'cargo': {
\ 'loadOutDirsFromCheck': v:true,
\ },
\ 'procMacro': {
\ 'enable': v:true,
\ },
\ },
\ },
\ }
racer configuration:
let g:racer_cmd = "/path/to/racer"
let g:racer_experimental_completer = 1
Summary
vim-lsp offers broader language support and extensibility through the Language Server Protocol, making it suitable for developers working with multiple languages. However, it requires more setup and may use more system resources. racer, being Rust-specific, provides a simpler setup for Rust development but lacks the versatility of vim-lsp for other languages.
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
Racer - code completion for Rust
RACER = Rust Auto-Complete-er. A utility intended to provide Rust code completion for editors and IDEs. Maybe one day the 'er' bit will be exploring + refactoring or something.
DISCLAIMER
Racer is not actively developped now. Please consider using newer software such as rust-analyzer.
Installation
NOTE From 2.1, racer needs nightly rust
Requirements
Current nightly Rust
If you're using rustup, run
rustup toolchain install nightly
rustup component add rustc-dev --toolchain=nightly
Note: The second command adds the rustc-dev
component to the nightly
toolchain, which is necessary to compile Racer.
Cargo
Internally, racer calls cargo as a CLI tool, so please make sure cargo is installed
With cargo install
Simply run:
cargo +nightly install racer
As mentioned in the command output, don't forget to add the installation directory to your PATH
.
From sources
-
Clone the repository:
git clone https://github.com/racer-rust/racer.git
-
cd racer; cargo +nightly build --release
. The binary will now be in./target/release/racer
-
Add the binary to your
PATH
. This can be done by moving it to a directory already in yourPATH
(i.e./usr/local/bin
) or by adding the./target/release/
directory to yourPATH
Configuration
-
Fetch the Rust sourcecode
-
automatically via rustup and run
rustup component add rust-src
in order to install the source to$(rustc --print sysroot)/lib/rustlib/src/rust/library
(or$(rustc --print sysroot)/lib/rustlib/src/rust/src
in older toolchains). Rustup will keep the sources in sync with the toolchain if you runrustup update
. -
manually from git: https://github.com/rust-lang/rust
Note
If you want to use
racer
with multiple release channels (Rust has 3 release channels:stable
,beta
andnightly
), you have to also download Rust source code for each release channel you install.e.g. (rustup case) Add a nightly toolchain build and install nightly sources too
rustup toolchain add nightly
rustup component add rust-src
-
-
(Optional) Set
RUST_SRC_PATH
environment variable to point to the 'src' dir in the Rust source installation e.g.% export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/library
or% export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
(older)It's recommended to set
RUST_SRC_PATH
for speed up, but racer detects it automatically if you don't set it. -
Test on the command line:
racer complete std::io::B
(should show some completions)
Note
To complete names in external crates, Racer needs Cargo.lock
.
So, when you add a dependency in your Cargo.toml
, you have to run a build command
such as cargo build
or cargo test
, to get completions.
Editors/IDEs Supported
RLS
Racer is used as a static library in RLS
Eclipse integration
Racer can be used with Eclipse through the use of RustDT. (User guide is linked in repo description)
Emacs integration
Emacs integration has been moved to a separate project: emacs-racer.
Gedit integration
Gedit integration can be found here.
Builder integration
Gnome Builder integration can be found here
Kate integration
The Kate community maintains a plugin. It is bundled with recent releases of Kate (tested with 16.08 - read more here).
-
Enable 'Rust code completion' in the plugin list in the Kate config dialog;
-
On the new 'Rust code completion' dialog page, make sure 'Racer command' and 'Rust source tree location' are set correctly.
Sublime Text integration
The Sublime Text community maintains some packages that integrates Racer
- RustAutoComplete that offers auto completion and goto definition.
- AnacondaRUST from the anaconda plugins family that offers auto completion, goto definition and show documentation
Vim integration
Vim integration has been moved to a separate project: vim-racer.
Visual Studio Code extension
Racer recommends the official Rust (rls)
extension based on RLS, which uses Racer for completion.
Atom integration
You can find the racer package for Atom here
Kakoune integration
Kakoune comes with a builtin integration for racer auto completion.
Top Related Projects
A Rust compiler front-end for IDEs
Repository for the Rust Language Server (aka RLS)
Language Server Protocol (LSP) support for vim and neovim.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
async language server protocol plugin for vim and neovim
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