-
Notifications
You must be signed in to change notification settings - Fork 24
/
toggle_breakpoint_command.py
80 lines (63 loc) · 2.82 KB
/
toggle_breakpoint_command.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
import sublime, sublime_plugin
try:
from .debugger import *
except:
from debugger import *
class EraseAllCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.erase(edit, sublime.Region(0, self.view.size()))
class ReplaceContentCommand(sublime_plugin.TextCommand):
def run(self, edit, new_content, line_to_show, should_append):
sublime.set_timeout(lambda view=self.view, new_content=new_content, line_to_show=line_to_show, should_append=should_append: ViewHelper.replace_content(view, new_content, line_to_show, should_append), 0)
class ToggleBreakpointCommand(sublime_plugin.TextCommand):
def run(self, edit, mode, **args):
if mode == "clear_all":
for view in self.view.window().views():
view.erase_regions("breakpoint")
DebuggerModel.BREAKPOINTS = []
self.view.window().run_command("debug", {"command" : "set_breakpoint"})
elif mode == "normal":
self.update_breakpoints()
elif mode == "conditional":
self.view.window().show_input_panel("Enter condition", '', lambda condition : self.update_breakpoints(condition), None, None)
elif mode == "refresh":
self.view.erase_regions("breakpoint")
self.update_regions(self.view.file_name(), [], "")
def update_breakpoints(self, condition=None):
self.view.erase_regions("breakpoint")
selected_lines = ViewHelper.get_lines(self.view, self.view.sel())
self.update_regions(self.view.file_name(), selected_lines, condition)
self.view.window().run_command("debug", {"command" : "set_breakpoint"})
def update_regions(self, selected_file, selcted_line_numbers, condition):
current_breakpoints = DebuggerModel.BREAKPOINTS
unchanged = []
unchanged_in_selected_file = []
added = []
for breakpoint in current_breakpoints:
was_found = False
for line_number in selcted_line_numbers:
if breakpoint.line_number-1 == line_number:
was_found = True
break
if not was_found and breakpoint.file_name == selected_file:
unchanged_in_selected_file += [breakpoint]
if not was_found :
unchanged += [breakpoint]
for line_number in selcted_line_numbers:
was_found = False
for breakpoint in current_breakpoints:
if breakpoint.line_number-1 == line_number:
was_found = True
break
if not was_found:
added += [self.create_breakpoint(line_number, condition)]
self.view.add_regions("breakpoint", self.to_regions(added+unchanged_in_selected_file), "string", "circle", sublime.PERSISTENT)
DebuggerModel.BREAKPOINTS = added+unchanged
def create_breakpoint(self, line_number, condition):
return Breakpoint(self.view.file_name(), line_number+1, condition)
def create_region(self, breakpoint):
point = self.view.text_point(breakpoint.line_number-1, 0)
region = sublime.Region(point, point)
return region
def to_regions(self, breakpoints):
return [self.create_region(breakpoint) for breakpoint in breakpoints]