#single-file #cargo-toml #cli #json-file #youcompleteme #none-cargo

app rvi

A small tool to let you write rust with rust-analyzer not using cargo

6 releases

0.1.5 Sep 26, 2024
0.1.4 May 17, 2022
0.1.3 Apr 26, 2022

#335 in Command line utilities

MIT license

13KB
213 lines

Crates.io rvi

A small tool to let you write rust with vim and rust-analyzer not using cargo to create a project, we just want to play with a single rust file!

  • Suppose you use vim and rust analyzer.
  • When you use vim and rust-analyzer to edit single rust file, you will find rust-analyzer do not work well, code completion and code check are broken.
  • Then, you must add rust-project.json in your file's directory, as the manual shows. At this time, code completion will work, but code check is still broken. it just complains could not find Cargo.toml in / or any parent directory, so you must add a Cargo.toml in your file's directory, like this:
[package]
name = "test"
version = "0.1.0"
edition = "2021"

[lib]
path= "test.rs"

[dependencies]
..
  • Then you will find, every time you edit a diffrent rust file, you must replace the field root_module in rust-project.json and the field path in Cargo.toml to your editing rust file's name, it's so boring and waste of time.

  • This tool will help you, you just need rvi your_file_name.rs!

Install

Download from release page

OR

cargo install rvi

Configure

1.Copy rvi.toml into $HOME/.config/, you can edit it according to your actual environment.

2.If you use Youcompleteme, you must fill the ycm_extra_conf field in above file, the config_file is like .ycm_extra_conf.py.example, you should place it in your directory and rename it to .ycm_extra_conf.py. The tool will copy it to your project_dir automatically.

3.If you do not use Youcompleteme, you should transfer the rust-analyzer.checkOnSave.overrideCommand configuration item to rust-analyzer lsp as your client explain. The following is official description:

Note that calls to cargo check are disabled when using rust-project.json by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the checkOnSave.overrideCommand configuration. As an example, the following configuration explicitly sets cargo check as the checkOnSave command.

{
  "rust-analyzer.checkOnSave.overrideCommand": [
    "cargo",
    "check",
    "--message-format=json"
  ]
}

The checkOnSave.overrideCommand requires the command specified to output json error messages for rust-analyzer to consume. The --message-format=json flag does this for cargo check so whichever command you use must also output errors in this format. See the Configuration section for more information.

Usage

rvi your_file.rs

Dependencies

~0.7–11MB
~72K SLoC