Module: Byebug::DAP::ValueHelpers Private
- Included in:
- Command::Evaluate, Command::Variables
- Defined in:
- lib/byebug/dap/helpers/value_helpers.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Methods to prepare values for DAP responses.
Instance Method Summary collapse
-
#prepare_value(val) ⇒ Object
private
Safely inspect a value and retrieve its class name, class and instance variables, and indexed members.
-
#prepare_value_response(thnum, frnum, kind, name: nil) { ... } ⇒ Object
private
Prepare a Variable or EvaluateResponseBody for a calculated value.
Instance Method Details
#prepare_value(val) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Safely inspect a value and retrieve its class name, class and instance variables, and indexed members. Scalar values do not have variables or members. Only arrays and hashes have members.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/byebug/dap/helpers/value_helpers.rb', line 9 def prepare_value(val) str = safe(val, :inspect) { safe(val, :to_s) { return yield } } cls = safe(val, :class) { nil } typ = safe(cls, :name) { safe(cls, :to_s) { nil } } scalar = safe(-> { Scalar === val }, :call) { true } return str, typ, [], [] if scalar named = safe(val, :instance_variables) { [] } || [] named += safe(val, :class_variables) { [] } || [] # named += safe(val, :constants) { [] } indexed = safe(-> { return (0...val.size).to_a if val.is_a?(Array) return val.keys if val.respond_to?(:keys) && val.respond_to?(:[]) [] }, :call) { [] } return str, typ, named, indexed end |
#prepare_value_response(thnum, frnum, kind, name: nil) { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare a Variable or EvaluateResponseBody for a calculated value. For global variables and evaluations, ‘thnum` and `frnum` should be 0. Local variables and evaluations are executed on the specified thread.
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 |
# File 'lib/byebug/dap/helpers/value_helpers.rb', line 39 def prepare_value_response(thnum, frnum, kind, name: nil, &block) err = nil raw = execute_on_thread(thnum, block) { |e| err = e; nil } if err.nil? value, type, named, indexed = prepare_value(raw) { |e| next exception_description(e), nil, [], [] } else type, named, indexed = nil, [], [] if err.is_a?(CommandProcessor::TimeoutError) name = err.context.thread.name value = "*Thread ##{err.context.thnum} #{name ? '(' + name + ')' : ''} unresponsive*" else value = exception_description(err) end end case kind when :variable klazz = Protocol::Variable args = { name: safe(name, :to_s) { safe(name, :inspect) { '???' } }, value: value, type: type } when :evaluate klazz = Protocol::EvaluateResponseBody args = { result: value, type: type } end if named.empty? && indexed.empty? args[:variablesReference] = 0 else args[:variablesReference] = @session.save_variables(thnum, frnum, kind, raw, named, indexed) args[:namedVariables] = named.size args[:indexedVariables] = indexed.size end klazz.new(args).validate! end |