diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 71c3b06fb..ac25e64e6 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -690,10 +690,20 @@ def register_vars vars, tid end end + class NaiveString + attr_reader :str + def initialize str + @str = str + end + end + class ThreadClient - def value_inspect obj + + MAX_LENGTH = 180 + + def value_inspect obj, short: true # TODO: max length should be configuarable? - str = DEBUGGER__.safe_inspect obj, short: true, max_length: 4 * 1024 + str = DEBUGGER__.safe_inspect obj, short: short, max_length: MAX_LENGTH if str.encoding == Encoding::UTF_8 str.scrub @@ -805,8 +815,9 @@ def process_dap args when String vars = [ variable('#length', obj.length), - variable('#encoding', obj.encoding) + variable('#encoding', obj.encoding), ] + vars << variable('#dump', NaiveString.new(obj)) if obj.length > MAX_LENGTH when Class, Module vars = obj.instance_variables.map{|iv| variable(iv, obj.instance_variable_get(iv)) @@ -819,10 +830,12 @@ def process_dap args ] end - vars += M_INSTANCE_VARIABLES.bind_call(obj).map{|iv| - variable(iv, M_INSTANCE_VARIABLE_GET.bind_call(obj, iv)) - } - vars.unshift variable('#class', M_CLASS.bind_call(obj)) + unless NaiveString === obj + vars += M_INSTANCE_VARIABLES.bind_call(obj).map{|iv| + variable(iv, M_INSTANCE_VARIABLE_GET.bind_call(obj, iv)) + } + vars.unshift variable('#class', M_CLASS.bind_call(obj)) + end end end event! :dap_result, :variable, req, variables: (vars || []), tid: self.id @@ -940,11 +953,7 @@ def search_const b, expr end def evaluate_result r - v = variable nil, r - v.delete :name - v.delete :value - v[:result] = value_inspect(r) - v + variable nil, r end def type_name obj @@ -965,15 +974,31 @@ def variable_ name, obj, indexedVariables: 0, namedVariables: 0 vid = 0 end - ivnum = M_INSTANCE_VARIABLES.bind_call(obj).size + namedVariables += M_INSTANCE_VARIABLES.bind_call(obj).size - { name: name, - value: value_inspect(obj), - type: type_name(obj), - variablesReference: vid, - indexedVariables: indexedVariables, - namedVariables: namedVariables + ivnum, - } + if NaiveString === obj + str = obj.str.dump + vid = indexedVariables = namedVariables = 0 + else + str = value_inspect(obj) + end + + if name + { name: name, + value: str, + type: type_name(obj), + variablesReference: vid, + indexedVariables: indexedVariables, + namedVariables: namedVariables, + } + else + { result: str, + type: type_name(obj), + variablesReference: vid, + indexedVariables: indexedVariables, + namedVariables: namedVariables, + } + end end def variable name, obj @@ -983,7 +1008,7 @@ def variable name, obj when Hash variable_ name, obj, namedVariables: obj.size when String - variable_ name, obj, namedVariables: 3 # #to_str, #length, #encoding + variable_ name, obj, namedVariables: 3 # #length, #encoding, #to_str when Struct variable_ name, obj, namedVariables: obj.size when Class, Module