forked from nvim-lua/kickstart.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_snippets.py
More file actions
35 lines (31 loc) · 1010 Bytes
/
Copy pathgenerate_snippets.py
File metadata and controls
35 lines (31 loc) · 1010 Bytes
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
# Generates cpp.json with VSCode-style snippets for LuaSnip
import os, json, sys
snippets = {}
paths = {}
for root, dirs, files in os.walk('.'):
dirs[:] = [d for d in dirs if d != '.git']
if root == '.':
continue
for file in files:
name, ext = os.path.splitext(file)
if ext != '.cpp':
continue
path = os.path.join(root, file)
if name in snippets:
print(f'error: duplicate snippet {name}', file=sys.stderr)
print(f' first: {paths[name]}', file=sys.stderr)
print(f' second: {path}', file=sys.stderr)
sys.exit(1)
paths[name] = path
with open(path) as f:
snippets[name] = {
'prefix': name,
'body': [line.rstrip() for line in f],
'description': name
}
out = os.path.join('snippets', 'cpp.json') if os.path.isdir('snippets') else 'cpp.json'
with open(out, 'w') as f:
json.dump(snippets, f, indent=2)
for name in snippets:
print(f'generated snippet {name}', file=sys.stderr)
print('done', file=sys.stderr)