# turbo-moonbit snippets. # # Each [[snippet]] becomes one line of the Snippets menu. Snippets sharing a # group appear together in a submenu of that name; one with no group goes into # %s. A snippet is inserted at the cursor, and every line after the # first is indented to match the line you inserted it on. # # languages restricts a snippet to files of those kinds, by the names the # editor uses: bash, dockerfile, html, javascript, markdown, moonbit, toml, # xml, yaml. Leave it out and the snippet is offered everywhere. # # Bodies are indented with two spaces, which is what `moon fmt` writes. Running # the formatter over a file indented any other way rewrites the whole file, so # a snippet that disagrees with it turns one insertion into a large diff. # # Every MoonBit body below is written in single quotes — '''…''' rather than # """…""" — because MoonBit interpolates with \{…}, and a backslash before a # brace is not a valid escape in a TOML basic string. In a literal string a # backslash is just a backslash, which is exactly what a MoonBit snippet needs. # # Your own snippets, shared across every project, go in: # %s [[snippet]] name = "main" group = "MoonBit" languages = ["moonbit"] body = ''' fn main { println("Hello, MoonBit!") }''' [[snippet]] name = "test" group = "MoonBit" languages = ["moonbit"] body = ''' test "it works" { assert_eq(1 + 1, 2) }''' [[snippet]] name = "struct" group = "MoonBit" languages = ["moonbit"] body = ''' struct Point { x : Int y : Int } derive(Eq)''' [[snippet]] name = "enum" group = "MoonBit" languages = ["moonbit"] body = ''' enum Shape { Circle(Double) Rect(Double, Double) } derive(Debug)''' [[snippet]] name = "match" group = "MoonBit" languages = ["moonbit"] body = ''' match value { Some(x) => "got \{x}" None => "nothing" }''' [[snippet]] name = "trait impl" group = "MoonBit" languages = ["moonbit"] body = ''' impl Show for Point with fn output(self, logger) { logger.write_string("Point(\{self.x}, \{self.y})") }''' [[snippet]] name = "loop" group = "MoonBit" languages = ["moonbit"] body = ''' for i = 0, acc = 0 { if i > n { break acc } else { continue i + 1, acc + i } }''' [[snippet]] name = "guard" group = "MoonBit" languages = ["moonbit"] body = ''' guard xs.length() > 0 else { fail("empty") }''' [[snippet]] group = "General" name = "Hello" body = "Hello!!!" [[snippet]] group = "Markdown" name = "Image" languages = ["markdown"] body = "![img](./pictures)"