Skip to content

Commit 663cad4

Browse files
committed
feat(rust): add .match, extends .ref and .refm
1 parent 92424df commit 663cad4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ ls.setup({
196196
| `.rw` | Wraps with `RwLock::new(?)` if expr, `RwLock<?>` if type. | `expr_or_type` |
197197
| `.cell` | Wraps with `Cell::new(?)` if expr, `Cell<?>` if type. | `expr_or_type` |
198198
| `.refcell` | Wraps with `RefCell::new(?)` if expr, `RefCell<?>` if type. | `expr_or_type` |
199-
| `.ref` | Wraps with `&?`. | `expr` |
200-
| `.refm` | Wraps with `&mut ?`. | `expr` |
199+
| `.ref` | Wraps with `&?`. | `expr_or_type` |
200+
| `.refm` | Wraps with `&mut ?`. | `expr_or_type` |
201201
| `.ok` | Wraps with `Ok(?)`. | `expr` |
202202
| `.err` | Wraps with `Err(?)`. | `expr` |
203203
| `.some` | Wraps with `Some(?)`. | `expr` |
204204
| `.println` | Wraps with `println!("{:?}", ?)`. | `expr` |
205+
| `.match` | Wraps with `match ? {}`. | `expr` |
205206

206207
</details>
207208

lua/luasnip-snippets/snippets/rust/postfix.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ return {
9999
expr_or_type_tsp(".rw", "RwLock"),
100100
expr_or_type_tsp(".cell", "Cell"),
101101
expr_or_type_tsp(".refcell", "RefCell"),
102-
expr_tsp(".ref", "&?"),
103-
expr_tsp(".refm", "&mut ?"),
102+
expr_or_type_tsp(".ref", "&?"),
103+
expr_or_type_tsp(".refm", "&mut ?"),
104104
expr_tsp(".ok", "Ok(?)"),
105105
expr_tsp(".err", "Err(?)"),
106106
expr_tsp(".some", "Some(?)"),
@@ -123,4 +123,24 @@ return {
123123
)
124124
end, {}),
125125
}),
126+
127+
tsp.treesitter_postfix({
128+
trig = ".match",
129+
name = [[(.match) match ?]],
130+
dscr = [[Wrap expression with match ? block]],
131+
wordTrig = false,
132+
reparseBuffer = nil,
133+
matchTSNode = {
134+
query = expr_query,
135+
query_lang = "rust",
136+
},
137+
}, {
138+
f(function(_, parent)
139+
return Utils.replace_all(
140+
parent.snippet.env.LS_TSMATCH,
141+
[[match %s {
142+
}]]
143+
)
144+
end, {}),
145+
}),
126146
}

0 commit comments

Comments
 (0)