Commit a8e7495a8c5ff18780129d9e13ef26faf2bb8563

extracted breakpoint manipulation commands out to BreakpointCommander module

Commit diff

Commands/Debug - Delete All Breakpoints.tmCommand

 
1111
1212d = RubyAMP::RemoteDebugger.new
1313
14count_breakpoints = d.evaluate("Debugger.breakpoints.length", :control)
14count_breakpoints = d.breakpoint.list.length
1515if count_breakpoints == 0
1616 puts "There are no breakpoints set"
1717 exit
1818end
1919
20d.evaluate("Debugger.breakpoints.map{ |b| b.id }.each { |b_id| Debugger.remove_breakpoint(b_id) }", :control)
20count_deleted = d.breakpoint.delete_all
2121
22new_count_breakpoints = d.evaluate("Debugger.breakpoints.length", :control)
23if new_count_breakpoints == 0
24 puts "Deleted all #{count_breakpoints} breakpoint(s)"
22if count_deleted == count_breakpoints
23 puts "Deleted all #{count_deleted} breakpoint(s)"
2524else
2625 puts "Error deleting breakpoints."
2726end</string>
toggle raw diff

Commands/Debug - Set Breakpoint at Current Line.tmCommand

 
1212d = RubyAMP::RemoteDebugger.new
1313exit unless d.connected?
1414
15result = d.evaluate &lt;&lt;-EOF, :control
16 bp = Debugger.add_breakpoint #{ENV['TM_FILEPATH'].to_s.inspect}, #{ENV['TM_LINE_NUMBER']}
17 if bp
18 "Set breakpoint at \#{bp.source}:\#{bp.pos}"
19 else
20 "Failed to set breakpoint."
21 end
22EOF
15source = ENV['TM_FILEPATH']
16line = ENV['TM_LINE_NUMBER']
2317
24puts result
25</string>
18if d.breakpoint.add(source, line)
19 puts "Set breakpoint at #{source}:#{line}"
20else
21 puts "Failed to set breakpoint."
22end</string>
2623 <key>fallbackInput</key>
2724 <string>line</string>
2825 <key>input</key>
toggle raw diff

Commands/Debug - Show Breakpoints Menu.tmCommand

 
1616require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
1717
1818d = RubyAMP::RemoteDebugger.new
19breakpoints = d.evaluate("Debugger.breakpoints.map{|b| {:source =&gt; b.source, :line =&gt; b.pos} }", :control)
19breakpoints = d.breakpoint.list
2020
2121if breakpoints.empty?
2222 puts "No breakpoints"
2323 exit_show_tool_tip
2424end
2525
26b_index = TextMate::UI.menu(breakpoints.map{|b| "#{b[:source]}:#{b[:line]}"})
26b_index = TextMate::UI.menu(breakpoints.map{|b| "#{b.source}:#{b.line}"})
2727
2828exit_discard if b_index.nil?
2929
3030breakpoint = breakpoints[b_index]
31tm_open(breakpoint[:source], :line =&gt; breakpoint[:line])</string>
31tm_open(breakpoint.source, :line =&gt; breakpoint.line)</string>
3232 <key>input</key>
3333 <string>none</string>
3434 <key>keyEquivalent</key>
toggle raw diff

Support/lib/ruby_amp/remote_debugger.rb

 
116116 raw_evaluate(expression)
117117 end
118118 end
119
120 AUTO_LOAD = {
121 :BreakpointCommander => 'breakpoint_commander.rb',
122 :CommanderBase => 'commander_base.rb',
123 }
124
125 def self.const_missing(name)
126 @looked_for ||= {}
127 raise "Class not found: #{name}" if @looked_for[name]
128
129 return super unless AUTO_LOAD[name]
130 @looked_for[name] = true
131
132 require File.join(RUBYAMP_ROOT, "remote_debugger", AUTO_LOAD[name])
133 const_get(name)
134 end
135
136 def breakpoint
137 @breakpoint ||= BreakpointCommander.new(self)
138 end
119139 end
120140end
121141
toggle raw diff

Support/lib/ruby_amp/remote_debugger/breakpoint_commander.rb

 
1module RubyAMP
2 class RemoteDebugger
3 class BreakpointCommander < CommanderBase
4 def list
5 base.evaluate("Debugger.breakpoints.map{|b| {:id => b.id, :source => b.source, :line => b.pos} }", :control).map do |bp_options|
6 Breakpoint.new(base, self, bp_options)
7 end
8 end
9
10 def delete_all
11 base.evaluate <<-EOF, :control
12 breakpoint_ids = Debugger.breakpoints.map { |b| b.id }
13 begin
14 breakpoint_ids.each { |b_id| Debugger.remove_breakpoint(b_id) }
15 breakpoint_ids.length
16 rescue
17 0
18 end
19 EOF
20 end
21
22 def add(source, line)
23 base.evaluate <<-EOF, :control
24 bp = Debugger.add_breakpoint #{ENV['TM_FILEPATH'].to_s.inspect}, #{ENV['TM_LINE_NUMBER']}
25 bp ? true : false
26 EOF
27 end
28 end
29
30 class Breakpoint
31 attr_accessor :source, :line, :id
32
33 def initialize(base, parent, options = {})
34 self.id = options[:id]
35 self.source = options[:source]
36 self.line = options[:line]
37 end
38 end
39 end
40end
toggle raw diff

Support/lib/ruby_amp/remote_debugger/commander_base.rb

 
1module RubyAMP
2 class RemoteDebugger
3 class CommanderBase
4 attr_accessor :base
5 def initialize(base)
6 @base = base
7 end
8 end
9 end
10end
toggle raw diff