You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//! Actual logic is implemented in [`crate::completions::postfix`] and [`crate::completions::snippet`].
4
+
5
+
// Feature: User Snippet Completions
6
+
//
7
+
// rust-analyzer allows the user to define custom (postfix)-snippets that may depend on items to be accessible for the current scope to be applicable.
8
+
//
9
+
// A custom snippet can be defined by adding it to the `rust-analyzer.completion.snippets` object respectively.
10
+
//
11
+
// [source,json]
12
+
// ----
13
+
// {
14
+
// "rust-analyzer.completion.snippets": {
15
+
// "thread spawn": {
16
+
// "prefix": ["spawn", "tspawn"],
17
+
// "body": [
18
+
// "thread::spawn(move || {",
19
+
// "\t$0",
20
+
// ")};",
21
+
// ],
22
+
// "description": "Insert a thread::spawn call",
23
+
// "requires": "std::thread",
24
+
// "scope": "expr",
25
+
// }
26
+
// }
27
+
// }
28
+
// ----
29
+
//
30
+
// In the example above:
31
+
//
32
+
// * `"thread spawn"` is the name of the snippet.
33
+
//
34
+
// * `prefix` defines one or more trigger words that will trigger the snippets completion.
35
+
// Using `postfix` will instead create a postfix snippet.
36
+
//
37
+
// * `body` is one or more lines of content joined via newlines for the final output.
38
+
//
39
+
// * `description` is an optional description of the snippet, if unset the snippet name will be used.
40
+
//
41
+
// * `requires` is an optional list of item paths that have to be resolvable in the current crate where the completion is rendered.
42
+
// On failure of resolution the snippet won't be applicable, otherwise the snippet will insert an import for the items on insertion if
43
+
// the items aren't yet in scope.
44
+
//
45
+
// * `scope` is an optional filter for when the snippet should be applicable. Possible values are:
46
+
// ** for Snippet-Scopes: `expr`, `item` (default: `item`)
47
+
// ** for Postfix-Snippet-Scopes: `expr`, `type` (default: `expr`)
48
+
//
49
+
// The `body` field also has access to placeholders as visible in the example as `$0`.
50
+
// These placeholders take the form of `$number` or `${number:placeholder_text}` which can be traversed as tabstop in ascending order starting from 1,
51
+
// with `$0` being a special case that always comes last.
52
+
//
53
+
// There is also a special placeholder, `${receiver}`, which will be replaced by the receiver expression for postfix snippets, or nothing in case of normal snippets.
54
+
// It does not act as a tabstop.
4
55
use ide_db::helpers::{import_assets::LocatedImport, insert_use::ImportScope};
0 commit comments