Skip to content

Commit 1ddc00a

Browse files
committed
feat(cpp): add postfix "rc" to reinterpret_cast
1 parent 9a2f6e7 commit 1ddc00a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ tmss! -> absl::flat_hash_map<std::string, std::string>
220220
| `.uu` | Wraps with `(void)?`. | `any_expr` |
221221
| `.ts` | Switches indent's coding style between `CamelCase` and `snake_case`. | `indent` |
222222
| `.sc` | Wraps with `static_cast<>(?)`. | `any_expr` |
223+
| `.rc` | Wraps with `reinterpret_cast<>(?)`. | `any_expr` |
223224
| `.single` | Wraps with `ranges::views::single(?)`. | `any_expr` |
224225
| `.await` | Expands to `co_await ?`. | `any_expr` |
225226
| `.in` | Expands to `if (...find)` statements. | `any_expr` |

lua/luasnip-snippets/snippets/cpp/postfix.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,32 @@ return {
131131
)
132132
),
133133

134+
tsp.treesitter_postfix(
135+
{
136+
trig = ".rc",
137+
name = "(.rc) reinterpret_cast<TYPE>(?)",
138+
dscr = "Wraps an expression with reinterpret_cast<TYPE>(?)",
139+
wordTrig = false,
140+
reparseBuffer = "live",
141+
matchTSNode = {
142+
query = expr_query,
143+
query_lang = "cpp",
144+
},
145+
},
146+
fmt(
147+
[[
148+
reinterpret_cast<{body}>({expr}){end}
149+
]],
150+
{
151+
body = i(1),
152+
expr = f(function(_, parent)
153+
return Utils.replace_all(parent.snippet.env.LS_TSMATCH, "%s")
154+
end, {}),
155+
["end"] = i(0),
156+
}
157+
)
158+
),
159+
134160
tsp.treesitter_postfix(
135161
{
136162
trig = ".in",

0 commit comments

Comments
 (0)