Class: DebugAdapterProtocolTunnel::DAPConnection
- Inherits:
-
Object
- Object
- DebugAdapterProtocolTunnel::DAPConnection
- Defined in:
- lib/debuggers.rb
Instance Method Summary collapse
- #_write(message) ⇒ Object
- #close ⇒ Object
-
#initialize(connection, plugins) ⇒ DAPConnection
constructor
A new instance of DAPConnection.
- #run ⇒ Object
- #run2 ⇒ Object
Constructor Details
#initialize(connection, plugins) ⇒ DAPConnection
Returns a new instance of DAPConnection.
180 181 182 183 184 185 186 187 |
# File 'lib/debuggers.rb', line 180 def initialize(connection, plugins) @connection = connection @plugins = plugins @running = false @next_seq = 1 @write_mutex = Mutex.new @_dump_messages = (ENV['HAPLO_DAP_DEBUG'] == '1') end |
Instance Method Details
#_write(message) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/debuggers.rb', line 250 def _write() @write_mutex.synchronize do m = {'seq' => @next_seq} @next_seq += 1 m.merge!() puts "DAP WRITE: #{JSON.pretty_generate(m)}\n" if @_dump_messages msg_json = JSON.generate(m) @connection.write("Content-Length: #{msg_json.bytesize}\r\n\r\n") @connection.write(msg_json) end end |
#close ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/debuggers.rb', line 189 def close begin @connection.close rescue => e # ignore any errors end end |
#run ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/debuggers.rb', line 197 def run begin run2 rescue => e puts "DEBUGGER: Local connection closed" end self.close end |
#run2 ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/debuggers.rb', line 206 def run2 @running = true have_initialized = false while @running header = @connection.readline blank = @connection.readline if header =~ /\Acontent-length:\s+(\d+)\r\n\z/i && blank == "\r\n" body = @connection.read($1.to_i) = JSON.parse(body) puts "DAP READ: #{JSON.pretty_generate()}\n" if @_dump_messages unless have_initialized if ['type'] == 'request' && ['command'] == 'initialize' puts "DEBUGGER: Local connection from #{['arguments']['clientName']} (#{['arguments']['clientID']})\nDEBUGGER: Starting remote debugger..." plugin_locations = {} @plugins.each { |p| plugin_locations[p.name] = p.plugin_dir } start_response = PluginTool.post("/api/development-plugin-loader/debugger-dap-start", { :plugin_locations => JSON.generate(plugin_locations) }) unless start_response =~ /\ATOKEN: (.+)\z/ raise "Remote debugger failed to start" end @token = $1 puts "DEBUGGER: Remote debugger started." have_initialized = true else raise "Expected initialize message after DAP connection" end end # TODO: Send messages in another thread, so that they can be batched together = PluginTool.post_with_json_response("/api/development-plugin-loader/debugger-dap-messages", { :token => @token, :messages => JSON.generate([]) }) if ['error'] puts "DEBUGGER: Server responded with error: #{['error']}" else ['messages'].each do |response| _write(response) if response end end end end end |