-
Notifications
You must be signed in to change notification settings - Fork 7
/
listener.py
62 lines (51 loc) · 1.55 KB
/
listener.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
import os
import re
import sublime
import sublime_plugin
from const import *
class ClosureLinterEventListener(sublime_plugin.EventListener):
"""jslint event"""
disabled = False
def __init__(self):
self.previous_resion = None
self.file_view = None
def on_deactivated(self, view):
if view.name() != RESULT_VIEW_NAME:
return
self.previous_resion = None
if self.file_view:
self.file_view.erase_regions(RESULT_VIEW_NAME)
def on_selection_modified(self, view):
if ClosureLinterEventListener.disabled:
return
if view.name() != RESULT_VIEW_NAME:
return
region = view.line(view.sel()[0])
# make sure call once.
if self.previous_resion == region:
return
self.previous_resion = region
# extract line from jslint result.
m = re.match('^Line (\d+), E:(\d+):', view.substr(region))
if m == None:
return
line = int(m.group(1))
col = int(m.group(2))
# hightligh view line.
view.add_regions(RESULT_VIEW_NAME, [region], "comment")
# find the file view.
file_path = view.settings().get('file_path')
window = sublime.active_window()
file_view = None
for v in window.views():
if v.file_name() == file_path:
file_view = v
break
if file_view == None:
return
self.file_view = file_view
window.focus_view(file_view)
file_view.run_command("goto_line", {"line": line})
file_region = file_view.line(file_view.sel()[0])
# highlight file_view line
file_view.add_regions(RESULT_VIEW_NAME, [file_region], "string")