From dbed0f0e9960904193fd56327201b91bf585e016 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Mar 2019 13:19:46 +0300 Subject: [PATCH] document some nice things --- docs/user/features.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/user/features.md b/docs/user/features.md index aa3bf5157e..90f182f357 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -321,3 +321,39 @@ use algo:<|>:visitor::{Visitor, visit}; //after: use algo::{<|>visitor::{Visitor, visit}}; ``` + +### Magic Completions + +In addition to usual reference completion, rust-analyzer provides some ✨magic✨ +completions as well: + +Keywords like `if`, `else` `while`, `loop` are completed with braces, and cursor +is placed at the appropriate position. Even though `if` is easy to type, you +still want to complete it, to get ` { }` for free! `return` is inserted with a +space or `;` depending on the return type of the function. + +When completing a function call, `()` are automatically inserted. If function +takes arguments, cursor is positioned inside the parenthesis. + +There are postifx completions, which can be triggerd by typing something like +`foo().if`. The word after `.` determines postifx completion, possible variants are: + +- `expr.if` -> `if expr {}` +- `expr.match` -> `match expr {}` +- `expr.while` -> `while expr {}` +- `expr.ref` -> `&expr` +- `expr.refm` -> `&mut expr` +- `expr.not` -> `!expr` +- `expr.dbg` -> `dbg!(expr)` + +There also snippet completions: + +#### Inside Expressions + +- `pd` -> `println!("{:?}")` +- `ppd` -> `println!("{:#?}")` + +#### Inside Modules + +- `tfn` -> `#[test] fn f(){}` +