pry-doc 0.13.0pre7 → 0.13.0pre8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecf2ae29bffe6f81c0a6ec6dce2e15c2ce364d09
4
- data.tar.gz: 20fd2f5ae0a4f1cb9eab9c736e199991d40834ff
3
+ metadata.gz: 4f18f3949c483ac69e2b6b7786a72b176e9d7212
4
+ data.tar.gz: e6a1bbc5787add79d0d3ed0b75aba42f39545136
5
5
  SHA512:
6
- metadata.gz: de7b2c32043e9917fce673b8bf10b2070ce17e091cd08bc9708ec4d51441f22e9a6ba5c16af886cab9684f8aa29a34c62d817d6dc65c54c8eb912833e15ff122
7
- data.tar.gz: 0273e48b4b2c3bfcdc0480204b065c85e3465827c13049c065edcd890a265b90005c6866c2adaa189d1e22a598fe1615aae073af1aae7b89e215d0e6486f97f0
6
+ metadata.gz: 870ceb665ca6397cfcdf4995879f44a1f45972f05b3f259651d4f01a22983538c2e138b0dc424a06ab559d64d55b58fdb9ad536ffaed02461955811b79723bc0
7
+ data.tar.gz: e0c1d2da207f8a96bfcfceb71f8f243c81873dc13c00d2accc6d00e428b2dc636a26e44b43b70ac95dbc267c9779f370cb263b7ab6d7f67fad8c0c2201ecc3a0
data/Rakefile CHANGED
@@ -17,6 +17,11 @@ task :pry_fixture do
17
17
  sh %{pry -I./lib -r pry-doc -e "Pry::CInternals::CodeFetcher.ruby_source_folder = './spec/fixtures/c_source'"}
18
18
  end
19
19
 
20
+ desc "start pry with pry-doc code loaded"
21
+ task :pry do
22
+ sh "pry -I./lib -r pry-doc"
23
+ end
24
+
20
25
  desc "generate fixture etags"
21
26
  task :etags do
22
27
  sh 'etags --no-members spec/fixtures/c_source/*.c -o spec/fixtures/c_source/tags'
@@ -22,13 +22,14 @@ module Pry::CInternals
22
22
  end
23
23
 
24
24
  def process
25
- if opts.present?(:c)
25
+ if opts.present?(:c) && !Pry.config.skip_mri_source
26
26
  show_c_source
27
27
  return
28
28
  else
29
29
  super
30
30
  end
31
31
  rescue Pry::CommandError
32
+ raise if Pry.config.skip_mri_source
32
33
  show_c_source
33
34
  end
34
35
 
@@ -96,7 +96,17 @@ module Pry::CInternals
96
96
  raise Pry::CommandError, message if $?.to_i != 0
97
97
  end
98
98
 
99
+ def self.ask_for_install
100
+ puts "Method/class Not found - do you want to install MRI sources to attempt to resolve the lookup there? (This allows the lookup of C internals) Y/N"
101
+
102
+ if $stdin.gets !~ /^y/i
103
+ puts "MRI sources not installed. To prevent being asked again, add `Pry.config.skip_mri_source = true` to your ~/.pryrc"
104
+ raise Pry::CommandError, "No definition found."
105
+ end
106
+ end
107
+
99
108
  def self.install_and_setup_ruby_source
109
+ ask_for_install
100
110
  puts "Downloading and setting up Ruby #{ruby_version} source in attempt to resolve symbol..."
101
111
  FileUtils.mkdir_p(ruby_source_folder)
102
112
  FileUtils.cd(File.dirname(ruby_source_folder)) do
@@ -50,17 +50,14 @@ module Pry::CInternals
50
50
 
51
51
  def extract_function(info)
52
52
  source_file = source_from_file(info.file)
53
- offset = 1
54
- start_line = info.line
53
+ offset, start_line = 1, info.line
55
54
 
56
55
  if !complete_function_signature?(source_file[info.line]) && function_return_type?(source_file[info.line - 1])
57
56
  start_line = info.line - 1
58
57
  offset += 1
59
58
  end
60
59
 
61
- if !source_file[info.line].strip.end_with?("{")
62
- offset += 1
63
- end
60
+ offset += 1 if !source_file[info.line].strip.end_with?("{")
64
61
 
65
62
  extract_code(info, offset: offset, start_line: start_line) do |code|
66
63
  return code if balanced?(code)
@@ -70,13 +67,11 @@ module Pry::CInternals
70
67
  def extract_code(info, offset: 1, start_line: info.line, direction: :forward, &block)
71
68
  source_file = source_from_file(info.file)
72
69
 
70
+ code_proc = direction == :reverse ? -> { source_file[start_line - offset..info.line].join }
71
+ : -> { source_file[start_line, offset].join }
72
+
73
73
  loop do
74
- code = if direction == :reverse
75
- source_file[start_line - offset..info.line].join
76
- else
77
- source_file[start_line, offset].join
78
- end
79
- yield code
74
+ yield code_proc.()
80
75
  offset += 1
81
76
  end
82
77
  end
@@ -1,3 +1,3 @@
1
1
  module PryDoc
2
- VERSION = '0.13.0pre7'
2
+ VERSION = '0.13.0pre8'
3
3
  end
@@ -29,3 +29,15 @@ typedef struct {
29
29
  int lovely;
30
30
  char horse;
31
31
  } cutie_pie;
32
+
33
+ void tinkywinky(void) {
34
+ }
35
+
36
+ void lala(void)
37
+ {
38
+ }
39
+
40
+ int*
41
+ po(void)
42
+ {
43
+ }
@@ -2,7 +2,7 @@
2
2
  goodbye.c,9
3
3
  foo(2,5
4
4
 
5
- hello.c,256
5
+ hello.c,309
6
6
  foo(2,4
7
7
  #define baby 5,19
8
8
  typedef int wassup;9,73
@@ -17,3 +17,6 @@ typedef enum cute_enum_e 22,169
17
17
  lilt25,217
18
18
  } baby_enum;26,224
19
19
  } cutie_pie;31,283
20
+ void tinkywinky(33,297
21
+ void lala(36,324
22
+ po(41,350
data/spec/pry-doc_spec.rb CHANGED
@@ -100,7 +100,7 @@ int
100
100
  foo(void) {
101
101
  }
102
102
  EOF
103
- ).or include <<EOF
103
+ ).or include <<EOF
104
104
  char
105
105
  foo(int*) {
106
106
  return 'a';
@@ -162,6 +162,52 @@ typedef enum cute_enum_e {
162
162
  EOF
163
163
  end
164
164
 
165
+ context "function definitions" do
166
+ context "return type is on same line" do
167
+ subject do
168
+ decolor described_class.new(line_number_style: nil)
169
+ .fetch_first_definition("tinkywinky")
170
+ .first
171
+ end
172
+
173
+ it do is_expected.to include <<EOF
174
+ void tinkywinky(void) {
175
+ }
176
+ EOF
177
+ end
178
+ end
179
+
180
+ context "curl brackets on subsequent line" do
181
+ subject do
182
+ decolor described_class.new(line_number_style: nil)
183
+ .fetch_first_definition("lala")
184
+ .first
185
+ end
186
+
187
+ it do is_expected.to include <<EOF
188
+ void lala(void)
189
+ {
190
+ }
191
+ EOF
192
+ end
193
+ end
194
+
195
+ context "return type on prior line and curly brackets on subsequent" do
196
+ subject do
197
+ decolor described_class.new(line_number_style: nil)
198
+ .fetch_first_definition("po")
199
+ .first
200
+ end
201
+
202
+ it do is_expected.to include <<EOF
203
+ int*
204
+ po(void)
205
+ {
206
+ }
207
+ EOF
208
+ end
209
+ end
210
+ end
165
211
  end
166
212
  end
167
213
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0pre7
4
+ version: 0.13.0pre8
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)