pry-inline 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccf76045d92a7d2fc6007dd1c25e50ecd132cd32
4
- data.tar.gz: 57745615589a32560e63968cb342257b9591967a
3
+ metadata.gz: 90b17cf9bb9eb0a447283a2ad34d1e581ed045c9
4
+ data.tar.gz: 12fc419a7d493a318bd4797facab7f715a7c4091
5
5
  SHA512:
6
- metadata.gz: adf5e3164713671c75e60575e0cf4976230f069482d8491ede24e4b43bcc0d669bc140100b65d320d1b621ae2418d3676a49efb2392d0cef6a29fdb29a8b213b
7
- data.tar.gz: 81e37a0a848be77bda06062269b3ee8e6256b51b461fde7628271af3a5b00f7a468a21143a0d042d7d2c4ba76320778c92db882b17ef0eef6412e14a431d3547
6
+ metadata.gz: 942e74b75b54f63f4849d3f986159281ca1d79cc1bcb3cb5116966705e37920c519bec4d1be97bf2fc01c24940d6e391079a3349ce3527d35ddfddac5f35d91d
7
+ data.tar.gz: 46e61a948e6ba68a844d85034f7f304d1a0aab067d2c88e7959a4898d0dcc6ff0c8c0469303792c64899cd18deea4c6316872dad7f83c85e55847c754906288c
@@ -6,9 +6,6 @@ AllCops:
6
6
  Metrics/LineLength:
7
7
  Max: 120
8
8
 
9
- Style/ClassVars:
10
- Enabled: false
11
-
12
9
  Style/Documentation:
13
10
  Enabled: false
14
11
 
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- group :development do
6
- gem 'rubocop'
7
- gem 'pry-theme'
8
- end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Pry Inline
2
2
 
3
3
  Pry Inline is a plugin for [pry](https://github.com/pry/pry/),
4
- which enables the inline debugging functionality like [RubyMine](https://www.jetbrains.com/ruby/help/inline-debugging.html).
4
+ which enables the inline variables view like [RubyMine](https://www.jetbrains.com/ruby/help/inline-debugging.html).
5
5
 
6
6
  ![screenshot](./screenshot.png)
7
7
 
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
 
26
26
  There is no need to edit any configuration.
27
27
  After you have added the dependency in Gemfile,
28
- pry-inline will enable the inline debugging functionality.
28
+ pry-inline will enable the inline variables view functionality.
29
29
 
30
30
  ## Development
31
31
 
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ task default: [:test]
8
8
 
9
9
  Rake::TestTask.new do |t|
10
10
  t.libs << 'test'
11
+ t.ruby_opts = ['-r./test/helper']
11
12
  t.test_files = Dir['test/**/test_*.rb']
12
13
  t.verbose = true
13
14
  end
@@ -2,10 +2,11 @@ require 'pry'
2
2
  require 'ripper'
3
3
  require 'set'
4
4
 
5
- require 'pry-inline/inline_debuggable_code'
5
+ require 'pry-inline/code_extension'
6
+ require 'pry-inline/parser'
6
7
 
7
8
  Pry.config.hooks.add_hook(:when_started, :pry_inline) do
8
- Pry::Code.send(:prepend, PryInline::InlineDebuggableCode)
9
+ Pry::Code.send(:prepend, PryInline::CodeExtension)
9
10
  end
10
11
 
11
12
  before_session_hooks = Pry.config.hooks.get_hooks(:before_session)
@@ -13,7 +14,7 @@ Pry.config.hooks.delete_hooks(:before_session)
13
14
 
14
15
  begin
15
16
  Pry.config.hooks.add_hook(:before_session, :pry_inline) do |_, target, _|
16
- PryInline::InlineDebuggableCode.binding = target
17
+ PryInline::CodeExtension.current_binding = target
17
18
  end
18
19
  ensure
19
20
  before_session_hooks.each do |name, callable|
@@ -0,0 +1,106 @@
1
+ require 'unicode'
2
+
3
+ module PryInline
4
+ # monkey patch for Pry::Code
5
+ module CodeExtension
6
+ def self.current_binding
7
+ @current_binding
8
+ end
9
+
10
+ def self.current_binding=(value)
11
+ @current_binding = value
12
+ end
13
+
14
+ def print_to_output(output, color = false)
15
+ begin
16
+ not_colorized_output_lines = super('', false).split("\n")
17
+ @lineno_to_variables = Hash.new { |h, k| h[k] = Set.new }
18
+ traverse_sexp(Parser.sexp(@lines.map(&:line).join("\n")))
19
+
20
+ @lineno_to_variables.each do |lineno, variables|
21
+ variables.each do |v|
22
+ next unless @lineno_to_variables.any? do |l, vs|
23
+ l > lineno && vs.include?(v)
24
+ end
25
+ variables.delete(v)
26
+ end
27
+ end
28
+
29
+ current_line = CodeExtension.current_binding.eval('__LINE__')
30
+ @lineno_to_variables.each do |lineno, variables|
31
+ next if lineno == 0 || @lines.length <= lineno
32
+ next if lineno > (current_line - @lines[0].lineno)
33
+
34
+ original_width = Unicode.width(not_colorized_output_lines[lineno - 1], true)
35
+ debug_info_width = terminal_width - original_width % terminal_width + 1
36
+ debug_info_width += terminal_width if debug_info_width < min_debug_info_width
37
+
38
+ @lines[lineno - 1].tuple[0] +=
39
+ debug_info(variables)
40
+ .slice(0, debug_info_width)
41
+ .split('')
42
+ .map { |c| [c, Unicode.width(c, true)] }
43
+ .reduce([]) { |a, e| a + [[e[0], e[1] + (a.empty? ? 0 : a[-1][1])]] }
44
+ .take_while { |_, w| w < debug_info_width }
45
+ .map(&:first)
46
+ .join
47
+ end
48
+ ensure
49
+ ret = super(output, color)
50
+ end
51
+ ret
52
+ end
53
+
54
+ private
55
+
56
+ def terminal_width
57
+ `tput cols`.to_i
58
+ end
59
+
60
+ def traverse_sexp(sexp)
61
+ return unless sexp.is_a?(Array)
62
+ event = sexp[0]
63
+
64
+ return sexp.each { |s| traverse_sexp(s) } if event.is_a?(Array)
65
+ return traverse_sexp_in_assignment(sexp[1]) if %i( assign opassign massign ).include?(event)
66
+ return traverse_sexp_in_assignment(sexp[1..-1]) if event == :params
67
+ traverse_sexp(sexp[1..-1]) unless event.to_s.start_with?('@')
68
+ end
69
+
70
+ def traverse_sexp_in_assignment(sexp)
71
+ return unless sexp.is_a?(Array)
72
+ event = sexp[0]
73
+
74
+ return sexp.each { |s| traverse_sexp_in_assignment(s) } if event.is_a?(Array)
75
+ if %i( @ident @cvar @ivar @gvar ).include?(event)
76
+ return @lineno_to_variables[sexp[2][0]] << sexp[1]
77
+ elsif %i( @label ).include?(event)
78
+ return @lineno_to_variables[sexp[2][0]] << sexp[1].slice(0..-2)
79
+ end
80
+
81
+ traverse_sexp_in_assignment(sexp[1..-1])
82
+ end
83
+
84
+ def defined_variables
85
+ return [] unless CodeExtension.current_binding
86
+ %w(local_variables global_variables
87
+ self.instance_variables self.class.class_variables).map do |exp|
88
+ CodeExtension.current_binding.eval(exp)
89
+ end.flatten.to_set.map(&:to_s)
90
+ end
91
+
92
+ def debug_info(variables)
93
+ return '' if !variables || (variables & defined_variables).size <= 0
94
+ ' # ' + variables.select { |k| defined_variables.include?(k) }
95
+ .map { |k| "#{k}: #{CodeExtension.current_binding.eval(k).inspect.delete("\n")}" }
96
+ .join(', ')
97
+ end
98
+
99
+ def min_debug_info_width
100
+ if Pry.config.inline.is_a?(Hash)
101
+ min_width = Pry.config.inline[:min_debug_info_width]
102
+ end
103
+ min_width || 16
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,37 @@
1
+ require 'ripper'
2
+
3
+ module PryInline
4
+ class Parser < Ripper
5
+ attr_reader :ret
6
+
7
+ def self.sexp(src, filename = '-', lineno = 1)
8
+ parser = Parser.new(src, filename, lineno)
9
+ parser.parse || parser.ret
10
+ end
11
+
12
+ Ripper::PARSER_EVENTS.each do |event|
13
+ module_eval(<<-End, __FILE__, __LINE__ + 1)
14
+ def on_#{event}(*args)
15
+ args.unshift :#{event}
16
+ @ret = args
17
+ end
18
+ End
19
+ end
20
+
21
+ Ripper::SCANNER_EVENTS.each do |event|
22
+ module_eval(<<-End, __FILE__, __LINE__ + 1)
23
+ def on_#{event}(tok)
24
+ @ret = [:@#{event}, tok, [lineno(), column()]]
25
+ end
26
+ End
27
+ end
28
+
29
+ def compile_error(_)
30
+ @ret
31
+ end
32
+
33
+ def on_parse_error(_)
34
+ @ret
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module PryInline
2
- VERSION = '0.1.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Seiichi KONDO']
11
11
  spec.email = ['seikichi@kmc.gr.jp']
12
12
 
13
- spec.summary = 'Inline debugging like RubyMine'
14
- spec.description = 'This Pry plugin enables inline debugging like RubyMine!'
13
+ spec.summary = 'Inline variables view like RubyMine'
14
+ spec.description = 'This Pry plugin enables inline variables view like RubyMine!'
15
15
  spec.homepage = 'https://github.com/seikichi/pry-inline'
16
16
  spec.license = 'MIT'
17
17
 
@@ -19,7 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'pry', '~> 0.10.0'
22
+ spec.add_dependency 'unicode', '~> 0.4.4'
22
23
  spec.add_development_dependency 'bundler', '~> 1.10'
23
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'simplecov', '~> 0.10.0'
24
26
  spec.add_development_dependency 'test-unit', '>= 3.0.0'
27
+
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'pry-theme'
25
30
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiichi KONDO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-06 00:00:00.000000000 Z
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: unicode
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.4
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: test-unit
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +94,35 @@ dependencies:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: 3.0.0
69
- description: This Pry plugin enables inline debugging like RubyMine!
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-theme
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: This Pry plugin enables inline variables view like RubyMine!
70
126
  email:
71
127
  - seikichi@kmc.gr.jp
72
128
  executables: []
@@ -81,10 +137,9 @@ files:
81
137
  - LICENSE.txt
82
138
  - README.md
83
139
  - Rakefile
84
- - bin/console
85
- - bin/setup
86
140
  - lib/pry-inline.rb
87
- - lib/pry-inline/inline_debuggable_code.rb
141
+ - lib/pry-inline/code_extension.rb
142
+ - lib/pry-inline/parser.rb
88
143
  - lib/pry-inline/version.rb
89
144
  - pry-inline.gemspec
90
145
  - screenshot.png
@@ -111,6 +166,6 @@ rubyforge_project:
111
166
  rubygems_version: 2.4.5
112
167
  signing_key:
113
168
  specification_version: 4
114
- summary: Inline debugging like RubyMine
169
+ summary: Inline variables view like RubyMine
115
170
  test_files: []
116
171
  has_rdoc:
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'pry/inline'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
@@ -1,71 +0,0 @@
1
- module PryInline
2
- # monkey patch for Pry::Code
3
- module InlineDebuggableCode
4
- MAX_DEBUG_INFO_LENGTH = 80
5
-
6
- @@binding = nil
7
-
8
- def self.binding=(value)
9
- @@binding = value
10
- end
11
-
12
- def print_to_output(output, color = false)
13
- begin
14
- @lineno_to_variables = Hash.new { |h, k| h[k] = Set.new }
15
- traverse_sexp(Ripper.sexp(@lines.map(&:line).join("\n")))
16
- @lineno_to_variables.each do |lineno, variables|
17
- next if lineno == 0 || @lines.length <= lineno
18
- next if @with_marker && lineno > (@marker_lineno - @lines[0].lineno)
19
- add_debug_info(@lines[lineno - 1], variables)
20
- end
21
- ensure
22
- ret = super(output, color)
23
- end
24
- ret
25
- end
26
-
27
- private
28
-
29
- def traverse_sexp(sexp)
30
- return unless sexp.is_a?(Array)
31
- event = sexp[0]
32
-
33
- return sexp.each { |s| traverse_sexp(s) } if event.is_a?(Array)
34
- return traverse_sexp_in_assignment(sexp[1]) if %i( assign massign ).include?(event)
35
- return traverse_sexp_in_assignment(sexp[1..-1]) if event == :params
36
- traverse_sexp(sexp[1..-1]) unless event.to_s.start_with?('@')
37
- end
38
-
39
- def traverse_sexp_in_assignment(sexp)
40
- return unless sexp.is_a?(Array)
41
- event = sexp[0]
42
-
43
- return sexp.each { |s| traverse_sexp_in_assignment(s) } if event.is_a?(Array)
44
- if %i( @ident @cvar @ivar ).include?(event)
45
- return @lineno_to_variables[sexp[2][0]] << sexp[1]
46
- end
47
-
48
- traverse_sexp_in_assignment(sexp[1..-1])
49
- end
50
-
51
- def add_debug_info(loc, variables)
52
- return if !variables || (variables & defined_variables).size <= 0
53
- info = debug_info(variables)
54
- loc.tuple[0] += " # #{info[0..MAX_DEBUG_INFO_LENGTH]}"
55
- loc.tuple[0] += ' ...' if info.length > MAX_DEBUG_INFO_LENGTH
56
- end
57
-
58
- def defined_variables
59
- return [] unless @@binding
60
- @@binding.eval('local_variables').map(&:to_s) |
61
- @@binding.eval('self.instance_variables').map(&:to_s) |
62
- @@binding.eval('self.class.class_variables').map(&:to_s)
63
- end
64
-
65
- def debug_info(variables)
66
- variables.select { |k| defined_variables.include?(k) }
67
- .map { |k| "#{k}: #{@@binding.eval(k).inspect}" }
68
- .join(', ')
69
- end
70
- end
71
- end