-
Notifications
You must be signed in to change notification settings - Fork 0
/
shards.code-snippets
192 lines (192 loc) · 5.09 KB
/
shards.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{
"C++ Prelude": {
"scope": "cpp",
"prefix": "prelude",
"body": [
"#include <shards/core/shared.hpp>",
"#include <shards/core/params.hpp>",
"#include <shards/common_types.hpp>",
],
"description": "Common includes for new shard implementations"
},
"C++ Shard Help": {
"scope": "cpp",
"prefix": "shardhelp",
"body": [
"static SHOptionalString help() { return SHCCSTR(\"$0\"); }",
]
},
"C++ Shard": {
"scope": "cpp",
"prefix": "shard",
"body": [
"struct ${0:SHARD_NAME} {",
" static SHTypesInfo inputTypes() { return shards::CoreInfo::AnyType; }",
" static SHTypesInfo outputTypes() { return shards::CoreInfo::AnyType; }",
" static SHOptionalString help() { return SHCCSTR(\"\"); }",
" ",
" PARAM_PARAMVAR(_someParam, \"RenameThis\", \"AddDescriptionHere\", {shards::CoreInfo::AnyType});",
" PARAM_IMPL(PARAM_IMPL_FOR(_someParam));",
" ",
" void warmup(SHContext *context) {",
" PARAM_WARMUP(context);",
" }",
" void cleanup(SHContext *context) {",
" PARAM_CLEANUP(context);",
" }",
" ",
" PARAM_REQUIRED_VARIABLES();",
" SHTypeInfo compose(SHInstanceData &data) {",
" PARAM_COMPOSE_REQUIRED_VARIABLES(data);",
" return outputTypes().elements[0];",
" }",
" ",
" SHVar activate(SHContext *shContext, const SHVar &input) { return input; }",
"};",
],
"description": "New C++ shard scaffolding"
},
"Register shards": {
"scope": "cpp",
"prefix": "register_shard",
"body": [
"SHARDS_REGISTER_FN($0) {",
"\t//REGISTER_SHARD(\"ShardName\", ShardName);",
"}",
],
"description": "C++ registration scaffolding"
},
"Rust Enum": {
"scope": "rust",
"prefix": "enum",
"body": [
"#[derive(shards::shards_enum)]",
"#[enum_info(",
" b\"${2:aaaa}\",",
" \"${1:NAME}\",",
" \"AddDescriptionHere\"",
")]",
"pub enum ${1:NAME} {",
" #[enum_value(\"AddDescriptionHere\")]",
" None = 0x0,",
"}",
],
"description": "New rust enum scaffolding"
},
"Warmup + Cleanup + Compose defaults": {
"scope": "rust",
"prefix": "compose_warmup_cleanup",
"body": [
" fn warmup(&mut self, ctx: &Context) -> Result<(), &str> {",
" self.warmup_helper(ctx)?;",
" Ok(())",
" }",
"",
" fn cleanup(&mut self, ctx: Option<&Context>) -> Result<(), &str> {",
" self.cleanup_helper(ctx)?;",
" Ok(())",
" }",
"",
" fn compose(&mut self, data: &InstanceData) -> Result<Type, &str> {",
" self.compose_helper(data)?;",
" Ok(self.output_types()[0])",
" }",
"",
" fn activate(&mut self, _context: &Context, _input: &Var) -> Result<Var, &str> {",
" Ok(Var::default())",
" }",
],
"description": "New rust enum scaffolding"
},
"Try cast variable": {
"scope": "rust",
"prefix": "tryvar",
"body": [
"if let Ok(v) = TryInto::<${2:TYPE}>::try_into(&${1:VAR}) {",
" $0",
"}",
],
"description": "Try cast SHVar into some native rust type"
},
"Try cast with default": {
"scope": "rust",
"prefix": "tryvardefault",
"body": [
"let v = TryInto::<${2:TYPE}>::try_into(&${1:VAR}).unwrap_or_default();",
],
"description": "Try cast SHVar into some native rust type, with default fallback"
},
"Rust Prelude": {
"scope": "rust",
"prefix": "prelude",
"body": [
"use shards::types::{ExposedTypes, Types, Context, InstanceData, Type, Var, ParamVar};",
"use shards::types::{common_type, NONE_TYPES};",
"use shards::shard::Shard;",
"use shards::core::{register_shard, register_enum};",
],
"description": "Common imports for new shard implementations"
},
"Rust Param": {
"scope": "rust",
"prefix": "param",
"body": [
"#[shard_param(\"${1:NAME}\", \"AddDescriptionHere\", [common_type::int])]",
"${1/(.*)/${1:/downcase}/}: ${2:ParamVar},",
],
"description": "A shard parameter"
},
"Rust Shard": {
"scope": "rust",
"prefix": "shard",
"body": [
"#[derive(shards::shard)]",
"#[shard_info(\"${1:NAME}\", \"AddDescriptionHere\")]",
"struct ${1:NAME}Shard {",
" #[shard_required]",
" required: ExposedTypes,",
"}",
"",
"impl Default for ${1:Name}Shard {",
" fn default() -> Self {",
" Self {",
" required: ExposedTypes::new(),",
" }",
" }",
"}",
"",
"#[shards::shard_impl]",
"impl Shard for ${1:Name}Shard {",
" fn input_types(&mut self) -> &Types {",
" &NONE_TYPES",
" }",
"",
" fn output_types(&mut self) -> &Types {",
" &NONE_TYPES",
" }",
"",
" fn warmup(&mut self, ctx: &Context) -> Result<(), &str> {",
" self.warmup_helper(ctx)?;",
" ",
" Ok(())",
" }",
"",
" fn cleanup(&mut self, ctx: Option<&Context>) -> Result<(), &str> {",
" self.cleanup_helper(ctx)?;",
" ",
" Ok(())",
" }",
"",
" fn compose(&mut self, data: &InstanceData) -> Result<Type, &str> {",
" self.compose_helper(data)?;",
" Ok(self.output_types()[0])",
" }",
"",
" fn activate(&mut self, _context: &Context, _input: &Var) -> Result<Var, &str> {",
" Ok(Var::default())",
" }",
"}",
],
"description": "New rust shard scaffolding"
}
}