-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathnavigation.py
104 lines (77 loc) · 3.19 KB
/
navigation.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import re
import sublime
import sublime_plugin
from Dart._init_ import editor_context
from Dart.lib.notifications import show_analysis_tooltip
from Dart.lib.notifications import show_status_tooltip
class DartGoToDeclaration(sublime_plugin.WindowCommand):
def run(self):
try:
view = self.window.active_view()
if not view:
return
except Exception as e:
return
sel = view.sel()[0]
self.get_navigation(view, sel)
def get_navigation(self, view, r):
# FIXME(guillermooo): we may have a race condition here, or get info
# for the wrong file.
navigation = editor_context.navigation
if not navigation:
sublime.status_message('Dart: No navigation available.')
return
sources = navigation.regions
# TODO(guillermooo): move this check to the generated API.
targets = [source for source in sources
if source.offset <= r.begin() <= (source.offset + source.length)]
if not targets:
show_status_tooltip("No navigations available at this location.", timeout=3000)
sublime.status_message('Dart: No navigations available for the current location.')
return
first_target = targets[0].targets[0]
first_target = navigation.targets[first_target]
fname = navigation.files[first_target.fileIndex]
row = first_target.startLine
col = first_target.startColumn
self.window.open_file("{}:{}:{}".format(fname, row, col), sublime.ENCODED_POSITION)
class ErrorNavigator(object):
'''
Navigates the errors received from the analysis server and stored in the
global EditorContext.
'''
ERROR_LINE_RX = re.compile(r'^(?P<severity>\w+)\|(?P<type>\w+)\|(?P<fname>.+)\|(?P<row>\d+)\|(?P<col>\d+)\|(?P<message>.+)$')
def __init__(self, editor_context):
self.editor_context = editor_context
def next(self):
self.editor_context.increment_error_index()
match = self.ERROR_LINE_RX.match(editor_context.get_current_error())
return match.groupdict()
def previous(self):
self.editor_context.decrement_error_index()
match = self.ERROR_LINE_RX.match(editor_context.get_current_error())
return match.groupdict()
class DartGoToNextResult(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('next_result')
# todo(guillermo): check that the errors affect the current file.
if editor_context.errors:
navi = ErrorNavigator(editor_context)
try:
data = navi.next()
except IndexError:
return
else:
show_analysis_tooltip(data)
class DartGoToPrevResult(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('prev_result')
# todo(guillermo): check that the errors affect the current file.
if editor_context.errors:
navi = ErrorNavigator(editor_context)
try:
data = navi.previous()
except IndexError:
return
else:
show_analysis_tooltip(data)