Skip to content

Commit 17f8329

Browse files
committed
support for inline debugger rendering
1 parent 036cde8 commit 17f8329

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,30 @@ def print_variable(name, value, kind)
170170
end
171171
end
172172
value_str = "[Binary Data]" if (value_str.respond_to?('is_binary_data?') && value_str.is_binary_data?)
173-
print("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
174-
CGI.escapeHTML(name), kind, CGI.escapeHTML(value_str), value.class,
173+
compact_value_str = build_compact_name(value_str, value)
174+
print("<variable name=\"%s\" compactValue=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
175+
CGI.escapeHTML(name), CGI.escapeHTML(compact_value_str), kind, CGI.escapeHTML(value_str), value.class,
175176
has_children, value.respond_to?(:object_id) ? value.object_id : value.id)
176177
print("<value><![CDATA[%s]]></value>", CGI.escapeHTML(value_str))
177178
print('</variable>')
178179
end
180+
181+
def build_compact_name(value_str, value)
182+
compact = value_str
183+
if value.is_a?(Array)
184+
slice = value[0..10]
185+
compact = slice.inspect
186+
if (value.size != slice.size)
187+
compact = compact[0..compact.size-2] + ", ...]"
188+
end
189+
end
190+
if value.is_a?(Hash)
191+
slice = value.sort_by { |k,v| k }[0..5]
192+
compact = slice.map {|kv| "#{kv[0]}: #{kv[1]}"}.join(", ")
193+
compact = "{" + compact + (slice.size != value.size ? ", ..." : "") + "}"
194+
end
195+
compact
196+
end
179197

180198
def print_breakpoints(breakpoints)
181199
print_element 'breakpoints' do

0 commit comments

Comments
 (0)