Racer - code completion for Rust

Racer - code completion for rust-analyzer

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

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:

As mentioned in the command output, don't forget to add the installation directory to your PATH.

From sources

  1. Clone the repository:

  2. . The binary will now be in

  3. Add the binary to your PATH. This can be done by moving it to a directory already in your PATH (i.e. /usr/local/bin) or by adding the ./target/release/ directory to your PATH

Configuration

  1. Fetch the Rust sourcecode

    1. 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 run rustup update.

    2. 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 and nightly), 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

  2. (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.

  3. 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).

  1. Enable 'Rust code completion' in the plugin list in the Kate config dialog;

  2. 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.

Issues

Collection of the latest Issues

Thomas28M

Thomas28M

1

I have tried to install racer but I keep getting this error. I couldn't find it anywhere else.

Info

$ rustup show Default host: x86_64-unknown-linux-gnu rustup home: /home/thomas28/.rustup

installed toolchains

stable-x86_64-unknown-linux-gnu (default) nightly-x86_64-unknown-linux-gnu

active toolchain

stable-x86_64-unknown-linux-gnu (default) rustc 1.60.0 (7737e0b5c 2022-04-04)

$rustup update info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu' info: checking for self-updates

stable-x86_64-unknown-linux-gnu unchanged - rustc 1.60.0 (7737e0b5c 2022-04-04) nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.62.0-nightly (f4ec0e7cf 2022-04-22)

info: cleaning up downloads & tmp directories

Fail

$cargo +nightly install racer Updating crates.io index Installing racer v2.2.2 Compiling proc-macro2 v1.0.37 Compiling unicode-xid v0.2.2 Compiling syn v1.0.91 Compiling serde_derive v1.0.136 Compiling serde v1.0.136 Compiling memchr v2.4.1 Compiling libc v0.2.124 Compiling serde_json v1.0.79 Compiling log v0.4.16 Compiling cfg-if v1.0.0 Compiling itoa v1.0.1 Compiling unicode-width v0.1.9 Compiling ryu v1.0.9 Compiling quick-error v1.2.3 Compiling regex-syntax v0.6.25 Compiling termcolor v1.1.3 Compiling vec_map v0.8.2 Compiling convert_case v0.4.0 Compiling strsim v0.8.0 Compiling ansi_term v0.12.1 Compiling bitflags v1.3.2 Compiling lazy_static v1.4.0 Compiling humantime v2.1.0 Compiling lazycell v1.3.0 Compiling textwrap v0.11.0 Compiling humantime v1.3.0 Compiling quote v1.0.18 Compiling aho-corasick v0.7.18 Compiling atty v0.2.14 Compiling regex v1.5.5 Compiling clap v2.34.0 Compiling env_logger v0.7.1 Compiling derive_more v0.99.17 Compiling racer-interner v0.1.0 Compiling rls-span v0.5.4 Compiling racer-cargo-metadata v0.1.2 Compiling racer v2.2.2 error[E0053]: method fallback_fluent_bundle has an incompatible type for trait --> /home/thomas28/.cargo/registry/src/github.com-1ecc6299db9ec823/racer-2.2.2/src/racer/ast.rs:36:41 | 36 | fn fallback_fluent_bundle(&self) -> &Lrc<rustc_errors::FluentBundle> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | expected struct fluent_bundle::bundle::FluentBundle, found struct Lrc | help: change the output type to match the trait: &fluent_bundle::bundle::FluentBundle<fluent_bundle::resource::FluentResource, intl_memoizer::IntlLangMemoizer> | = note: expected fn pointer fn(&DummyEmitter) -> &fluent_bundle::bundle::FluentBundle<fluent_bundle::resource::FluentResource, intl_memoizer::IntlLangMemoizer> found fn pointer fn(&DummyEmitter) -> &Lrc<fluent_bundle::bundle::FluentBundle<fluent_bundle::resource::FluentResource, intl_memoizer::IntlLangMemoizer>>

error[E0023]: this pattern has 5 fields, but the corresponding tuple variant has 6 fields --> /home/thomas28/.cargo/registry/src/github.com-1ecc6299db9ec823/racer-2.2.2/src/racer/ast.rs:232:31 | 232 | visit::FnKind::Fn(_, _, ref fn_sig, _, ) => &*fn_sig.decl, | ^ ^ ^^^^^^^^^^ ^ ^ expected 6 fields, found 5 | help: use _ to explicitly ignore each field | 232 | visit::FnKind::Fn(, _, ref fn_sig, _, _, _) => &*fn_sig.decl, | +++

error[E0023]: this pattern has 5 fields, but the corresponding tuple variant has 6 fields --> /home/thomas28/.cargo/registry/src/github.com-1ecc6299db9ec823/racer-2.2.2/src/racer/ast.rs:1261:31 | 1261 | visit::FnKind::Fn(_, _, ref fn_sig, _, ) => &*fn_sig.decl, | ^ ^ ^^^^^^^^^^ ^ ^ expected 6 fields, found 5 | help: use _ to explicitly ignore each field | 1261 | visit::FnKind::Fn(, _, ref fn_sig, _, _, _) => &*fn_sig.decl, | +++

Some errors have detailed explanations: E0023, E0053. For more information about an error, try rustc --explain E0023. error: could not compile racer due to 3 previous errors warning: build failed, waiting for other jobs to finish... error: failed to compile racer v2.2.2, intermediate artifacts can be found at /tmp/cargo-installODCwvH

emadbaqeri

emadbaqeri

7

Hey folks, I'm have install rust and rustup dev components alongside racer. I'm trying to use doom-emacs but I got this error and no code completion. Screen Shot 2022-04-02 at 02 59 03

I don't know what should have done since I have installed the cargo, cargo +nightly, rustup and all the dev dependencies of the rust on my device. I should also mention that I've got M1 CPU on my machine, is the problem the CPU?

mqudsi

mqudsi

0

rls is unable to complete linter allow hints without a closing parenthesis and brace, but is able to complete them otherwise.

i.e. this works:

but this doesn`t

(In case it's not rendered correctly, the completion is triggered at the same location immediately after the opening ( in both samples.)

PlumpHip

PlumpHip

1

% racer complete std::io::B Unable to find libstd under RUST_SRC_PATH. N.B. RUST_SRC_PATH variable needs to point to the src directory inside a rust checkout e.g. "/home/foouser/src/rust/src". Current value ""/nix/store/fjghknnd4x9zpgx6hxznaiw6c7y0jr2s-rust-1.47.0-2020-10-07-18bf6b4f0/lib/rustlib/src/rust/library/libstd""

I use nix Mozilla-rust-overlay stable

nixpkgs.latest.rustChannels.stable.rust.override { extensions = [ # # "lldb-preview" "clippy-preview" # "miri-preview" "rls-preview" # "rust-analyzer-preview" "rustfmt-preview" "llvm-tools-preview" "rust-analysis" "rust-std" "rustc-dev" # "rustc-docs" "rust-src" ]

Thanks

kfrncs

kfrncs

1

When I run racer complete std::io::B, I get this:

Unable to find libstd under RUST_SRC_PATH. N.B. RUST_SRC_PATH variable needs to point to the *s│ rc* directory inside a rust checkout e.g. "/home/foouser/src/rust/src". Current value ""/home/ken/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd""

Despite the fact that my ~/.zshrc contains:

export RUST_SRC_PATH=${HOME}/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src

Any help would be appreciated.

Leorii

Leorii

4

Panic occurs when typing a std module name.

Example

'thread 'searcher' panicked at 'Failed load file "$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/std/src/primitive_docs.rs": Os { code: 2, kind: NotFound, message: "No such file or directory" }', $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/racer-2.1.38/src/racer/core.rs:816:14\nnote: run with RUST_BACKTRACE=1 environment variable to display a backtrace\n'

Thoughts

I believe this might have something to do with #1130. The completion does still work (it attempts to find the source from the original rust directory layout), but then I think it still tries to find the source from the new layout and fails at that.

mabushey

mabushey

1

I have Rust installed the correct way via the OS:

The docs infer I need to run rustc. I would be happy to that in a docker container, but I'm not trashing my OS... Is there any way to install this the Debian [correct] way on Ubuntu? I'm happy to copy the plugin into ~/.vim_runtime/my_plugins If I can figure out how to compile it.

adaschevici

adaschevici

7

Hi,

I've updated OSX to the last supplemental update and completion seems to have stopped working. the rust-src component path seems to no longer be detected accurately. Setting it manually seems to not work very well as it can't find libstd

it seems this path no longer exists: export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

Versions: rustc 1.47.0-nightly (8e21bd063 2020-08-14) rustup 1.22.1 (b01adbbc3 2020-07-08) racer 2.1.37

Not sure what i am missing

fitzgen

fitzgen

1

Sometimes building racer breaks because of nightly stuff (e.g. nightly-2020-07-16 doesn't build racer 2.1.35). It would be cool if the latest tagged releases had prebuilt binary executables for linux/macos/windows attached.

For example, cargo-wasi automatically builds and publishes binaries in github actions, which might be helpful to borrow from:

andremarcais

andremarcais

1

I am not getting auto completions for anything in std::os::unix. racer complete std::os:: | grep unix has no output. Everything else in std::os seems to have correct auto completion.

I have not found anything on the web regarding this.

I am using racer 2.1.31 from the arch linux packages.

Arthaclarius

Arthaclarius

0

Taking the std::fs::File example I write

If I go to let mut f = File::open("story.txt").u

If you check the code I can use unwrap_or_else but is not in the complete suggestions.

If I go to match f.w

But I was expecting write, write_vectored, write_all, and even more.

Maybe I'm wrong but It should be working.

trayanr

trayanr

0

Racer doesn't show lool up definitions in $CARGO_HOME

Cargo toml:

I ran cargo run to generate the .lock file. Now if I run RUST_BACKTRACE=1 RUST_LOG=racer=trace racer complete std

But running RUST_BACKTRACE=1 RUST_LOG=racer=trace racer complete gtk results in:

It would seem that racer doesn't look in the cargo directory, so it doesn't find the definitions. Can I manually add it from the command line?

ensc

ensc

0

racer fails to lookup symbols which are made available by std::include!().

E.g.

main.rs

common.inc-rs

bar.rs

does not return a result

Position "4 17" is the foo in the function call.

racer 2.1.28; built with 1.41.0-nightly (5c5b8afd8 2019-11-16)

martinellison

martinellison

0

I am running cargo +nightly install --path . --all-features against the current source (99a830229c974d5f7ca227e3a66a60d5dba6423a), and getting many compile errors.

edit: cargo +nightly install racer works for me.

I am getting

Compiling rustc-ap-syntax v610.0.0 error[E0407]: method mixed_site is not a member of trait server::Span --> /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-syntax-610.0.0/ext/proc_macro_server.rs:669:5 | 669 | / fn mixed_site(&mut self) -> Self::Span { 670 | | self.mixed_site 671 | | } | |_____^ not a member of trait server::Span

and lots of errors like

error[E0658]: use of unstable library feature 'mem_take' --> /home/martin/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-syntax-610.0.0/parse/parser.rs:1535:22 | 1535 | Some(mem::take(list)) | ^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/61129 = help: add #![feature(mem_take)] to the crate attributes to enable

For your information:

rustc -V rustc 1.37.0 (eae3437df 2019-08-13)

uname -a Linux starnova 4.4.154-59-rockchip-g5e70f14 #4 SMP Fri Dec 14 20:55:41 CST 2018 aarch64 aarch64 aarch64 GNU/Linux

SephVelut

SephVelut

1

racer complete 32 8 src/main.rs results in ERROR 2019-07-19T03:36:40.729973000Z: racer: Search thread panicked: Any. I tried to minify the example but any code that I remove now avoids the panic for some reason.

SephVelut

SephVelut

bug
0

I realize it's not correct syntax, but the splatter of panic errors on IDE integrations are intrusive.

racer complete 3 6 main.rs

SpencerMacKinnon

SpencerMacKinnon

bug
1

I have racer mainly working now but I can't get it to complete fields within a struct or methods for that struct. When I try and complete structs from a crate ("cgmath::" then autocomplete) that seems to work. When I try and autocomplete a field or method ("v2.") that doesn't seem to return anything. Are fields and methods supported? Thanks for helping look into this!

main.rs

cargo.toml

Versions

Find the latest versions by id

v2.1.36 - Jul 18, 2020

v2.1.32 - Mar 31, 2020

v2.1.28 - Oct 11, 2019

v2.1.27 - Sep 09, 2019

v2.1.26 - Sep 07, 2019

v1.1.0 - Dec 28, 2015

  • Adds basic 'daemon' mode, racer process can be kept running between invocations
  • now uses clap to parse command line options
  • Adds caching of file source and code indices
  • Adds an alternative 'tabbed' mode where inputs and outputs can be tab separated for easier parsing
  • emacs and vim support split out into their own git projects at https://github.com/racer-rust/emacs-racer https://github.com/racer-rust/vim-racer
  • Fix issue resolving some std::* modules in latest rust source: (rust std lib implicitly imports core with #![no_std])
  • Searches multirust overrides when locating cargo src directories

v1.0.0 - Jul 29, 2015

First release!

Information - Updated May 14, 2022

Stars: 3.3K
Forks: 289
Issues: 146

Repositories & Extras

Tensorflow rust bindings with loads of easy to use documentation

bindings for documentation can be found in github or on our docs page

Tensorflow rust bindings with loads of easy to use documentation

Wasm template for Rust hosting without npm-deploy on github pages using Travis script

It automatically hosts your wasm projects on gh-pages using a travis script on the latest commit

Wasm template for Rust hosting without npm-deploy on github pages using Travis script

If you like Rusty Engine, please sponsor me on GitHub or on Patreon, or take...

If you like Rusty Engine, please sponsor me on Patreon, or Bevy, which I encourage you to use directly for more serious game engine needs

If you like Rusty Engine, please sponsor me on GitHub or on Patreon, or take...

Try Out Development Containers: Rust

A development container is a running GitHub Codespaces or vscode-remote-try-* sample projects, too

Try Out Development Containers: Rust

Roctogen: a rust client library for the GitHub v3 API

This client API is generated from the Isahc HTTP client

Roctogen: a rust client library for the GitHub v3 API

Try Out Development Containers: Rust

A development container is a running GitHub Codespaces or vscode-remote-try-* sample projects, too

Try Out Development Containers: Rust

Rust crate for logging to LogDNA

Bug reports and pull requests are welcome on GitHub at

Rust crate for logging to LogDNA

A rust github template for ease of use

Install the rust toolchain in order to have cargo installed by following

A rust github template for ease of use

Rust-generated WebAssembly GitHub action template

A template to bootstrap the creation of a Rust-generated WebAssembly GitHub action

Rust-generated WebAssembly GitHub action template

Template for Rust lib/bin module with built-in GitHub Action to build and test

You will want to change the lib name and bin name in Cargo

Template for Rust lib/bin module with built-in GitHub Action to build and test

cargo_auto_github_lib

Library for cargo-auto automation tasks written in rust language with functions for github

cargo_auto_github_lib

A Rust library to connect to AxonServer

See the GitHub project Command / Query Responsibility Segregation (CQRS)

A Rust library to connect to AxonServer
Facebook Instagram Twitter GitHub Dribbble
Privacy