Skip to content

Commit dc1ecde

Browse files
committed
feat(cpp): add more snippets
1 parent 942d42b commit dc1ecde

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ ls.setup({
5353
| `\|filter` | Expand to ranges::views::filter pipe. | No |
5454
| `cpo` | Expand to customize point object. | No |
5555
| `ns%s(%S+)` | Expand to namespace block (including comments). | No |
56+
| `itf` | Expand to a struct with default virtual destruction. | No |
57+
| `pvf` | Expand to a pure virtual function declaration. | No |
5658

5759
#### Auto-snippets
5860

@@ -75,6 +77,8 @@ ls.setup({
7577
| `i32` | Expand to `int32_t`. | No |
7678
| `i64` | Expand to `int64_t`. | No |
7779
| `t(%s)!` | Evaluate (QET) marker, and expand to typename. | No |
80+
| `#"` | Expand to include statement with quotes. `#include ""`. | No |
81+
| `#<` | Expand to include statement with `<>`. `#include <>`. | No |
7882

7983
##### Quick Expand Type markers
8084

lua/luasnip-snippets/snippets/cpp/default.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ return {
177177
},
178178
},
179179

180+
-- include short cuts
181+
snippet {
182+
'#"',
183+
name = 'include ""',
184+
dscr = "#include with quotes",
185+
mode = "bA",
186+
nodes = {
187+
t('#include "'),
188+
i(1, "header"),
189+
t('"'),
190+
},
191+
},
192+
snippet {
193+
"#<",
194+
name = "include <>",
195+
dscr = "#include with <>",
196+
mode = "bA",
197+
nodes = {
198+
t("#include <"),
199+
i(1, "header"),
200+
t(">"),
201+
},
202+
},
203+
180204
-- fast int types
181205
int_type_snippet(8, true),
182206
int_type_snippet(8, false),

lua/luasnip-snippets/snippets/cpp/statements.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ local d = ls.dynamic_node
44
local sn = ls.snippet_node
55
local t = ls.text_node
66
local fmta = require("luasnip.extras.fmt").fmta
7+
local snippet = require("luasnip-snippets.nodes").construct_snippet
8+
local i = require("luasnip-snippets.nodes").insert_node
9+
local c = require("luasnip-snippets.nodes").choice_node
10+
local rep = require("luasnip.extras").rep
711

812
local function inject_class_name(_, line_to_cursor, match, captures)
913
-- check if at the line begin
@@ -135,4 +139,36 @@ return {
135139
<cls>(<cls>&&) = delete;
136140
]]
137141
),
142+
snippet {
143+
"itf",
144+
name = "Interface",
145+
dscr = "Declare interface",
146+
mode = "bw",
147+
nodes = fmta(
148+
[[
149+
struct <> {
150+
virtual ~<>() = default;
151+
152+
<>
153+
};
154+
]],
155+
{
156+
i(1, "Interface"),
157+
rep(1),
158+
i(0),
159+
}
160+
),
161+
},
162+
snippet {
163+
"pvf",
164+
name = "Pure virtual function",
165+
dscr = "Declare pure virtual function",
166+
mode = "bw",
167+
nodes = fmta("virtual <ret_t> <name>(<args>) <specifier> = 0;", {
168+
name = i(1, "func", { dscr = "Function name" }),
169+
args = i(2, "args", { dscr = "Function arguments" }),
170+
specifier = i(3, "const", { dscr = "Function specifier" }),
171+
ret_t = i(4, "void", { dscr = "Return type" }),
172+
}),
173+
},
138174
}

0 commit comments

Comments
 (0)