-
Notifications
You must be signed in to change notification settings - Fork 5
/
JumpToDependency.py
78 lines (60 loc) · 2.09 KB
/
JumpToDependency.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sublime_plugin
import threading
import sys
if sys.version_info < (3,):
from BaseCommand import BaseCommand
from BaseThread import BaseThread
from lib.printer import p
from node_dependents_editor_backend import backend
else:
from .BaseCommand import BaseCommand
from .BaseThread import BaseThread
from .lib.printer import p
from .node_dependents_editor_backend import backend
class JumpToDependencyCommand(BaseCommand, sublime_plugin.WindowCommand):
def run(self):
if super(JumpToDependencyCommand, self).run():
# Done on main thread due to ST2
self.view.selection = self.get_selection()
self.init_thread(JumpToDependencyThread, 'Jumping to dependency')
def get_selection(self):
"""
Returns the sublime region corresponding to the selected module path
"""
selections = self.view.sel()
if not selections:
return None
region = selections[0]
row, col = self.view.rowcol(region.a)
p('clicked row: ', row)
p('clicked col: ', col)
p('region: ', region)
line = self.view.substr(self.view.line(region))
p('line: ', line)
p('line length: ', len(line))
return {
"clicked_position": col,
"line": line
}
class JumpToDependencyThread(BaseThread):
"""
A thread to prevent the jump to dependency from freezing the UI
"""
def __init__(self, command):
self.window = command.window
self.view = command.view
threading.Thread.__init__(self)
def run(self):
"""
Jumps to the file identified by the string under the cursor
"""
selection = self.view.selection
p('Extracted Selection', selection)
file_to_open = backend({
'filename': self.view.filename,
'path': selection.get('line'),
'lookup_position': selection.get('clicked_position'),
'command': 'lookup'
}).strip()
p('After cabinet lookup', file_to_open)
self.open_file(file_to_open)