motoko 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/contrib/monaco.js CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const { keywords, typeKeywords } = require('../lib/keywords');
4
+ const snippetConfig = require('./snippets.json');
4
5
 
5
6
  /// Monaco editor configuration
6
- exports.configure = (monaco) => {
7
+ exports.configure = (monaco, { snippets } = {}) => {
7
8
  monaco.languages.register({ id: 'motoko' });
8
9
  monaco.languages.setLanguageConfiguration('motoko', {
9
10
  comments: {
@@ -121,4 +122,32 @@ exports.configure = (monaco) => {
121
122
  ],
122
123
  },
123
124
  });
125
+
126
+ if (snippets) {
127
+ monaco.languages.registerCompletionItemProvider('motoko', {
128
+ provideCompletionItems() {
129
+ return {
130
+ suggestions: Object.entries(snippetConfig).map(
131
+ ([name, snippet]) => {
132
+ return {
133
+ label:
134
+ typeof snippet.prefix === 'string'
135
+ ? snippet.prefix
136
+ : snippet.prefix[0],
137
+ detail: name,
138
+ insertText:
139
+ typeof snippet.body === 'string'
140
+ ? snippet.body
141
+ : snippet.body.join('\n'),
142
+ // insert as snippet (https://microsoft.github.io/monaco-editor/api/enums/monaco.languages.CompletionItemInsertTextRule.html)
143
+ insertTextRules: 4,
144
+ // snippet completion (https://microsoft.github.io/monaco-editor/api/enums/monaco.languages.CompletionItemKind.html)
145
+ kind: 27,
146
+ };
147
+ },
148
+ ),
149
+ };
150
+ },
151
+ });
152
+ }
124
153
  };
@@ -0,0 +1,410 @@
1
+ {
2
+ "For Loop (Collection)": {
3
+ "prefix": [
4
+ "for-each"
5
+ ],
6
+ "body": [
7
+ "for(${1:item} in ${2:collection}.vals()) {",
8
+ "\t$0",
9
+ "};"
10
+ ],
11
+ "description": "for loop which iterates through a collection"
12
+ },
13
+ "For Loop (Range)": {
14
+ "prefix": [
15
+ "for-range"
16
+ ],
17
+ "body": [
18
+ "for(${1:i} in Iter.range(0, ${2:count} - 1)) {",
19
+ "\t$0",
20
+ "};"
21
+ ],
22
+ "description": "for loop over a numeric range"
23
+ },
24
+ "Range (Inclusive)": {
25
+ "prefix": [
26
+ "iter-range"
27
+ ],
28
+ "body": [
29
+ "Iter.range(${1:start}, ${2:endInclusive})"
30
+ ],
31
+ "description": "iterator over a range of values (including the upper bound)."
32
+ },
33
+ "Range (Exclusive)": {
34
+ "prefix": [
35
+ "iter-range-exclusive"
36
+ ],
37
+ "body": [
38
+ "Iter.range(${1:start}, ${2:end} - 1)"
39
+ ],
40
+ "description": "iterator over a range of values (excluding the upper bound)."
41
+ },
42
+ "Type Declaration": {
43
+ "prefix": [
44
+ "type"
45
+ ],
46
+ "body": [
47
+ "type ${1:Name} = ${2:declaration};"
48
+ ],
49
+ "description": "simple type declaration"
50
+ },
51
+ "Object Type": {
52
+ "prefix": [
53
+ "type-obj"
54
+ ],
55
+ "body": [
56
+ "type ${1:Name} = {",
57
+ "\t${2:attribute} : ${3:Type};",
58
+ "};"
59
+ ],
60
+ "description": "object / record type block"
61
+ },
62
+ "Type Variant": {
63
+ "prefix": [
64
+ "type-variant"
65
+ ],
66
+ "body": [
67
+ "type ${1:Name} = {",
68
+ "\t#${2:tag};",
69
+ "};"
70
+ ],
71
+ "description": "variant type block"
72
+ },
73
+ "Mutable Variable": {
74
+ "prefix": [
75
+ "var"
76
+ ],
77
+ "body": [
78
+ "var ${1:name} = ${2:value};"
79
+ ],
80
+ "description": "declare a mutable variable"
81
+ },
82
+ "Immutable Variable": {
83
+ "prefix": [
84
+ "let"
85
+ ],
86
+ "body": [
87
+ "let ${1:name} = ${2:value};"
88
+ ],
89
+ "description": "declare an immutable variable"
90
+ },
91
+ "Simple Function": {
92
+ "prefix": [
93
+ "func"
94
+ ],
95
+ "body": [
96
+ "func ${1:name}(${2:arg} : ${5:Type}) : ${4:()} {",
97
+ "\t$0",
98
+ "};"
99
+ ],
100
+ "description": "simple function declaration"
101
+ },
102
+ "Public Actor Function": {
103
+ "prefix": [
104
+ "func-actor"
105
+ ],
106
+ "body": [
107
+ "public func ${1:name}(${2:arg} : ${5:Type}) : async ${4:()} {",
108
+ "\t$0",
109
+ "};"
110
+ ],
111
+ "description": "public actor function declaration"
112
+ },
113
+ "Base Library Import": {
114
+ "prefix": [
115
+ "import-base"
116
+ ],
117
+ "body": [
118
+ "import ${1:Module} \"mo:base/${1}\";"
119
+ ]
120
+ },
121
+ "Canister Import": {
122
+ "prefix": [
123
+ "import-canister"
124
+ ],
125
+ "body": [
126
+ "import ${1:Module} \"canister:${2}\";"
127
+ ]
128
+ },
129
+ "Switch Statement": {
130
+ "prefix": [
131
+ "switch"
132
+ ],
133
+ "body": [
134
+ "switch(${1:input}) {",
135
+ "\tcase($2) { $0 };",
136
+ "\tcase($3) { };",
137
+ "};"
138
+ ]
139
+ },
140
+ "Switch Statement (Option)": {
141
+ "prefix": [
142
+ "switch-option"
143
+ ],
144
+ "body": [
145
+ "switch(${1:input}) {",
146
+ "\tcase(?${2:value}) { $0 };",
147
+ "\tcase(null) { };",
148
+ "};"
149
+ ]
150
+ },
151
+ "Switch Statement (Result)": {
152
+ "prefix": [
153
+ "switch-result"
154
+ ],
155
+ "body": [
156
+ "switch(${1:input}) {",
157
+ "\tcase(#ok(${2:value})) { $0 };",
158
+ "\tcase(#err(${3:error})) { };",
159
+ "};"
160
+ ]
161
+ },
162
+ "Module": {
163
+ "prefix": [
164
+ "module"
165
+ ],
166
+ "body": [
167
+ "module {",
168
+ "\tpublic let ${1:value} = ${2:0};",
169
+ "\t",
170
+ "\tpublic func ${3:name}(${4:arg : Text}) : ${5:()} {",
171
+ "\t\t$0",
172
+ "\t};",
173
+ "};"
174
+ ]
175
+ },
176
+ "Actor": {
177
+ "prefix": [
178
+ "actor"
179
+ ],
180
+ "body": [
181
+ "actor {",
182
+ "\tstable var ${1:state} = ${2:0};",
183
+ "\t",
184
+ "\tpublic func ${3:name}(${4:arg : Text}) : async ${5:()} {",
185
+ "\t\t$0",
186
+ "\t};",
187
+ "};"
188
+ ]
189
+ },
190
+ "Actor Class": {
191
+ "prefix": [
192
+ "actor-class"
193
+ ],
194
+ "body": [
195
+ "actor class ${1:Name}($2) = self {",
196
+ "\tstable var ${3:state} = ${4:0};",
197
+ "\t",
198
+ "\tpublic func ${5:name}(${6:input : Text}) : async ${7:()} {",
199
+ "\t\t$0",
200
+ "\t};",
201
+ "};"
202
+ ]
203
+ },
204
+ "Class": {
205
+ "prefix": [
206
+ "class"
207
+ ],
208
+ "body": [
209
+ "class ${1:Name}($2) = self {",
210
+ "\tvar ${3:state} = ${4:0};",
211
+ "\t",
212
+ "\tpublic func ${5:name}(${6:input : Text}) : ${7:()} {",
213
+ "\t\t$0",
214
+ "\t};",
215
+ "};"
216
+ ]
217
+ },
218
+ "Record": {
219
+ "prefix": [
220
+ "record"
221
+ ],
222
+ "body": [
223
+ "{",
224
+ "\t${1:key} = ${2:value};",
225
+ "}"
226
+ ],
227
+ "description": "record value (equivalent to an object in JS, dictionary in Python)"
228
+ },
229
+ "Do Block": {
230
+ "prefix": [
231
+ "do"
232
+ ],
233
+ "body": [
234
+ "do {",
235
+ "\t$0",
236
+ "}"
237
+ ]
238
+ },
239
+ "Anonymous Function": {
240
+ "prefix": [
241
+ "lambda"
242
+ ],
243
+ "body": [
244
+ "func ($1) { $0 }"
245
+ ],
246
+ "description": "a lambda expression"
247
+ },
248
+ "Array Literal": {
249
+ "prefix": [
250
+ "array"
251
+ ],
252
+ "body": [
253
+ "[$0]"
254
+ ],
255
+ "description": "an immutable array (values cannot be replaced)"
256
+ },
257
+ "Mutable Array Literal": {
258
+ "prefix": [
259
+ "array-mut"
260
+ ],
261
+ "body": [
262
+ "[var $0]"
263
+ ],
264
+ "description": "a mutable array (values can be replaced)"
265
+ },
266
+ "New Array": {
267
+ "prefix": [
268
+ "array-new"
269
+ ],
270
+ "body": [
271
+ "var ${1:array} = [];"
272
+ ]
273
+ },
274
+ "New Hash Map": {
275
+ "prefix": [
276
+ "hash-map-new"
277
+ ],
278
+ "body": [
279
+ "let ${1:map} = HashMap.HashMap<${2:Text}, ${3:Nat}>(0, ${2}.equal, ${2}.hash);"
280
+ ]
281
+ },
282
+ "New Trie": {
283
+ "prefix": [
284
+ "trie-new"
285
+ ],
286
+ "body": [
287
+ "var ${1:trie} = Trie.empty<${2:Text}, ${3:Nat}>();"
288
+ ]
289
+ },
290
+ "New Trie Map": {
291
+ "prefix": [
292
+ "trie-map-new"
293
+ ],
294
+ "body": [
295
+ "let ${1:map} = TrieMap.TrieMap<${2:Text}, ${3:Nat}>(0);"
296
+ ]
297
+ },
298
+ "New RB Tree": {
299
+ "prefix": [
300
+ "rb-tree-new"
301
+ ],
302
+ "body": [
303
+ "let ${1:map} = RBTree.RBTree<${2:Text}, ${3:Nat}>(${2}.compare);"
304
+ ]
305
+ },
306
+ "New Trie Set": {
307
+ "prefix": [
308
+ "trie-set-new"
309
+ ],
310
+ "body": [
311
+ "let ${1:set} = TrieSet.empty<${2:Text}>();"
312
+ ]
313
+ },
314
+ "New Deque": {
315
+ "prefix": [
316
+ "deque-new"
317
+ ],
318
+ "body": [
319
+ "let ${1:queue} = Deque.empty<${2:Text}>();"
320
+ ]
321
+ },
322
+ "New List": {
323
+ "prefix": [
324
+ "list-new"
325
+ ],
326
+ "body": [
327
+ "var ${1:list} = List.nil<${2:Text}>();"
328
+ ]
329
+ },
330
+ "Sort Array": {
331
+ "prefix": [
332
+ "sort-array"
333
+ ],
334
+ "body": [
335
+ "Array.sort<$1>(${2:array}, func (a : $1, b : $1) { ${3:#equal} })"
336
+ ]
337
+ },
338
+ "Ok (Result)": {
339
+ "prefix": [
340
+ "ok"
341
+ ],
342
+ "body": [
343
+ "#ok($0)"
344
+ ]
345
+ },
346
+ "Error (Result)": {
347
+ "prefix": [
348
+ "err"
349
+ ],
350
+ "body": [
351
+ "#err($0)"
352
+ ]
353
+ },
354
+ "Array to Blob": {
355
+ "prefix": [
356
+ "array-2-blob"
357
+ ],
358
+ "body": [
359
+ "Blob.fromArray(${1:array})"
360
+ ]
361
+ },
362
+ "Blob to Array": {
363
+ "prefix": [
364
+ "blob-2-array"
365
+ ],
366
+ "body": [
367
+ "Blob.toArray(${1:blob})"
368
+ ]
369
+ },
370
+ "Array to Buffer": {
371
+ "prefix": [
372
+ "array-2-buffer"
373
+ ],
374
+ "body": [
375
+ "Buffer.fromArray(${1:array})"
376
+ ]
377
+ },
378
+ "Buffer to Array": {
379
+ "prefix": [
380
+ "buffer-2-array"
381
+ ],
382
+ "body": [
383
+ "Buffer.toArray(${1:buffer})"
384
+ ]
385
+ },
386
+ "Principal to Text": {
387
+ "prefix": [
388
+ "principal-2-text"
389
+ ],
390
+ "body": [
391
+ "Principal.toText(${1:principal})"
392
+ ]
393
+ },
394
+ "Text to Principal": {
395
+ "prefix": [
396
+ "text-2-principal"
397
+ ],
398
+ "body": [
399
+ "Principal.fromText(${1:text})"
400
+ ]
401
+ },
402
+ "Actor to Principal": {
403
+ "prefix": [
404
+ "actor-2-principal"
405
+ ],
406
+ "body": [
407
+ "Principal.fromActor(${1:actor})"
408
+ ]
409
+ }
410
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motoko",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "Compile and run Motoko smart contracts in Node.js or the browser.",
5
5
  "author": "Ryan Vandersmith (https://github.com/rvanasa)",
6
6
  "license": "Apache-2.0",
@@ -22,7 +22,7 @@
22
22
  "cross-fetch": "3.1.5",
23
23
  "debug": "4.3.4",
24
24
  "isomorphic-parse-github-url": "1.0.2",
25
- "sanitize-filename": "^1.6.3"
25
+ "sanitize-filename": "1.6.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/jest": "^28.1.3",