Skip to content

Commit 92f8880

Browse files
ehussJayflux
authored andcommitted
New Cargo build system. (#165)
* New Cargo build system. * Fix wrapping of commands in GitHub flavored markdown. * Minor fixes to unittests for Rust 1.16. * Add support for "cargo check". * Support clippy for on-save checking. * Fix on-save syntax check running clippy multiple times. * Add ability to configure cargo build features. * Support setting environment variables. This includes a dependency on shellenv to capture the user's environment from their login shell. * Normalize paths when dealing with settings. This fixes some problems running tests on Windows. * Disable on-load message display for tests. This was causing random breakage (particularly on Windows). * Fix race condition in tests manifested on linux. * Add support for custom build variants. This includes some significant changes to how the current package is selected. It should work a little better if you have multiple packages. * Add support for a default path/package. * Add "Automatic" build variant. * Stop looking for JSON output during Cargo build once compile is finished. This fixes issues with "cargo run" if your program outputs { at the start of a line. * Better fix for checking when we should stop looking for JSON output. The previous fix caused issues with Clippy. * Remove debug print left behind. * Minor updates for rust 1.17. * Change message tests to check the region of the message. * Fix error highlighting for nested macros. * Fix clearing of error regions. * Add rust_phantom_style and rust_region_style config settings. Fixes #182. * Honor show_errors_inline config setting for Cargo build. * Fix links in messages that are surrounded by angled brackets. * Consolidate all Cargo config commands into a single command. Add commands to configure extra arguments and environment variables. * Document the new build configure command. Also document the `default_path` option. * On-save syntax checking now uses configuration settings from the build system. * Finish documenting all settings, and include link to new build docs. * Fix Cargo environment variable config command when selecting "all build commands". * Only print warning about sublime-project when saving setings. * Fix target detection for cdylib. Adapted from #186, thanks @smbolton. * Update tests for new messages in rust 1.18.
1 parent 41e189a commit 92f8880

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+10211
-742
lines changed

Cargo.build-language

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<key>name</key>
3939
<string>variable.parameter</string>
4040
</dict>
41+
<dict>
42+
<key>match</key>
43+
<string>^warning:</string>
44+
<key>name</key>
45+
<string>variable.parameter</string>
46+
</dict>
4147
<dict>
4248
<key>match</key>
4349
<string>^test result:</string>
@@ -108,4 +114,4 @@
108114
<key>scopeName</key>
109115
<string>source.build_results</string>
110116
</dict>
111-
</plist>
117+
</plist>

Cargo.sublime-build

-53
This file was deleted.

Default (Linux).sublime-keymap

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{"keys": ["f4"], "command": "rust_next_message", "context":
3+
[
4+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
5+
]
6+
},
7+
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
8+
[
9+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
10+
]
11+
},
12+
{"keys": ["ctrl+break"], "command": "rust_cancel", "context":
13+
[
14+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
15+
]
16+
},
17+
]

Default (OSX).sublime-keymap

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{"keys": ["f4"], "command": "rust_next_message", "context":
3+
[
4+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
5+
]
6+
},
7+
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
8+
[
9+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
10+
]
11+
},
12+
{"keys": ["ctrl+c"], "command": "rust_cancel", "context":
13+
[
14+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
15+
]
16+
},
17+
]

Default (Windows).sublime-keymap

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{"keys": ["f4"], "command": "rust_next_message", "context":
3+
[
4+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
5+
]
6+
},
7+
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
8+
[
9+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
10+
]
11+
},
12+
{"keys": ["ctrl+break"], "command": "rust_cancel", "context":
13+
[
14+
{"key": "selector", "operator":"equal", "operand": "source.rust"}
15+
]
16+
},
17+
]

README.md

+23-22
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,12 @@ If you can't see `Rust Enhanced` its most likely because you're using Sublime Te
2727

2828
## Features
2929
### Go To Definition
30-
### Build functionality
31-
Rust Enhanced has the following build functions:
32-
- Cargo Check
33-
- Cargo Run
34-
- Cargo Script [Cargo Script is needed](https://github.com/DanielKeep/cargo-script)
35-
- Cargo Test
36-
- Cargo Bench
37-
- Cargo Clean
38-
- Cargo Release
39-
- Cargo Document
40-
- Cargo Clippy
41-
- Rust
42-
- Rust Run
30+
### Cargo Build
31+
Rust Enhanced has a custom build system tailored for running Cargo. It will display errors and warnings in line using Sublime's phantoms. It also supports a variety of configuration options to control how Cargo is run.
4332

33+
![testingrust](https://cloud.githubusercontent.com/assets/43198/22944409/7780ab9a-f2a5-11e6-87ea-0e253d6c40f6.png)
34+
35+
See [the build docs](docs/build.md) for more information.
4436

4537
### Cargo tests with highlighting
4638
Thanks to [urschrei](https://github.com/urschrei/) we have Highlighting for:
@@ -53,24 +45,31 @@ Thanks to [urschrei](https://github.com/urschrei/) we have Highlighting for:
5345
- total number of measured tests > 0
5446

5547
Example:
48+
5649
![highlight_rust_test](https://cloud.githubusercontent.com/assets/936006/19247437/3cf6e056-8f23-11e6-9bbe-d8c542287db6.png)
5750

5851
### Syntax Checking
5952
Rust Enhanced will automatically perform syntax checking each time you save a file.
53+
Errors and warnings are displayed in line the same way as the [build system](docs/build.md).
6054
This relies on Cargo and Rust (>= 1.8.0) being installed and on your system path. Plus Sublime Text >= 3118.
6155

62-
There are a variety of settings (see [Settings](#settings)) for controlling the syntax highlighting:
56+
[Settings](#settings) for controlling the on-save syntax checking:
6357

6458
| Setting | Default | Description |
6559
| :------ | :------ | :---------- |
6660
| `rust_syntax_checking` | `true` | Enable the on-save syntax checking. |
67-
| `rust_syntax_checking_include_tests` | `true` | Enable checking of test code within `#[cfg(test)]` sections. |
68-
| `rust_syntax_hide_warnings` | `false` | If true, will not display warning messages. |
69-
| `rust_syntax_error_color` | `"#F00"` | Color of error messages. |
70-
| `rust_syntax_warning_color` | `"#FF0"` | Color of warning messages. |
61+
| `rust_syntax_checking_include_tests` | `true` | Enable checking of test code within `#[cfg(test)]` sections (only for `no-trans` method). |
62+
| `rust_syntax_checking_method` | `"no-trans"` | The method used for checking your code (see below). |
7163

72-
Here is an example:
73-
![testingrust](https://cloud.githubusercontent.com/assets/43198/22944409/7780ab9a-f2a5-11e6-87ea-0e253d6c40f6.png)
64+
The available checking methods are:
65+
66+
| Method | Description |
67+
| :----- | :---------- |
68+
| `no-trans` | Runs the rustc compiler with the `-Zno-trans` option. This will be deprecated soon, however it has the benefit of supporting `#[test]` sections. |
69+
| `check` | Uses `cargo check` (requires at least Rust 1.16). |
70+
| `clippy` | Uses `cargo clippy`. This requires [Clippy](https://github.com/Manishearth/rust-clippy) to be installed. This also may be a little slower since it must check every target in your package. |
71+
72+
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](docs/build.md) for more information.
7473

7574
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:
7675

@@ -93,9 +92,11 @@ Projects with multiple build targets are supported too (--lib, --bin, --example,
9392
```
9493

9594
## Settings
96-
You can customize the behaviour of sublime-rust by creating a settings file in your User package. This can be accessed from within SublimeText by going to the menu Preferences > Browse Packages.... Create a file named Rust.sublime-settings or alternatively copy the default settings file Packages/sublime-rust/Rust.sublime-settings to your User package and edit it to your liking.
95+
To customize the settings, use the command from the Sublime menu:
96+
97+
Preferences > Package Settings > Rust Enhanced > Settings - User
9798

98-
Note: File names are case-sensitive on some platforms (e.g. Linux) so the file name should be exactly Rust.sublime-settings with capitalization preserved.
99+
Additionally, you can customize settings per-project by adding settings to your `.sublime-project` file under the `"settings"` key.
99100

100101
## Development
101102

RustEnhanced.sublime-build

+49-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,58 @@
11
{
2-
"shell_cmd": "rustc \"$file\"",
2+
"target": "cargo_exec",
33
"selector": "source.rust",
4-
"file_regex": "[ \\t]*-->[ \\t]*(.*?):([0-9]+):([0-9]+)$",
5-
"osx":
6-
{
7-
"path": "~/.cargo/bin:$path",
8-
},
4+
"command": "build",
95

106
"variants": [
117
{
12-
"selector": "source.rust",
13-
"shell_cmd": "./$file_base_name",
8+
"name": "Automatic",
9+
"command": "auto",
10+
},
11+
{
1412
"name": "Run",
15-
"windows":
16-
{
17-
"shell_cmd": "\"$file_base_name.exe\""
13+
"command": "run",
14+
},
15+
{
16+
"name": "Run (with args)...",
17+
"command": "run",
18+
"command_info": {
19+
"wants_run_args": true
20+
}
21+
},
22+
{
23+
"name": "Check",
24+
"command": "check",
25+
},
26+
{
27+
"name": "Test",
28+
"command": "test",
29+
},
30+
{
31+
"name": "Test (with args)...",
32+
"command": "test",
33+
"command_info": {
34+
"wants_run_args": true
1835
}
19-
}
36+
},
37+
{
38+
"name": "Bench",
39+
"command": "bench",
40+
},
41+
{
42+
"name": "Clean",
43+
"command": "clean",
44+
},
45+
{
46+
"name": "Document",
47+
"command": "doc",
48+
},
49+
{
50+
"name": "Clippy",
51+
"command": "clippy",
52+
},
53+
{
54+
"name": "Script",
55+
"command": "script",
56+
},
2057
]
2158
}

RustEnhanced.sublime-commands

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
[
2-
{
3-
"caption": "Rust: Toggle Syntax Checking",
2+
{
3+
"caption": "Rust: Toggle Syntax Checking",
44
"command": "toggle_rust_syntax_setting"
5-
}
5+
},
6+
{
7+
"caption": "Rust: Next Message",
8+
"command": "rust_next_message"
9+
},
10+
{
11+
"caption": "Rust: Prev Message",
12+
"command": "rust_prev_message"
13+
},
14+
{
15+
"caption": "Rust: Cancel Build",
16+
"command": "rust_cancel"
17+
},
18+
{
19+
"caption": "Rust: Create New Cargo Build Variant",
20+
"command": "cargo_create_new_build"
21+
},
22+
{
23+
"caption": "Rust: Configure Cargo Build",
24+
"command": "cargo_configure"
25+
},
626
]

RustEnhanced.sublime-settings

+18-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,24 @@
1313
"rust_syntax_error_color": "#F00",
1414

1515
// Color of warning messages.
16-
"rust_syntax_warning_color":"#FF0"
16+
"rust_syntax_warning_color":"#FF0",
17+
18+
// Specify environment variables to add when running Cargo.
19+
// "rust_env": {"PATH": "$PATH:$HOME/.cargo/bin"}
20+
21+
// If true, will use the environment from the user's login shell when
22+
// running Cargo.
23+
"rust_include_shell_env": true,
24+
25+
// For errors/warnings, how to show the inline message.
26+
// "normal" - Shows the message inline.
27+
// "none" - Do not show the message inline.
28+
"rust_phantom_style": "normal",
29+
30+
// For errors/warnings, how to highlight the region of the error.
31+
// "outline" - Outlines the region.
32+
// "none" - No outlining.
33+
"rust_region_style": "outline",
1734

1835
// If your cargo project has several build targets, it's possible to specify mapping of
1936
// source code filenames to the target names to enable syntax checking.

0 commit comments

Comments
 (0)