-
Notifications
You must be signed in to change notification settings - Fork 5
/
TreeCommand.py
55 lines (44 loc) · 1.64 KB
/
TreeCommand.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sublime
import sublime_plugin
import threading
import json
import sys
if sys.version_info < (3,):
from BaseCommand import BaseCommand
from BaseThread import BaseThread
from node_dependents_editor_backend import backend
else:
from .BaseCommand import BaseCommand
from .BaseThread import BaseThread
from .node_dependents_editor_backend import backend
class TreeCommand(BaseCommand, sublime_plugin.WindowCommand):
def run(self):
if super(TreeCommand, self).run():
self.init_thread(TreeThread, 'Generating Tree')
class TreeThread(BaseThread):
def __init__(self, command):
self.window = command.window
self.view = command.view
threading.Thread.__init__(self)
def run(self):
"""
Finds the dependents of the current file and jumps to that file or shows a panel of dependent files
"""
tree = self.get_results()
sublime.set_timeout(lambda: self.open_new_file_with_results(tree), 100)
def open_new_file_with_results(self, tree):
new_file = self.window.new_file()
new_file.set_syntax_file('Packages/JavaScript/JSON.tmLanguage')
new_file.set_name('Tree for ' + self.view.file_name())
new_file.run_command('insert_snippet', {'contents': tree})
def get_results(self):
"""
Asks the node tool for the dependents of the current module
"""
tree = backend({
'filename': self.view.filename,
'command': 'get-tree'
})
tree = tree.replace(self.window.config['directory'] + '/', '')
data = json.loads(tree)
return json.dumps(data, indent=4)