-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlambda_store.py
36 lines (29 loc) · 1.13 KB
/
lambda_store.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
import sublime, sublime_plugin
import urllib
import json
settings = None
LIST_URL = '{}/list'
FUNC_URL = '{}/func/'
def resp(url):
try:
data = urllib.request.urlopen(url).read().decode("utf8")
return json.loads(data)
except Exception:
return {}
class LambdaStoreInsertCommand(sublime_plugin.TextCommand):
def run(self, edit, to_insert=""):
self.view.insert(edit, self.view.sel()[0].begin(), to_insert)
class LambdaStoreCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.methods_list = resp(LIST_URL.format(settings.get('endpoint'))).get('functions', [])
self.view.window().show_quick_panel(self.methods_list, lambda x:self.on_select(x))
def on_select(self, index):
if index < 0:
return
func_source = resp(FUNC_URL.format(settings.get('endpoint')) + self.methods_list[index]).get('func', '')
self.view.run_command("lambda_store_insert", {'to_insert': func_source})
def plugin_loaded():
global settings
settings = sublime.load_settings('lambda_store.sublime-settings')
if int(sublime.version()) < 3000:
plugin_loaded()