-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocs.org
More file actions
executable file
·166 lines (150 loc) · 4.53 KB
/
Copy pathdocs.org
File metadata and controls
executable file
·166 lines (150 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#+Title: Development Docs
#+AUTHOR: MiniApollo5935
#+Startup: showeverything
#+Options: toc:2
* Table of Contents :toc:
- [[#links][Links]]
- [[#vscode][Vscode]]
- [[#program-structure][Program Structure]]
- [[#favorite-snippets][Favorite snippets]]
- [[#hacks][Hacks]]
- [[#variables--functions][Variables & Functions]]
* Links
Specification
- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax
TJ
- https://www.youtube.com/watch?v=Dn800rlPIho
- https://www.youtube.com/watch?v=aNWx-ym7jjI
** Vscode
*** Code
https://github.com/microsoft/vscode/tree/6b921dda5c679c6ca1928a4505567c533ede72f9/src/vs/editor/contrib/snippet/browser
*** Docs
- https://github.com/microsoft/vscode/blob/6b921dda5c679c6ca1928a4505567c533ede72f9/src/vs/editor/contrib/snippet/browser/snippet.md
- https://code.visualstudio.com/docs/editing/userdefinedsnippets#_placeholders
* Program Structure
- Read from package.json location
- Get version and check it
#+begin_src javascript
"engines": {
"vscode": "^1.11.0"
},
#+end_src
- Read in language locations
#+begin_src js
"contributes": {
"snippets": [
{
"language": [
"plaintext",
"markdown",
"tex",
"html",
"global",
"all"
],
"path": "./snippets/global.json"
},
{
"language": ["license"],
"path": "./snippets/license.json"
},
#+end_src
- 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
* Favorite snippets
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:
#+begin_src js
"for argv[]": {
"prefix": "fora",
"body": ["for (int ${1:i} = ${2:1}; $1 < argc; $1++) {$0", "}"],
"description": "'for' loop for cmdline arguments"
},
#+end_src
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:
#+begin_src js
"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"
},
#+end_src
* Hacks
Example multiple choices in yasnippet:
$$ Needed for elisp evalution
https://pragmaticemacs.wordpress.com/2017/06/25/multiple-choices-in-yasnippets/
#+begin_src emacs-lisp
# -*- mode: snippet -*-
# name: align-items
# key: ai
# --
Importance: ${1:$$(yas-choose-value '("high" "average" "below average"))}
Difficulty: ${2:$$(yas-choose-value '("easy" "hard"))}
$0
#+end_src
Yasnippet don't like this:
It goes to the last one:
So we replace all duplicates and leave only one.
#+begin_src js
# -*- 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
}
#+end_src
* Variables & Functions
User Variables:
- snippy-install-dir
- snippy-source
- snippy-global-languages
- snippy-emacs-to-vscode-lang-alist
Internal Variables:
- snippy--min-vscode-version
- snippy--package-json-content
- snippy--buffer-language
- snippy--merged-snippets
- snippy--computed-candidates
- snippy--capf-properties
User Functions:
- snippy-install-or-update-snippets
- snippy-refresh-snippets
- snippy-expand
- snippy-fix-lsp-snippet-mode
- snippy-capf
- snippy-minor-mode
- global-snippy-minor-mode
Public functions:
- snippy-transform-snippet-body
- snippy-expand-snippet
Internal 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-paths-for-language
- snippy--get-all-snippets-paths
- snippy--get-current-language-path
- snippy--compute-candidates
- snippy--find-snippet-by-prefix
- snippy--get-variable-value
- snippy--fix-lsp-yasnippet
- snippy--doc-buffer
- snippy--turn-on