pry-sorbet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bfc26a70315521bb64ed1dd37c0d5270d33821417a0630052092b0f2efebba0f
4
+ data.tar.gz: bd69b579be964eb4f007a4506e58aad3f864f392004aa27bd56941081d45feba
5
+ SHA512:
6
+ metadata.gz: ece438c8451b3c4831d9714514e2c0cc516d0a40cf97173aff42abe76798d87f449b4701118411f76ad46f15cf965eacd28041458e3f253164b4c275cc0f79a9
7
+ data.tar.gz: 7c0810dc4586b041fad1c8e734a41dbd38a8b5dfc484c9b8ac8ce7df0e23222c18e01d23034e077cce5ff00ac6c97e27b27917390f6389d57eb2282f3207188c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pry-sorbet.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Aaron Christiansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # pry-sorbet
2
+
3
+ pry-sorbet is a Pry extension which enables it to work seamlessly with Sorbet
4
+ projects.
5
+
6
+ **Before:** Incorrect method source
7
+
8
+ ```
9
+ From: /home/aaron/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.4.4929/lib/types/private/methods/_methods.rb @ line 208:
10
+ Owner: #<Class:Foo>
11
+ Visibility: public
12
+ Number of lines: 35
13
+
14
+ T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
15
+ if !T::Private::Methods.has_sig_block_for_method(new_method)
16
+ # This should only happen if the user used alias_method to grab a handle
17
+ # to the original pre-unwound `sig` method. I guess we'll just proxy the
18
+ # call forever since we don't know who is holding onto this handle to
19
+ ```
20
+
21
+ **After:** Method source and a signature!
22
+
23
+ ```
24
+ From: playground/test.rb @ line 9:
25
+ Owner: #<Class:Foo>
26
+ Visibility: public
27
+ Sorbet: sig { returns(Integer) }
28
+ Number of lines: 3
29
+
30
+ def self.bar
31
+ 3
32
+ end
33
+ ```
34
+
35
+ ## Installation
36
+
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'pry-sorbet'
41
+ ```
42
+
43
+ And then execute:
44
+
45
+ $ bundle
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install pry-sorbet
50
+
51
+ ## Usage
52
+
53
+ Make sure you've required `pry-sorbet`. The `$` command in Pry will be
54
+ automatically overwritten to add the Sorbet-specific functionality.
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/pry-sorbet.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/lib/extension.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'sorbet-runtime'
2
+ require 'pry'
3
+
4
+ class Pry
5
+ class Command
6
+ class ShowInfo
7
+ old_method_sections = instance_method(:method_sections)
8
+
9
+ define_method(:method_sections) do |code_object|
10
+ sorbet_object = T::Private::Methods.signature_for_method(code_object)
11
+
12
+ if sorbet_object
13
+ call_chain = []
14
+
15
+ # Modifiers
16
+ call_chain << "generated" if sorbet_object.generated
17
+
18
+ if sorbet_object.mode != "standard"
19
+ # This is a string like "overridable_override"
20
+ call_chain += sorbet_object.mode.split("_")
21
+ end
22
+
23
+ # Parameters
24
+ all_parameters = []
25
+
26
+ # Positional
27
+ all_parameters += sorbet_object.arg_types.map do |(name, type)|
28
+ "#{name}: #{type}"
29
+ end
30
+
31
+ # Splat
32
+ if sorbet_object.rest_type
33
+ all_parameters << "#{sorbet_object.rest_name}: #{sorbet_object.rest_type}"
34
+ end
35
+
36
+ # Keyword
37
+ all_parameters += sorbet_object.kwarg_types.map do |(name, type)|
38
+ "#{name}: #{type}"
39
+ end
40
+
41
+ # Double-splat
42
+ if sorbet_object.rest_type
43
+ all_parameters << "#{sorbet_object.keyrest_name}: #{sorbet_object.keyrest_type}"
44
+ end
45
+
46
+ # Block
47
+ if sorbet_object.block_type
48
+ all_parameters << "#{sorbet_object.block_name}: #{sorbet_object.block_type}"
49
+ end
50
+
51
+ call_chain << "params(#{all_parameters.join(", ")})" if all_parameters.any?
52
+
53
+ # Returns
54
+ if sorbet_object.return_type.is_a?(T::Private::Types::Void)
55
+ call_chain << "void"
56
+ else
57
+ call_chain << "returns(#{sorbet_object.return_type})"
58
+ end
59
+
60
+ sorbet_string = "sig { #{call_chain.join(".")} }"
61
+ else
62
+ sorbet_string = "Unknown"
63
+ end
64
+
65
+ old_method_sections.bind(self).(code_object).merge({
66
+ sorbet: "\n\e[1mSorbet:\e[0m #{sorbet_string}"
67
+ })
68
+ end
69
+
70
+ old_method_header = instance_method(:method_header)
71
+
72
+ define_method(:method_header) do |code_object, line_num|
73
+ old_method_header.bind(self).(code_object, line_num) \
74
+ + method_sections(code_object)[:sorbet]
75
+ end
76
+ end
77
+ end
78
+
79
+ class Method
80
+ # Maybe use a dict or something, I think methods are suitable keys
81
+ define_method(:source_location) do
82
+ loc = super()
83
+
84
+ file_path, line = loc
85
+ return loc unless file_path && File.exists?(file_path)
86
+
87
+ first_source_line = IO.readlines(file_path)[line - 1]
88
+
89
+ # This is how Sorbet replaces methods.
90
+ # If Sorbet undergoes drastic refactorings, this may need to be updated!
91
+ initial_sorbet_line = "T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|"
92
+ replaced_sorbet_line = "mod.send(:define_method, method_sig.method_name) do |*args, &blk|"
93
+
94
+ if [initial_sorbet_line, replaced_sorbet_line].include?(first_source_line.strip)
95
+ T::Private::Methods.signature_for_method(@method).method.source_location
96
+ else
97
+ loc
98
+ end
99
+ end
100
+ end
101
+ end
data/lib/pry_sorbet.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative 'extension.rb'
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "pry-sorbet"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Aaron Christiansen"]
8
+ spec.email = ["aaronc20000@gmail.com"]
9
+
10
+ spec.summary = %q{Pry plugin for Sorbet}
11
+ spec.homepage = "https://github.com/AaronC81/pry-sorbet"
12
+ spec.license = "MIT"
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-sorbet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Christiansen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - aaronc20000@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/extension.rb
54
+ - lib/pry_sorbet.rb
55
+ - pry-sorbet.gemspec
56
+ homepage: https://github.com/AaronC81/pry-sorbet
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/AaronC81/pry-sorbet
61
+ source_code_uri: https://github.com/AaronC81/pry-sorbet
62
+ changelog_uri: https://github.com/AaronC81/pry-sorbet/CHANGELOG.md
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Pry plugin for Sorbet
82
+ test_files: []