The official Sublime Text 3 package for the Rust Programming Language
Pull request Compare This branch is 281 commits ahead, 1 commit behind dbp:master.
bors[bot] and ehuss Merge #351
351: Fix async error that triggers often in Travis. r=ehuss a=ehuss



Co-authored-by: Eric Huss <eric@huss.org>
Latest commit de7e026 Sep 27, 2018
Permalink
Failed to load latest commit information.
.github adding issue template to make it easier for us to triage issues (#127) Nov 28, 2016
changelog Add compiler suggestions and message themes. (#267) Apr 22, 2018
docs Message updates. Sep 5, 2018
images/gutter Add compiler suggestions and message themes. (#267) Apr 22, 2018
rust Merge #344 Sep 20, 2018
snippets Snippets: change hard-coded 4 spaces to tabs Aug 31, 2018
tests Merge #344 Sep 20, 2018
.editorConfig adding ability to toggle rust syntax checking from command panel Fixes Nov 18, 2016
.gitignore Update message handling for Rust 1.24. (#235) Jan 27, 2018
.travis.yml Avoid running travis twice when used with bors. Sep 20, 2018
Cargo.sublime-syntax add 'Updating/Downloading/Documenting/Blocking' to cargo build syntax ( Jun 23, 2018
Context.sublime-menu Add debug logging feature. (#291) Jul 30, 2018
Default (Linux).sublime-keymap Add Escape keybinding to dismiss inline messages. (#211) Oct 28, 2017
Default (OSX).sublime-keymap Add Escape keybinding to dismiss inline messages. (#211) Oct 28, 2017
Default (Windows).sublime-keymap Add Escape keybinding to dismiss inline messages. (#211) Oct 28, 2017
Default.sublime-keymap Update r#""# auto-match to cooperate with raw identifiers. Sep 5, 2018
LICENSE.txt Reformat files and regenerate tmPreferences files from JSON Oct 7, 2015
Main.sublime-menu Use Sublime 3's new edit_settings command to edit Rust Enhanced setti… Sep 23, 2017
README.md Improve initial installation experience. (#292) Jun 23, 2018
RustComment.JSON-tmPreferences Reformat files and regenerate tmPreferences files from JSON Oct 7, 2015
RustComment.tmPreferences Add doc comments (`///` & `//!`). Aug 21, 2016
RustEnhanced.sublime-build Allow "Automatic" build selector to work with Cargo.toml. (#213) Oct 28, 2017
RustEnhanced.sublime-commands Message updates. Sep 5, 2018
RustEnhanced.sublime-settings Message updates. Sep 5, 2018
RustEnhanced.sublime-syntax Merge #345 #347 #348 #349 Sep 20, 2018
RustIndent.JSON-tmPreferences Reformat files and regenerate tmPreferences files from JSON Oct 7, 2015
RustIndent.tmPreferences Reformat files and regenerate tmPreferences files from JSON Oct 7, 2015
RustSymbols.JSON-tmPreferences Syntax: Index `const` and `static` symbols (for Goto-Symbol). Aug 21, 2018
RustSymbols.tmPreferences Syntax: Index `const` and `static` symbols (for Goto-Symbol). Aug 21, 2018
SyntaxCheckPlugin.py Merge #344 Sep 20, 2018
appveyor.yml CI updates Aug 5, 2018
bors.toml CI updates Aug 5, 2018
cargo_build.py Fix async error that triggers often in Travis. Sep 26, 2018
dependencies.json New Cargo build system. (#165) Jul 8, 2017
messages.json Add compiler suggestions and message themes. (#267) Apr 22, 2018
syntax_test_cargo.txt add 'Updating/Downloading/Documenting/Blocking' to cargo build syntax ( Jun 23, 2018
toggle_setting.py Add context menu (#222) Nov 26, 2017
unittesting.json Add Travis and AppVeyor. (#246) Feb 10, 2018

README.md

Rust Enhanced

About

This is a Sublime Text 3 package which supports Rust starting with version 1.0, it makes no attempt at supporting earlier incompatible versions.

This package used to be called 'Rust', but as of version 3, Sublime now comes with Rust built-in. The built-in version on Sublime is actually just a snapshot of this package with some fixes from quite some time ago. This package is still active and will continue to update and release, so if you want up to date features, and extra tools (such as syntax checking or building) we recommend using this package. It does not automatically override the built-in Rust package so you will have to disable it, and check "Rust Enhanced" is set. There is currently no plan to push upstream changes back into the Sublime Core Packages repo, and extra features will stay here.

For syntax highlighting for Cargo files. Its recommended installing this with the TOML package.

Running Tests with Rust Enhanced Highlighting errors and warnings with Rust Enhanced

Installation

Install the Package Control package if you haven't got it yet. Package Control is the best way to install packages for Sublime Text. See http://wbond.net/sublime_packages/package_control/installation for instructions.

Open the palette (control+shift+P or command+shift+P) in Sublime Text and select Package Control: Install Package and then select Rust Enhanced from the list. That's it. If you can't see Rust Enhanced its most likely because you're using Sublime Text 2.

Features

Go To Definition

Cargo Build

Rust Enhanced has a custom build system tailored for running Cargo. It will display errors and warnings in line using Sublime's phantoms (see Messages for settings to control how messages are displayed). It also supports a variety of configuration options to control how Cargo is run.

testingrust

See the build docs for more information.

Cargo tests with highlighting

Thanks to urschrei we have Highlighting for:

  • passed test
  • failed test
  • failed test source line (clickable)
  • total number of passed tests
  • total number of failed tests > 0
  • total number of ignored tests > 0
  • total number of measured tests > 0

Example:

highlight_rust_test

Syntax Checking

Rust Enhanced will automatically perform syntax checking each time you save a file. Errors and warnings are displayed in line the same way as the build system. This relies on Cargo and Rust (>= 1.8.0) being installed and on your system path. Plus Sublime Text >= 3118.

Settings for controlling the on-save syntax checking:

Setting Default Description
rust_syntax_checking true Enable the on-save syntax checking.
rust_syntax_checking_method "check" The method used for checking your code (see below).
rust_syntax_checking_include_tests true Enable checking of test code within #[cfg(test)] sections.
rust_syntax_hide_warnings false Don't show warnings when syntax checking

The available checking methods are:

Method Description
check Uses cargo check (requires at least Rust 1.16).
clippy Uses cargo clippy. This requires Clippy to be installed. This also may be a little slower since it must check every target in your package.

This will use the same configuration options as the "Check" and "Clippy" build variants (for example, extra environment variables, or checking with different features). See the build docs for more information.

Projects with multiple build targets are supported too (--lib, --bin, --example, etc.). If a cargo project has several build targets, it will attempt to automatically detect the correct target. In some rare cases, you may need to manually specify which target a file belongs to. This can be done by adding a "projects" setting in Rust.sublime-settings with the following format:

    "projects": {
       // One entry per project. Keys are project names.
       "my_cool_stuff": {
           // Path to the project root dir without trailing /src.
           "root": "/path/to/my/cool/stuff/project",

           // Targets will be used to replace {target} part in the command.
           // If no one target matches an, empty string will be used.
           "targets": {
               "bin/foo.rs": "--bin foo",  // format is "source_code_filename -> target_name"
               "bin/bar.rs": "--bin bar",
               "_default": "--lib"         // or "--bin main"
           }
       }
   }

RLS Support

RLS (Rust Language Server) support is experimental, because RLS is still in Alpha and the Sublime LSP plugin is work in progress. However, it's quite usable, and trying it is easy:

  • Set up RLS - follow the instructions, using the Nightly toolchain
  • Check that RLS is working correctly by running rustup run nightly rls --version. If you get a version back RLS is installed
  • Install LSP using Package Control
  • Enable LSP for Rust:
    • Open a Rust project, and open its lib.rs or main.rs file
    • Open the Command Palette, and select the LSP: Enable Language Server Globally | Project command
  • RLS should then initialise: you'll see a message in the status bar, and once the initial build has completed (this can be slow initially, as the RLS has to build your project), it is ready to use.

Note that as well as error checking, code-completion, and renaming, RLS can run rustfmt on your code: right-click, and select Format Document or Format Selection in a Rust source file.

You can keep RLS updated by running rustup update nightly, which will ensure that you get the latest features. LSP is also developing quickly, so it's worth checking package control for updates.

Context Menu

The Sublime context menu includes a Rust entry with a variety of commands. See context menu docs for more information.

Settings

To customize the settings, use the command from the Sublime menu:

Preferences > Package Settings > Rust Enhanced > Settings - User

Additionally, you can customize settings per-project by adding settings to your .sublime-project file under the "settings" key.

Development

Development is quite simple, just check out this project to your Sublime Text 3 packages folder, and switch to using this one. Syntax definitions are defined in the RustEnhanced.sublime-syntax file.

Credits

Created 2012 by Daniel Patterson, as a near complete from scratch rewrite of a package by Felix Martini.

This project is currently maintained by Jason Williams

License

This package is licensed under the MIT License.