Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Add assert!() and assert_eq!() snippets. #321

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ the following snippets:
* `unimplemented`
* `unreachable`
* `println`
* `assert` and `assert_eq`
* `macro_rules` - declare a macro
* `if let Option` - an `if let` statement for executing code only in the `Some`
case.
Expand Down
14 changes: 14 additions & 0 deletions snippets/rust.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
],
"description": "Insert println!"
},
"assert": {
"prefix": "assert",
"body": [
"assert!($1)$0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax here and for assert_eq looks wrong, should it be assert!($1, $0)? Also I don't see why it is in this order and not $0, $1.

Copy link
Contributor Author

@OnlyLys OnlyLys May 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nrc, the $0 tabstop in a snippet actually denotes the final cursor position. Its purpose is to allow users to 'jump out' of the braces on the final 'tab' keypress. It's very convenient because it allows users to add a semicolon at the end without needing to manually move the cursor there.

But it's not only added there for convenience reasons, it's also to have parity with function snippet completions. If you're familiar with them, they all have a final tabstop immediately to the right of the closing brace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!

],
"description": "Insert assert!"
},
"assert_eq": {
"prefix": "assert_eq",
"body": [
"assert_eq!($1, $2)$0"
],
"description": "Insert assert_eq!"
},
"macro_rules": {
"prefix": "macro_rules",
"body": [
Expand Down