Created
August 28, 2021 20:18
-
-
Save YannickFricke/4ff9caaba207006911046f5bf2a689a8 to your computer and use it in GitHub Desktop.
Elixir VSCode Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | |
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | |
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | |
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | |
// Placeholders with the same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "scope": "javascript,typescript", | |
// "prefix": "log", | |
// "body": [ | |
// "console.log('$1');", | |
// "$2" | |
// ], | |
// "description": "Log output to console" | |
// } | |
"Access current user": { | |
"scope": "html-eex", | |
"prefix": "user", | |
"body": [ | |
"<%= @current_user.$1 %>" | |
] | |
}, | |
"Elixir statement (HTML EEX)": { | |
"scope": "html-eex", | |
"prefix": "exstmt", | |
"body": [ | |
"<% $1 %>" | |
] | |
}, | |
"Elixir echo statement (HTML EEX)": { | |
"scope": "html-eex", | |
"prefix": "eexstmt", | |
"body": [ | |
"<%= $1 %>" | |
] | |
}, | |
"Elixir if statement (HTML EEX)": { | |
"scope": "html-eex", | |
"prefix": "eixstmt", | |
"body": [ | |
"<%= if $1 do %>", | |
"$2", | |
"<% end %>", | |
] | |
}, | |
"Elixir if else statement (HTML EEX)": { | |
"scope": "html-eex", | |
"prefix": "eiexstmt", | |
"body": [ | |
"<%= if $1 do %>", | |
"$2", | |
"<% else %>", | |
"$3", | |
"<% end %>", | |
] | |
}, | |
"Link (HTML EEX)":{ | |
"scope": "html-eex", | |
"prefix": "link", | |
"body": [ | |
"<%= link \"$1\", to: Routes.$2(@conn, $3) %>", | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | |
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | |
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | |
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | |
// Placeholders with the same ids are connected. | |
// Example: | |
"Create new supervisor module": { | |
"scope": "elixir", | |
"prefix": "sup", | |
"body": [ | |
"defmodule $1 do", | |
" use Supervisor", | |
"", | |
" def start_link(opts) do", | |
" Supervisor.start_link(__MODULE__, :ok, opts)", | |
" end", | |
"", | |
" @impl true", | |
" def init(:ok) do", | |
" children = [$2]", | |
"", | |
" Supervisor.init(children, strategy: :one_for_one)", | |
" end", | |
"end" | |
], | |
"description": "Create a new supervisor" | |
}, | |
"Create new schema": { | |
"scope": "elixir", | |
"prefix": "sche", | |
"body": [ | |
"defmodule $1 do", | |
" use Ecto.Schema", | |
"", | |
" schema \"$2\" do", | |
" field :$3, $4", | |
" end", | |
"end" | |
] | |
}, | |
"Create new GenServer":{ | |
"scope": "elixir", | |
"prefix": "gen", | |
"body": [ | |
"defmodule $1 do", | |
" @name __MODULE__", | |
"", | |
" use GenServer", | |
"", | |
" # Client API", | |
"", | |
" def init(initial_args \\\\\\\\ $2) do", | |
" {:ok, initial_args}", | |
" end", | |
"", | |
" # Server API", | |
"", | |
" def start_link(initial_args \\\\\\\\ $2) do", | |
" GenServer.start_link(@name, initial_args, name: @name)", | |
" end", | |
"end" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment