Skip to content

DAP: change result chars: 4096 -> 180 #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down