forked from quarnster/SublimeClang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrormarkers.py
185 lines (149 loc) · 5.68 KB
/
errormarkers.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import sublime
import sublime_plugin
from collections import defaultdict
from common import get_setting
ERRORS = {}
WARNINGS = {}
ERROR = "error"
WARNING = "warning"
clang_view = None
class ClangNext(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
fn = v.file_name()
line, column = v.rowcol(v.sel()[0].a)
gotoline = -1
if fn in ERRORS:
for errLine in ERRORS[fn]:
if errLine > line:
gotoline = errLine
break
if fn in WARNINGS:
for warnLine in WARNINGS[fn]:
if warnLine > line:
if gotoline == -1 or warnLine < gotoline:
gotoline = warnLine
break
if gotoline != -1:
v.window().open_file("%s:%d" % (fn, gotoline + 1), sublime.ENCODED_POSITION)
else:
sublime.status_message("No more errors or warnings!")
class ClangPrevious(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
fn = v.file_name()
line, column = v.rowcol(v.sel()[0].a)
gotoline = -1
if fn in ERRORS:
for errLine in ERRORS[fn]:
if errLine < line:
gotoline = errLine
if fn in WARNINGS:
for warnLine in WARNINGS[fn]:
if warnLine < line:
if gotoline == -1 or warnLine > gotoline:
gotoline = warnLine
if gotoline != -1:
v.window().open_file("%s:%d" % (fn, gotoline + 1), sublime.ENCODED_POSITION)
else:
sublime.status_message("No more errors or warnings!")
# Apparently get_output_panel clears the output view so we'll have
# to do this for now.
# See http://www.sublimetext.com/forum/viewtopic.php?f=6&t=2044
def set_clang_view(view):
global clang_view
clang_view = view
def highlight_panel_row():
if clang_view is None:
return
v = clang_view
view = sublime.active_window().active_view()
row, col = view.rowcol(view.sel()[0].a)
str = "%s:%d" % (view.file_name(), (row + 1))
r = v.find(str.replace('\\','\\\\'), 0)
panel_marker = get_setting("marker_output_panel_scope", "invalid")
if r == None:
v.erase_regions('highlightText')
else:
regions = [v.full_line(r)]
v.add_regions('highlightText', regions, panel_marker, 'dot', sublime.DRAW_OUTLINED)
def clear_error_marks():
global ERRORS, WARNINGS
listdict = lambda: defaultdict(list)
ERRORS = defaultdict(listdict)
WARNINGS = defaultdict(listdict)
def add_error_mark(severity, filename, line, message):
if severity.lower() == ERROR:
ERRORS[filename][line].append(message)
else:
WARNINGS[filename][line].append(message)
def show_error_marks(view):
'''Adds error marks to view.'''
erase_error_marks(view)
if not get_setting("show_visual_error_marks", True):
return
fill_outlines = False
gutter_mark = 'dot'
outlines = {'warning': [], 'illegal': []}
fn = view.file_name()
markers = {'warning': get_setting("marker_warning_scope", "comment"),
'illegal': get_setting("marker_error_scope", "invalid")
}
for line in ERRORS[fn].keys():
outlines['illegal'].append(view.full_line(view.text_point(line, 0)))
for line in WARNINGS[fn].keys():
outlines['warning'].append(view.full_line(view.text_point(line, 0)))
for lint_type in outlines:
if outlines[lint_type]:
args = [
'sublimeclang-outlines-{0}'.format(lint_type),
outlines[lint_type],
markers[lint_type],
gutter_mark
]
if not fill_outlines:
args.append(sublime.DRAW_OUTLINED)
view.add_regions(*args)
def erase_error_marks(view):
'''erase all error marks from view'''
view.erase_regions('sublimeclang-outlines-illegal')
view.erase_regions('sublimeclang-outlines-warning')
def last_selected_lineno(view):
return view.rowcol(view.sel()[0].end())[0]
def update_statusbar(view):
fn = view.file_name()
lineno = last_selected_lineno(view)
if fn in ERRORS and lineno in ERRORS[fn]:
view.set_status('SublimeClang_line', "Error: %s" % '; '.join(ERRORS[fn][lineno]))
elif fn in WARNINGS and lineno in WARNINGS[fn]:
view.set_status('SublimeClang_line', "Warning: %s" % '; '.join(WARNINGS[fn][lineno]))
else:
view.erase_status('SublimeClang_line')
class SublimeClangStatusbarUpdater(sublime_plugin.EventListener):
''' This EventListener will show the error messages for the current
line in the statusbar when the current line changes.
'''
def __init__(self):
super(SublimeClangStatusbarUpdater, self).__init__()
self.lastSelectedLineNo = -1
def is_enabled(self):
return True
def on_selection_modified(self, view):
if view.is_scratch():
return
# We only display errors in the status bar for the last line in the current selection.
# If that line number has not changed, there is no point in updating the status bar.
lastSelectedLineNo = last_selected_lineno(view)
if lastSelectedLineNo != self.lastSelectedLineNo:
self.lastSelectedLineNo = lastSelectedLineNo
update_statusbar(view)
highlight_panel_row()
def has_errors(self, view):
fn = view.file_name()
return fn in ERRORS or fn in WARNINGS
def on_activated(self, view):
if self.has_errors(view):
show_error_marks(view)
def on_load(self, view):
if self.has_errors(view):
show_error_marks(view)