byebug-dap 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3396f670f640d236adac1e58a6dd95af568925af57e9215262a0c10cd870d8df
4
- data.tar.gz: 516cc5caca246d9a2764c1cc7ec72b5e1ed2ce27bfcca04a9c7ce1413ce720c3
3
+ metadata.gz: 9695c31c89057519d92567d4b14faf182a108aeaad4994d92104733c966f1e32
4
+ data.tar.gz: d030b0a78edd8010d05f3a8af5e6adbc88ab553671f429babdc1f14390a222c1
5
5
  SHA512:
6
- metadata.gz: cc4611e07bc8c7738335c1a27340849ddb59a0728ce880926e99753d5168cd1f03f8e6197ba375fe074d852eaa502fb824e2555f39c76195ca301e9b4100926b
7
- data.tar.gz: c6af798756bb6d6ab71089f365b5cc869dd1c0fde932960f1b450c198439c4bb7be0ff385a22ebc9bcc486ff5465ee937bba9836ef367857c88dd9d8f0660d15
6
+ metadata.gz: e37dd536e602234f326c4d86b179046f1896fc8913979bbe193646a0387a829975abe6f4e7cad1d42d1615fff02436242d7caeaff030e34ec1472c82547e9cdc
7
+ data.tar.gz: f9efa4e3ca7cec53cd8c2b9dc89212640006ac1ffd841b753a72bbb3540a842fa7622ae010c55d6fee005d631e6bd4d15b36108517a22a0935465ed564a629cf
@@ -0,0 +1,4 @@
1
+ # Byebug Debug Adapter Protocol
2
+
3
+ This gem adds [Debug Adapter
4
+ Protocol](https://microsoft.github.io/debug-adapter-protocol) support to Byebug.
@@ -11,34 +11,26 @@ module Byebug
11
11
  end
12
12
 
13
13
  def run
14
- @trace.enable
15
-
16
14
  loop do
17
15
  @request = @interface.receive
18
16
  process_command @request
19
-
20
- rescue InvalidRequestArgumentError => e
21
- handle_error e
22
-
23
- rescue CommandProcessor::TimeoutError => e
24
- respond! success: false, message: "Debugger on thread ##{e.context.thnum} is not responding"
25
17
  end
26
18
 
27
19
  rescue IOError, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNABORTED, DisconnectError
28
20
  STDERR.puts "\nClient disconnected"
29
21
 
30
- rescue StandardError => e
31
- STDERR.puts "\n! #{e.message} (#{e.class})", *e.backtrace
32
-
33
22
  ensure
34
23
  Byebug.mode = :off
35
24
  Byebug.stop
36
25
  @interface.socket.close
26
+ @trace.disable
37
27
  end
38
28
 
39
29
  private
40
30
 
41
31
  def process_trace(trace)
32
+ return unless Byebug.started?
33
+
42
34
  ctx = Byebug.contexts.find { |c| c.thread == Thread.current }
43
35
 
44
36
  case trace.event
@@ -47,10 +39,9 @@ module Byebug
47
39
  when :thread_end
48
40
  @interface.event! 'thread', reason: 'exited', threadId: ctx.thnum
49
41
  end
50
- end
51
42
 
52
- def running!
53
- raise InvalidRequestArgumentError.new(:not_running, nil) unless Byebug.started?
43
+ rescue IOError, Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNABORTED
44
+ # client disconnected, ignore error
54
45
  end
55
46
 
56
47
  def process_command(request)
@@ -83,6 +74,7 @@ module Byebug
83
74
 
84
75
  Byebug.mode = :attached
85
76
  Byebug.start
77
+ @trace.enable
86
78
 
87
79
  @signal_start.call(:attach) if @signal_start
88
80
 
@@ -95,6 +87,7 @@ module Byebug
95
87
  unless request.arguments.noDebug
96
88
  Byebug.mode = :launched
97
89
  Byebug.start
90
+ @trace.enable
98
91
  end
99
92
 
100
93
  @signal_start.call(:launch) if @signal_start
@@ -109,7 +102,10 @@ module Byebug
109
102
  return
110
103
  end
111
104
 
112
- running!
105
+ unless Byebug.started?
106
+ respond! success: false, message: "Debugger is not running"
107
+ return
108
+ end
113
109
 
114
110
  case request.command
115
111
  when 'pause', 'next', 'stepIn', 'stepOut', 'continue'
@@ -179,6 +175,12 @@ module Byebug
179
175
  # "To clear all breakpoint for a source, specify an empty array.
180
176
  # "When a breakpoint is hit, a ‘stopped’ event (with reason ‘breakpoint’) is generated.
181
177
 
178
+ unless File.exist?(request.arguments.source.path)
179
+ # file doesn't exist, no breakpoints set
180
+ respond! body: ::DAP::SetBreakpointsResponseBody.new(breakpoints: [])
181
+ return
182
+ end
183
+
182
184
  path = File.realpath(request.arguments.source.path)
183
185
  ::Byebug.breakpoints.each { |bp| ::Byebug::Breakpoint.remove(bp.id) if bp.source == path }
184
186
 
@@ -199,42 +201,46 @@ module Byebug
199
201
  else
200
202
  respond! success: false, message: 'Invalid command'
201
203
  end
202
- end
203
-
204
- def respond!(body = {}, success: true, message: 'Success', **values)
205
- # TODO make body default to nil?
206
- @interface << ::DAP::Response.new(
207
- request_seq: @request.seq,
208
- command: @request.command,
209
- success: success,
210
- message: message,
211
- body: body,
212
- **values)
213
- end
214
-
215
- def handle_error(ex)
216
- case ex.error
217
- when :not_running
218
- respond! success: false, message: "Debugger is not running"
219
204
 
205
+ rescue InvalidRequestArgumentError => e
206
+ case e.error
220
207
  when :missing_argument
221
- respond! success: false, message: "Missing #{ex.scope}"
208
+ respond! success: false, message: "Missing #{e.scope}"
222
209
 
223
210
  when :missing_entry
224
- respond! success: false, message: "Invalid #{ex.scope} #{ex.value}"
211
+ respond! success: false, message: "Invalid #{e.scope} #{e.value}"
225
212
 
226
213
  when :missing_thread
227
- respond! success: false, message: "Cannot locate thread ##{ex.value}"
214
+ respond! success: false, message: "Cannot locate thread ##{e.value}"
228
215
 
229
216
  when :missing_frame
230
- respond! success: false, message: "Cannot locate frame ##{ex.value}"
217
+ respond! success: false, message: "Cannot locate frame ##{e.value}"
231
218
 
232
219
  when :invalid_entry
233
- respond! success: false, message: "Error resolving #{ex.scope}: #{ex.value}"
220
+ respond! success: false, message: "Error resolving #{e.scope}: #{e.value}"
234
221
 
235
222
  else
236
- raise "Unknown internal error: #{err}"
223
+ respond! success: false, message: "An internal error occured"
224
+ STDERR.puts "#{e.message} (#{e.class})", *e.backtrace
237
225
  end
226
+
227
+ rescue CommandProcessor::TimeoutError => e
228
+ respond! success: false, message: "Debugger on thread ##{e.context.thnum} is not responding"
229
+
230
+ rescue StandardError => e
231
+ respond! success: false, message: "An internal error occured"
232
+ STDERR.puts "#{e.message} (#{e.class})", *e.backtrace
233
+ end
234
+
235
+ def respond!(body = {}, success: true, message: 'Success', **values)
236
+ # TODO make body default to nil?
237
+ @interface << ::DAP::Response.new(
238
+ request_seq: @request.seq,
239
+ command: @request.command,
240
+ success: success,
241
+ message: message,
242
+ body: body,
243
+ **values)
238
244
  end
239
245
  end
240
246
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byebug-dap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Reesor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - AUTHORS
49
49
  - LICENSE
50
+ - README.md
50
51
  - bin/byebug-dap
51
52
  - lib/byebug/dap.rb
52
53
  - lib/byebug/dap/channel.rb