-
Notifications
You must be signed in to change notification settings - Fork 9
/
vscode_ext_gen.py
40 lines (36 loc) · 1.18 KB
/
vscode_ext_gen.py
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
import json
import sys
"""
VS-Code Snippet Syntax
Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
"""
if __name__ == "__main__":
"""
This is a helper script to convert python or any language code to body of VS-Code snippet body"
This wont include tabstops and variables for snippet body
Collect the body string from the stdout and past it to VS-Code snippet body
"""
file_path = "test.py"
if len(sys.argv) > 1:
file_path = sys.argv[1] # if argument is provided use the argument one
# end if
try:
with open(file_path, 'r') as code:
for line in code:
# assume using 4 spaces as tab
line = line.rstrip().replace(" ", "\t")
line = json.dumps(line)
print(line, end=",\n")
except FileNotFoundError:
raise ValueError("""file not found, check command line argument of file path
Usage:
python vscode_ext_gen.py <file_path>
If <file_path> not specify, test.py will be the default file""")