Skip to content

Instantly share code, notes, and snippets.

@undoZen
Last active April 24, 2024 00:25
Show Gist options
  • Save undoZen/d104b2c88086f90165c438b61ef7c99b to your computer and use it in GitHub Desktop.
Save undoZen/d104b2c88086f90165c438b61ef7c99b to your computer and use it in GitHub Desktop.
Remesh snippets for VSCode

Remesh snippets for VS Code.

Installation

VSCode

per workspace

  1. cd into you the .vscode directory in your project, mkdir .vscode if this folder does not exists.
  2. wget https://gist.githubusercontent.com/undoZen/d104b2c88086f90165c438b61ef7c99b/raw/typescript.code-snippets

globally

ctrl/cmd + shift + p run Configure User Snippets, edit your typescript.json files, copy the file into it.

Neovim

You can use LuaSnip to load VSCode format snippets.

copy typescript.code-snippets to snippets/remesh.json under your nvim config path, then add a snippets/package.json file to load this snippets config file:

{
    "name": "my-custom-snippets",
    "contributes": {
        "snippets": [
            {
                "language": [
                    "javascript",
                    "javascriptreact",
                    "typescript",
                    "typescriptreact"
                ],
                "path": "./remesh.json"
            }
        ]
    }
}

then in your init.lua, add

require("luasnip.loaders.from_vscode").lazy_load() -- this load default luasnip snippets config
require("luasnip.loaders.from_vscode").load({paths = "./snippets"})
{
"fromQuery startWith current": {
"prefix": [
"fqsw"
],
"body": [
"fromQuery($1())",
"\t.pipe(startWith(get($1())))"
]
},
"Remesh AsyncModule": {
"prefix": [
"rasync"
],
"body": [
"const $1AsyncModule = AsyncModule(domain, {",
"\tname: '$1AsyncModule',",
"\tload: async ({ get }${2:, arg}) => {",
"\t\t$3",
"\t},",
"\tonSuccess: ({ get }, json${4:, arg}) => {",
"\t\t$5",
"\t},",
"});"
]
},
"Remesh Domain": {
"prefix": [
"rdomain"
],
"body": [
"const $1Domain = Remesh.domain({",
"\tname: '$1Domain',",
"\timpl: (domain${2:, arg}) => {",
"\t\t$3",
"",
"\t\treturn {",
"\t\t\tquery: {",
"\t\t\t},",
"\t\t}",
"\t},",
"});"
]
},
"Remesh State": {
"prefix": [
"rstate"
],
"body": [
"const $1State = domain.state<$2>({",
"\tname: '$1State',",
"\tdefault: $3,",
"});",
"const $1Query = domain.query({",
"\tname: '$1Query',",
"\timpl: ({ get }) => {",
"\t\treturn get($1State())",
"\t},",
"});",
"const Set$1Command = domain.command({",
"\tname: 'Set$1Command',",
"\timpl: ({ }${4:, newValue}: $2) => {",
"\t\treturn [$1State().new(newValue)]",
"\t},",
"});"
]
},
"Remesh Query": {
"prefix": [
"rquery"
],
"body": [
"const $1Query = domain.query({",
"\tname: '$1Query',",
"\timpl: ({ get }${2:, arg}) => {",
"\t\t$3",
"\t},",
"});"
]
},
"Remesh Command": {
"prefix": [
"rcommand"
],
"body": [
"const $1Command = domain.command({",
"\tname: '$1Command',",
"\timpl: ({ get }${2:, arg}) => {",
"\t\treturn [$3]",
"\t},",
"});"
]
},
"Remesh Event": {
"prefix": [
"revent"
],
"body": [
"const $1Event = domain.event<${2:void}>({",
"\tname: '$1Event',",
"});"
]
},
"Remesh Effect": {
"prefix": [
"reffect"
],
"body": [
"domain.effect({",
"\tname: '$1Effect',",
"\timpl: ({ get, fromQuery, fromEvent }) => {",
"\t\treturn $2",
"\t},",
"});"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment