pry-doc 0.13.2pre7 → 0.13.2
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/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb +58 -54
- data/lib/pry-doc/pry_ext/show_source_with_c_internals/code_fetcher.rb +10 -19
- data/lib/pry-doc/pry_ext/show_source_with_c_internals/etag_parser.rb +58 -0
- data/lib/pry-doc/version.rb +1 -1
- data/spec/pry-doc_spec.rb +3 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 103e744238b577ba5dd9be3e6f68d968d0a5d8389f0e644bcd47097db94615d3
|
4
|
+
data.tar.gz: 8a3648f1a0fc7cb95d681dc9d1b4448c9e368c2e51aae18b1c93b3f22f67b557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8600e1cc9e840f0b1e5506fd034dd9a176f89a854fd002da8f3e8dd9747742a31f7662ef16ecb2d4cfbbeb702b284749c9b14e2e1a08571fa3075fb3233e8531
|
7
|
+
data.tar.gz: '063338b70acd7313ce718f1314968aed4cc39e3e7f696803cac63a72db322898b19aecb4945a5dd48039ee27676c471f92ffbb5e8dd096c69c2e48c2659310eb'
|
@@ -8,72 +8,76 @@
|
|
8
8
|
# First line is the name of the file
|
9
9
|
# Following lines are the symbols followed by line number with char 127 as separator.
|
10
10
|
module Pry::CInternals
|
11
|
-
class
|
12
|
-
|
11
|
+
class ETagParser
|
12
|
+
class CFile
|
13
|
+
# Used to separate symbol from line number
|
14
|
+
SYMBOL_SEPARATOR = "\x7f"
|
15
|
+
ALTERNATIVE_SEPARATOR = "\x1"
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
ALTERNATIVE_SEPARATOR = "\x1"
|
17
|
+
attr_accessor :file_name
|
18
|
+
attr_reader :ruby_source_folder
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@lines = str.lines
|
24
|
-
@file_name = @lines.shift.split(",").first
|
25
|
-
end
|
20
|
+
def initialize(file_name: file_name, content: content, ruby_source_folder: nil)
|
21
|
+
@ruby_source_folder = ruby_source_folder
|
22
|
+
@content = content
|
23
|
+
@file_name = file_name
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
# Convert a C file to a map of symbols => SourceLocation that are found in that file
|
27
|
+
# e.g
|
28
|
+
# { "foo" => [SourceLocation], "bar" => [SourceLocation] }
|
29
|
+
def symbol_map
|
30
|
+
return @symbol_map if @symbol_map
|
31
|
+
@symbol_map = @content.each_with_object({}) do |v, h|
|
32
|
+
sep = v.include?(ALTERNATIVE_SEPARATOR) ? ALTERNATIVE_SEPARATOR : SYMBOL_SEPARATOR
|
33
|
+
symbol, line_number = v.split(sep)
|
34
|
+
next if symbol.strip =~ /^\w+$/ # these symbols are usually errors in etags
|
35
|
+
h[cleanup_symbol(symbol)] = [source_location_for(symbol, line_number)]
|
36
|
+
end
|
33
37
|
end
|
34
|
-
end
|
35
38
|
|
36
|
-
|
39
|
+
private
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def source_location_for(symbol, line_number)
|
42
|
+
SourceLocation.new(full_path_for(@file_name),
|
43
|
+
cleanup_linenumber(line_number), symbol_type_for(symbol.strip))
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def full_path_for(file_name)
|
47
|
+
if Pry::Platform.windows?
|
48
|
+
# windows etags already has the path expanded, wtf
|
49
|
+
file_name
|
50
|
+
else
|
51
|
+
File.join(ruby_source_folder, @file_name)
|
52
|
+
end
|
49
53
|
end
|
50
|
-
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
def symbol_type_for(symbol)
|
56
|
+
if symbol =~ /#\s*define/
|
57
|
+
:macro
|
58
|
+
elsif symbol =~ /\bstruct\b/
|
59
|
+
:struct
|
60
|
+
elsif symbol =~ /\benum\b/
|
61
|
+
:enum
|
62
|
+
elsif symbol.start_with?("}")
|
63
|
+
:typedef_struct
|
64
|
+
elsif symbol =~/^typedef.*;$/
|
65
|
+
:typedef_oneliner
|
66
|
+
elsif symbol =~ /\($/
|
67
|
+
:function
|
68
|
+
else
|
69
|
+
:unknown
|
70
|
+
end
|
67
71
|
end
|
68
|
-
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
def cleanup_symbol(symbol)
|
74
|
+
symbol = symbol.split.last
|
75
|
+
symbol.gsub(/\W/, '')
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
78
|
+
def cleanup_linenumber(line_number)
|
79
|
+
line_number.split.first.to_i
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require_relative 'c_file'
|
3
2
|
require_relative 'symbol_extractor'
|
3
|
+
require_relative 'etag_parser'
|
4
4
|
require_relative 'ruby_source_installer'
|
5
5
|
|
6
6
|
module Pry::CInternals
|
@@ -10,6 +10,7 @@ module Pry::CInternals
|
|
10
10
|
class << self
|
11
11
|
attr_accessor :ruby_source_folder
|
12
12
|
attr_accessor :ruby_source_installer
|
13
|
+
attr_accessor :symbol_map
|
13
14
|
end
|
14
15
|
|
15
16
|
# The Ruby version that corresponds to a downloadable release
|
@@ -73,26 +74,16 @@ module Pry::CInternals
|
|
73
74
|
line_number_style == :'base-one' ? 1 : line || 1
|
74
75
|
end
|
75
76
|
|
77
|
+
# Returns a hash that maps C symbols to an array of SourceLocations
|
78
|
+
# e.g: symbol_map["VALUE"] #=> [SourceLocation_1, SourceLocation_2]
|
79
|
+
# A SourceLocation is defined like this: Struct.new(:file, :line, :symbol_type)
|
80
|
+
# e.g file: "foo.c", line: 20, symbol_type: "function"
|
76
81
|
def self.symbol_map
|
77
|
-
@symbol_map
|
78
|
-
parse_tagfile
|
79
|
-
@c_files.each_with_object({}) do |v, h|
|
80
|
-
h.merge!(v.symbols) { |k, old_val, new_val| old_val + new_val }
|
81
|
-
end)
|
82
|
-
end
|
82
|
+
return @symbol_map if @symbol_map
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.tagfile
|
91
|
-
tags = File.join(ruby_source_folder, "TAGS")
|
92
|
-
if !File.exists?(tags)
|
93
|
-
ruby_source_installer.install
|
94
|
-
end
|
95
|
-
@tagfile ||= File.read(tags)
|
84
|
+
tags_path = File.join(ruby_source_folder, "TAGS")
|
85
|
+
ruby_source_installer.install unless File.exists?(tags_path)
|
86
|
+
@symbol_map = ETagParser.symbol_map_for(tags_path, ruby_source_folder)
|
96
87
|
end
|
97
88
|
end
|
98
89
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'c_file'
|
2
|
+
|
3
|
+
module Pry::CInternals
|
4
|
+
class ETagParser
|
5
|
+
SourceLocation = Struct.new(:file, :line, :symbol_type)
|
6
|
+
|
7
|
+
attr_reader :tags_path
|
8
|
+
attr_reader :ruby_source_folder
|
9
|
+
|
10
|
+
def self.symbol_map_for(tags_path, ruby_source_folder)
|
11
|
+
new(tags_path, ruby_source_folder).symbol_map
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(tags_path, ruby_source_folder)
|
15
|
+
@tags_path = tags_path
|
16
|
+
@ruby_source_folder = ruby_source_folder
|
17
|
+
end
|
18
|
+
|
19
|
+
def symbol_map
|
20
|
+
parse_tagfile.each_with_object({}) do |c_file, hash|
|
21
|
+
# Append all the SourceLocations for a symbol to the same array
|
22
|
+
# e.g
|
23
|
+
# { "foo" => [SourceLocation_1] }
|
24
|
+
# { "foo" => [SourceLocation_2] }
|
25
|
+
# => { "foo" => [SourceLocation_1, SourceLocation_2] }
|
26
|
+
hash.merge!(c_file.symbol_map) { |key, old_val, new_val| old_val + new_val }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# \f\n indicates a new C file boundary in the etags file.
|
33
|
+
# The first line is the name of the C file, e.g foo.c
|
34
|
+
# The successive lines contain information about the symbols for that file.
|
35
|
+
def parse_tagfile
|
36
|
+
tagfile_sections = tagfile.split("\f\n")
|
37
|
+
tagfile_sections.shift # first section is blank
|
38
|
+
|
39
|
+
tagfile_sections.map do |c_file_section|
|
40
|
+
file_name, content = file_name_and_content_for(c_file_section)
|
41
|
+
CFile.new(file_name: file_name, content: content, ruby_source_folder: ruby_source_folder)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_name_and_content_for(c_file_section)
|
46
|
+
file_name, *content = c_file_section.lines
|
47
|
+
[clean_file_name(file_name), content]
|
48
|
+
end
|
49
|
+
|
50
|
+
def tagfile
|
51
|
+
File.read(tags_path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def clean_file_name(file_name)
|
55
|
+
file_name.split(",").first
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/pry-doc/version.rb
CHANGED
data/spec/pry-doc_spec.rb
CHANGED
@@ -18,6 +18,7 @@ RSpec.describe PryDoc do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
21
|
+
described_class.symbol_map = nil
|
21
22
|
described_class.ruby_source_folder = File.join(File.dirname(__FILE__), "fixtures/c_source")
|
22
23
|
end
|
23
24
|
|
@@ -27,9 +28,9 @@ RSpec.describe PryDoc do
|
|
27
28
|
expect(described_class.ruby_source_installer).to receive(:install)
|
28
29
|
|
29
30
|
# will try to read from the 'created' tags file, this will error, so rescue
|
30
|
-
# (since we're stubbing out `
|
31
|
+
# (since we're stubbing out `install` no tags file
|
31
32
|
# ever gets created)
|
32
|
-
described_class.
|
33
|
+
described_class.symbol_map rescue nil
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair (banisterfiend)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/pry-doc/pry_ext/show_source_with_c_internals.rb
|
132
132
|
- lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb
|
133
133
|
- lib/pry-doc/pry_ext/show_source_with_c_internals/code_fetcher.rb
|
134
|
+
- lib/pry-doc/pry_ext/show_source_with_c_internals/etag_parser.rb
|
134
135
|
- lib/pry-doc/pry_ext/show_source_with_c_internals/ruby_source_installer.rb
|
135
136
|
- lib/pry-doc/pry_ext/show_source_with_c_internals/symbol_extractor.rb
|
136
137
|
- lib/pry-doc/version.rb
|
@@ -162,9 +163,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
163
|
version: '2.0'
|
163
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
165
|
requirements:
|
165
|
-
- - "
|
166
|
+
- - ">="
|
166
167
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
168
|
+
version: '0'
|
168
169
|
requirements: []
|
169
170
|
rubyforge_project:
|
170
171
|
rubygems_version: 2.7.3
|