| 📦 Turbo MoonBit cc1f595 k33g 16h ago | 1 | # turbo-moonbit snippets. |
| 2 | # |
| 3 | # Each [[snippet]] becomes one line of the Snippets menu. Snippets sharing a |
| 4 | # group appear together in a submenu of that name; one with no group goes into |
| 5 | # General. A snippet is inserted at the cursor, and every line after the |
| 6 | # first is indented to match the line you inserted it on. |
| 7 | # |
| 8 | # languages restricts a snippet to files of those kinds, by the names the |
| 9 | # editor uses: bash, dockerfile, html, javascript, markdown, moonbit, toml, |
| 10 | # xml, yaml. Leave it out and the snippet is offered everywhere. |
| 11 | # |
| 12 | # Bodies are indented with two spaces, which is what `moon fmt` writes. Running |
| 13 | # the formatter over a file indented any other way rewrites the whole file, so |
| 14 | # a snippet that disagrees with it turns one insertion into a large diff. |
| 15 | # |
| 16 | # Every MoonBit body below is written in single quotes — '''…''' rather than |
| 17 | # """…""" — because MoonBit interpolates with \{…}, and a backslash before a |
| 18 | # brace is not a valid escape in a TOML basic string. In a literal string a |
| 19 | # backslash is just a backslash, which is exactly what a MoonBit snippet needs. |
| 20 | # |
| 21 | # Your own snippets, shared across every project, go in: |
| 22 | # /Users/k33g/Library/Application Support/turbo-moonbit/snippets.toml |
| 23 | |
| 24 | [[snippet]] |
| 25 | name = "main" |
| 26 | group = "MoonBit" |
| 27 | languages = ["moonbit"] |
| 28 | body = ''' |
| 29 | fn main { |
| 30 | println("Hello, MoonBit!") |
| 31 | }''' |
| 32 | |
| 33 | [[snippet]] |
| 34 | name = "test" |
| 35 | group = "MoonBit" |
| 36 | languages = ["moonbit"] |
| 37 | body = ''' |
| 38 | test "it works" { |
| 39 | assert_eq(1 + 1, 2) |
| 40 | }''' |
| 41 | |
| 42 | [[snippet]] |
| 43 | name = "struct" |
| 44 | group = "MoonBit" |
| 45 | languages = ["moonbit"] |
| 46 | body = ''' |
| 47 | struct Point { |
| 48 | x : Int |
| 49 | y : Int |
| 50 | } derive(Eq)''' |
| 51 | |
| 52 | [[snippet]] |
| 53 | name = "enum" |
| 54 | group = "MoonBit" |
| 55 | languages = ["moonbit"] |
| 56 | body = ''' |
| 57 | enum Shape { |
| 58 | Circle(Double) |
| 59 | Rect(Double, Double) |
| 60 | } derive(Show)''' |
| 61 | |
| 62 | [[snippet]] |
| 63 | name = "match" |
| 64 | group = "MoonBit" |
| 65 | languages = ["moonbit"] |
| 66 | body = ''' |
| 67 | match value { |
| 68 | Some(x) => "got \{x}" |
| 69 | None => "nothing" |
| 70 | }''' |
| 71 | |
| 72 | [[snippet]] |
| 73 | name = "trait impl" |
| 74 | group = "MoonBit" |
| 75 | languages = ["moonbit"] |
| 76 | body = ''' |
| 77 | impl Show for Point with fn output(self, logger) { |
| 78 | logger.write_string("Point(\{self.x}, \{self.y})") |
| 79 | }''' |
| 80 | |
| 81 | [[snippet]] |
| 82 | name = "loop" |
| 83 | group = "MoonBit" |
| 84 | languages = ["moonbit"] |
| 85 | body = ''' |
| 86 | loop (0, 0) { |
| 87 | (i, acc) => if i > n { break acc } else { continue (i + 1, acc + i) } |
| 88 | }''' |
| 89 | |
| 90 | [[snippet]] |
| 91 | name = "guard" |
| 92 | group = "MoonBit" |
| 93 | languages = ["moonbit"] |
| 94 | body = ''' |
| 95 | guard xs.length() > 0 else { fail("empty") }''' |
| 96 | |
| 97 | [[snippet]] |
| 98 | group = "General" |
| 99 | name = "Hello" |
| 100 | body = "Hello!!!" |
| 101 | |
| 102 | [[snippet]] |
| 103 | group = "Markdown" |
| 104 | name = "Image" |
| 105 | languages = ["markdown"] |
| 106 | body = "" |