Skip to content

Commit 1fae8cf

Browse files
committed
Compact name should be compact
If string representation of a value is too long let's cut it to make compact value
1 parent a96a0af commit 1fae8cf

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def print_variable(name, value, kind)
173173
value_str = handle_binary_data(value_str)
174174
escaped_value_str = CGI.escapeHTML(value_str)
175175
print("<variable name=\"%s\" %s kind=\"%s\" %s type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
176-
CGI.escapeHTML(name), build_compact_value_attr(value), kind, build_value_attr(escaped_value_str), value.class,
176+
CGI.escapeHTML(name), build_compact_value_attr(value, value_str), kind,
177+
build_value_attr(escaped_value_str), value.class,
177178
has_children, value.respond_to?(:object_id) ? value.object_id : value.id)
178179
print("<value><![CDATA[%s]]></value>", escaped_value_str) if Debugger.rm_protocol_extensions
179180
print('</variable>')
@@ -341,15 +342,21 @@ def current_thread_attr(context)
341342
end
342343
end
343344

344-
def build_compact_name(value)
345+
def build_compact_name(value, value_str)
345346
return compact_array_str(value) if value.is_a?(Array)
346347
return compact_hash_str(value) if value.is_a?(Hash)
348+
return value_str[0..max_compact_name_size - 3] + '...' if value_str.size > max_compact_name_size
347349
nil
348350
rescue ::Exception => e
349351
print_debug(e)
350352
nil
351353
end
352354

355+
def max_compact_name_size
356+
# todo: do we want to configure it?
357+
50
358+
end
359+
353360
def compact_array_str(value)
354361
slice = value[0..10]
355362
compact = slice.inspect
@@ -365,8 +372,8 @@ def compact_hash_str(value)
365372
"{" + compact + (slice.size != value.size ? ", ..." : "") + "}"
366373
end
367374

368-
def build_compact_value_attr(value)
369-
compact_value_str = build_compact_name(value)
375+
def build_compact_value_attr(value, value_str)
376+
compact_value_str = build_compact_name(value, value_str)
370377
compact_value_str.nil? ? '' : "compactValue=\"#{CGI.escapeHTML(compact_value_str)}\""
371378
end
372379

0 commit comments

Comments
 (0)