debugvisualizer 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/debugvisualizer/array.rb +57 -0
- data/lib/debugvisualizer/nokogiri.rb +23 -23
- data/lib/debugvisualizer/rexml.rb +21 -22
- data/lib/debugvisualizer/rubyvm_ast.rb +46 -0
- data/lib/debugvisualizer/version.rb +1 -1
- data/lib/debugvisualizer.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ab9dc5705e726901b85ca46a4120af87973378e12ea49ba7d46decd36f6361
|
4
|
+
data.tar.gz: af3ca7d8fac6e411cbabdd97dd3ebbaea2e288e5d26e4660702c945155cfd86a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a3bc2c7a680f5c705d272dcf0c22ac837b73fed76259161653a18569a8f29ae8c55b53afbf135c4d7fdb30dcbe785f59e76af599ece93b291b578f1a31446c3
|
7
|
+
data.tar.gz: d4cdf558161675cdedadc7a09479b3a4d62170c28788c509e9ad8d83941e51b7d37007d74f73cf679b0fd380eff609ae59dfec93aa6fda8f4f74f9a450711dc7
|
@@ -70,4 +70,61 @@ module DebugVisualizer
|
|
70
70
|
}
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
def self.get_edges(nodes)
|
75
|
+
return [] if nodes.size < 3
|
76
|
+
|
77
|
+
edges = []
|
78
|
+
prev_id = nodes.first[:id]
|
79
|
+
# Get elements except for `First element` and `Last element`
|
80
|
+
nodes[1..nodes.size - 2].each{|elem|
|
81
|
+
edges << {
|
82
|
+
from: prev_id,
|
83
|
+
to: elem[:id]
|
84
|
+
}
|
85
|
+
prev_id = elem[:id]
|
86
|
+
}
|
87
|
+
edges << {
|
88
|
+
from: nodes.last[:id],
|
89
|
+
to: prev_id,
|
90
|
+
color: 'orange'
|
91
|
+
}
|
92
|
+
edges
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.inspect obj
|
96
|
+
obj.inspect
|
97
|
+
rescue Exception => e
|
98
|
+
"failed to inspect: #{e.message}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.get_nodes array
|
102
|
+
nodes = []
|
103
|
+
nodes << {
|
104
|
+
id: rand.to_s,
|
105
|
+
label: 'First element',
|
106
|
+
color: 'orange'
|
107
|
+
}
|
108
|
+
array.each{|elem| nodes << {id: rand.to_s, label: inspect(elem)}}
|
109
|
+
nodes << {
|
110
|
+
id: rand.to_s,
|
111
|
+
label: 'Last element',
|
112
|
+
color: 'orange'
|
113
|
+
}
|
114
|
+
nodes
|
115
|
+
end
|
116
|
+
|
117
|
+
DebugVisualizer.register(Array) do |data|
|
118
|
+
nodes = get_nodes(data)
|
119
|
+
{
|
120
|
+
id: "array_as_graph",
|
121
|
+
name: "Array As Graph",
|
122
|
+
priority: 90,
|
123
|
+
data: {
|
124
|
+
kind: { graph: true },
|
125
|
+
nodes: nodes,
|
126
|
+
edges: get_edges(nodes),
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
73
130
|
end
|
@@ -7,51 +7,51 @@ module DebugVisualizer
|
|
7
7
|
name: "Nokogiri As Tree",
|
8
8
|
data: {
|
9
9
|
kind: { tree: true },
|
10
|
-
root:
|
10
|
+
root: get_nokogiri_as_tree(data.children).last
|
11
11
|
}
|
12
12
|
}
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
16
|
+
def self.get_nokogiri_as_tree(elems)
|
17
17
|
result = []
|
18
18
|
elems.each{|elem|
|
19
|
-
|
19
|
+
items = [
|
20
|
+
{
|
21
|
+
text: elem.name,
|
22
|
+
emphasis: 'style1'
|
23
|
+
}
|
24
|
+
]
|
20
25
|
elem.attributes.each{|key, val|
|
21
|
-
items = []
|
22
26
|
items << {
|
23
|
-
text: "#{key}
|
24
|
-
emphasis: 'style2'
|
27
|
+
text: " #{key} =",
|
25
28
|
}
|
26
29
|
items << {
|
27
|
-
text: val.value,
|
30
|
+
text: "\"#{val.value}\"",
|
28
31
|
emphasis: 'style2'
|
29
32
|
}
|
30
|
-
child << {
|
31
|
-
items: items,
|
32
|
-
children: []
|
33
|
-
}
|
34
33
|
}
|
34
|
+
child = []
|
35
35
|
if elem.children
|
36
|
-
child
|
36
|
+
child = get_nokogiri_as_tree(elem.children)
|
37
37
|
end
|
38
38
|
next if elem.name == 'text'
|
39
39
|
|
40
|
-
tree = {
|
41
|
-
items: [
|
42
|
-
{
|
43
|
-
text: elem.name,
|
44
|
-
emphasis: 'style1'
|
45
|
-
}
|
46
|
-
],
|
47
|
-
children: child
|
48
|
-
}
|
49
40
|
text = elem.xpath('text()').text
|
50
41
|
if text && text.strip != ""
|
51
|
-
|
52
|
-
|
42
|
+
child << {
|
43
|
+
items: [
|
44
|
+
text: text.strip,
|
45
|
+
emphasis: 'style3'
|
46
|
+
],
|
47
|
+
children: []
|
53
48
|
}
|
54
49
|
end
|
50
|
+
|
51
|
+
tree = {
|
52
|
+
items: items,
|
53
|
+
children: child
|
54
|
+
}
|
55
55
|
result << tree
|
56
56
|
}
|
57
57
|
result
|
@@ -6,48 +6,47 @@ module DebugVisualizer
|
|
6
6
|
name: "REXML As Tree",
|
7
7
|
data: {
|
8
8
|
kind: { tree: true },
|
9
|
-
root:
|
9
|
+
root: get_rexml_as_tree(data)[0]
|
10
10
|
}
|
11
11
|
}
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.get_rexml_as_tree(elems)
|
16
16
|
result = []
|
17
17
|
elems.each_element{|elem|
|
18
|
-
|
18
|
+
items = [
|
19
|
+
{
|
20
|
+
text: elem.name,
|
21
|
+
emphasis: 'style1'
|
22
|
+
}
|
23
|
+
]
|
19
24
|
elem.attributes.each_attribute{|atr|
|
20
|
-
items = []
|
21
25
|
items << {
|
22
|
-
text: "#{atr.name}
|
23
|
-
emphasis: 'style2'
|
26
|
+
text: " #{atr.name} =",
|
24
27
|
}
|
25
28
|
items << {
|
26
29
|
text: atr.value,
|
27
30
|
emphasis: 'style2'
|
28
31
|
}
|
29
|
-
children << {
|
30
|
-
items: items,
|
31
|
-
children: []
|
32
|
-
}
|
33
32
|
}
|
33
|
+
children = []
|
34
34
|
if elem.has_elements?
|
35
|
-
children
|
35
|
+
children = get_rexml_as_tree(elem)
|
36
36
|
end
|
37
|
-
tree = {
|
38
|
-
items: [
|
39
|
-
{
|
40
|
-
text: elem.name,
|
41
|
-
emphasis: 'style1'
|
42
|
-
}
|
43
|
-
],
|
44
|
-
children: children
|
45
|
-
}
|
46
37
|
if elem.text && elem.text.strip != ""
|
47
|
-
|
48
|
-
|
38
|
+
children << {
|
39
|
+
items: [
|
40
|
+
text: elem.text.strip,
|
41
|
+
emphasis: 'style3'
|
42
|
+
],
|
43
|
+
children: []
|
49
44
|
}
|
50
45
|
end
|
46
|
+
tree = {
|
47
|
+
items: items,
|
48
|
+
children: children
|
49
|
+
}
|
51
50
|
result << tree
|
52
51
|
}
|
53
52
|
result
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module DebugVisualizer
|
2
|
+
DebugVisualizer.register do |data|
|
3
|
+
if data.kind_of? ::RubyVM::AbstractSyntaxTree::Node
|
4
|
+
{
|
5
|
+
id: "rubyvm_ast_visualizer",
|
6
|
+
name: "RubyVM As Tree",
|
7
|
+
data: {
|
8
|
+
kind: { tree: true },
|
9
|
+
root: get_tree(data).last
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.inspect obj
|
16
|
+
obj.inspect
|
17
|
+
rescue Exception => e
|
18
|
+
"failed to inspect: #{e.message}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_tree data
|
22
|
+
result = []
|
23
|
+
data.children.each{|child|
|
24
|
+
next if child.nil?
|
25
|
+
|
26
|
+
node = {
|
27
|
+
items: [],
|
28
|
+
children: []
|
29
|
+
}
|
30
|
+
if child.kind_of? ::RubyVM::AbstractSyntaxTree::Node
|
31
|
+
node[:items] << {
|
32
|
+
text: child.type,
|
33
|
+
emphasis: 'style1'
|
34
|
+
}
|
35
|
+
node[:children].push *get_tree(child)
|
36
|
+
else
|
37
|
+
node[:items] << {
|
38
|
+
text: inspect(child),
|
39
|
+
emphasis: 'style2'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
result << node
|
43
|
+
}
|
44
|
+
result
|
45
|
+
end
|
46
|
+
end
|
data/lib/debugvisualizer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debugvisualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoto Ono
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: debugvisualizer generates JSON based on VS Code Debug Visualizer protocol
|
14
14
|
email:
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/debugvisualizer/hash.rb
|
29
29
|
- lib/debugvisualizer/nokogiri.rb
|
30
30
|
- lib/debugvisualizer/rexml.rb
|
31
|
+
- lib/debugvisualizer/rubyvm_ast.rb
|
31
32
|
- lib/debugvisualizer/string_diff.rb
|
32
33
|
- lib/debugvisualizer/to_string.rb
|
33
34
|
- lib/debugvisualizer/version.rb
|