Specification
TJ
- https://github.com/microsoft/vscode/blob/6b921dda5c679c6ca1928a4505567c533ede72f9/src/vs/editor/contrib/snippet/browser/snippet.md
- https://code.visualstudio.com/docs/editing/userdefinedsnippets#_placeholders
- Read from package.json location
- Get version and check it
"engines": {
"vscode": "^1.11.0"
},- Read in language locations
"contributes": {
"snippets": [
{
"language": [
"plaintext",
"markdown",
"tex",
"html",
"global",
"all"
],
"path": "./snippets/global.json"
},
{
"language": ["license"],
"path": "./snippets/license.json"
},- Convert Emacs major mode to VSCode language identifier.
- Search by languages. Get all Paths for languages.
- Read all language snippets files.
- Merge them together for search
- When prefix given search for snippet
- If found expand it
Expansion:
- Make into one line divided with \n
- Remove duplicate placeholders (Yasnippet don’t likes duplicates).
- Convert choices to Yasnippet choices
- Search for Variables (e.g Date, Time,)
- Give it to yas-expand-snippet
Most generic: c (for argv[] (prefix . fora) (body . [for (int ${1:i} = ${2:1}; $1 < argc; $1++) {$0 }]) (description . ‘for’ loop for cmdline arguments)) JSON:
"for argv[]": {
"prefix": "fora",
"body": ["for (int ${1:i} = ${2:1}; $1 < argc; $1++) {$0", "}"],
"description": "'for' loop for cmdline arguments"
},Choices: css (align-items (prefix . ai) (body . align-items: ${1|flex-start,flex-end,center,baseline,stretch,start,end,self-start,self-end|};) (description . initial value: stretch)) JSON:
"align-items": {
"prefix": "ai",
"body": "align-items: ${1|flex-start,flex-end,center,baseline,stretch,start,end,self-start,self-end|};",
"description": "initial value: stretch"
},Example multiple choices in yasnippet: $$ Needed for elisp evalution https://pragmaticemacs.wordpress.com/2017/06/25/multiple-choices-in-yasnippets/
# -*- mode: snippet -*-
# name: align-items
# key: ai
# --
Importance: ${1:$$(yas-choose-value '("high" "average" "below average"))}
Difficulty: ${2:$$(yas-choose-value '("easy" "hard"))}
$0Yasnippet don’t like this: It goes to the last one: So we replace all duplicates and leave only one.
# -*- mode: snippet -*-
# name: For Loop
# key: for
# --
for (let ${1:index} = 0; ${1:index} < ${2:array}.length; ${1:index}++) {
const ${3:element} = ${2:array}[${1:index}];
$0
}Variables
- snippy–min-vscode-version
- snippy-package-json-content
- snippy–buffer-language
- snippy–merged-snippets
- snippy-capf-properties
Functions:
- snippy–get-snippet-dir
- snippy-get-package-data
- snippy–clean-version
- snippy-check-engine-version
- snippy–get-vscode-language-name
- snippy–update-buffer-language
- snippy–get-all-snippets-paths
- snippy–turn-on
- snippy–get-all-paths-for-language
- snippy–get-current-language-path
- snippy–find-snippet-by-prefix
- snippy–get-variable-value
- snippy–doc-buffer
- snippy-capf-candidates