AvinZarlez / processing-vscode

A Visual Studio Code extension for the programming language Processing
https://marketplace.visualstudio.com/items?itemName=Tobiah.language-pde
MIT License
177 stars 25 forks source link

Update snippets.json for better autocomplete #75

Closed jerrylususu closed 4 years ago

jerrylususu commented 5 years ago

Replace the numbered prefix to more detailed items.

Before: 图片 After: 图片

How is this done?

import json
with open("snippets.json") as f:
    snippets = json.load(f)
another_dict = {}
for k,v in snippets.items():
#     print(k,"_".join(v["description"].split()))
    concated = "_".join(v["description"].split())
    if not concated in snippets:
        if not concated in another_dict: 
            another_dict[concated] = v.copy()
            another_dict[concated]["prefix"] = concated
        else:
            print(concated, v)
    else:
        another_dict[k] = v.copy()
# output:
# keyPressed {'prefix': 'key', 'body': 'void keyPressed() {\n\t${1}\n}', 'description': 'keyPressed', 'scope': 'source.pde'}
# mousePressed {'prefix': 'mouse', 'body': 'void mousePressed() {\n\t${1}\n}', 'description': 'mousePressed', 'scope': 'source.pde'}
# These two have duplicated var name and method, so add the `_func` postfix for method.
with open('edited.json','w') as f:
    json.dump(another_dict, f)
AvinZarlez commented 5 years ago

This looks excellent! I'm traveling at the moment, but when I can I'll sit down and test + release this. Thank you!