rbs 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbs/parser.y CHANGED
@@ -608,7 +608,6 @@ rule
608
608
  method_member:
609
609
  annotations attributes overload kDEF method_kind def_name method_types {
610
610
  location = val[3].location + val[6].last.location
611
- children = {}
612
611
 
613
612
  required_children = { keyword: val[3].location, name: val[5].location }
614
613
  optional_children = { kind: nil, overload: nil }
data/lib/rbs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RBS
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
data/rbs.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  # Specify which files should be added to the gem when it is released.
29
29
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
30
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
32
32
  end
33
33
  spec.files << "lib/rbs/parser.rb"
34
34
  spec.bindir = "exe"
data/steep/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.1.3.1)
4
+ activesupport (6.1.3.2)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 1.6, < 2)
7
7
  minitest (>= 5.1)
@@ -9,36 +9,36 @@ GEM
9
9
  zeitwerk (~> 2.3)
10
10
  ast (2.4.2)
11
11
  concurrent-ruby (1.1.8)
12
- ffi (1.15.0)
12
+ ffi (1.15.1)
13
13
  i18n (1.8.10)
14
14
  concurrent-ruby (~> 1.0)
15
- language_server-protocol (3.16.0.0)
15
+ language_server-protocol (3.16.0.1)
16
16
  listen (3.5.1)
17
17
  rb-fsevent (~> 0.10, >= 0.10.3)
18
18
  rb-inotify (~> 0.9, >= 0.9.10)
19
19
  minitest (5.14.4)
20
20
  parallel (1.20.1)
21
- parser (3.0.0.0)
21
+ parser (3.0.1.1)
22
22
  ast (~> 2.4.1)
23
23
  rainbow (3.0.0)
24
- rb-fsevent (0.10.4)
24
+ rb-fsevent (0.11.0)
25
25
  rb-inotify (0.10.1)
26
26
  ffi (~> 1.0)
27
- rbs (1.1.1)
28
- steep (0.43.1)
27
+ rbs (1.2.0)
28
+ steep (0.44.1)
29
29
  activesupport (>= 5.1)
30
30
  language_server-protocol (>= 3.15, < 4.0)
31
31
  listen (~> 3.0)
32
32
  parallel (>= 1.0.0)
33
33
  parser (>= 2.7)
34
34
  rainbow (>= 2.2.2, < 4.0)
35
- rbs (~> 1.1.0)
35
+ rbs (>= 1.2.0)
36
36
  terminal-table (>= 2, < 4)
37
- terminal-table (3.0.0)
38
- unicode-display_width (~> 1.1, >= 1.1.1)
37
+ terminal-table (3.0.1)
38
+ unicode-display_width (>= 1.1.1, < 3)
39
39
  tzinfo (2.0.4)
40
40
  concurrent-ruby (~> 1.0)
41
- unicode-display_width (1.7.0)
41
+ unicode-display_width (2.0.0)
42
42
  zeitwerk (2.4.2)
43
43
 
44
44
  PLATFORMS
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  steep
49
49
 
50
50
  BUNDLED WITH
51
- 2.2.3
51
+ 2.2.15
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-21 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -29,15 +29,6 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - Steepfile
32
- - bin/annotate-with-rdoc
33
- - bin/console
34
- - bin/query-rdoc
35
- - bin/rbs-prof
36
- - bin/run_in_md.rb
37
- - bin/setup
38
- - bin/sort
39
- - bin/steep
40
- - bin/test_runner.rb
41
32
  - core/array.rbs
42
33
  - core/basic_object.rbs
43
34
  - core/binding.rbs
@@ -290,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
281
  - !ruby/object:Gem::Version
291
282
  version: '0'
292
283
  requirements: []
293
- rubygems_version: 3.2.3
284
+ rubygems_version: 3.2.15
294
285
  signing_key:
295
286
  specification_version: 4
296
287
  summary: Type signature for Ruby.
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
- require "rdoc"
6
-
7
- def store_for_class(name, stores:)
8
- stores.find do |store|
9
- store.find_class_named(name) || store.find_module_named(name)
10
- end
11
- end
12
-
13
- def format_comment(comment)
14
- out = RDoc::Markup::Document.new
15
- out << comment
16
- formatter = RDoc::Markup::ToMarkdown.new
17
- out.accept(formatter).lines.map(&:rstrip).join("\n")
18
- end
19
-
20
- def comment_for_constant(decl, stores:)
21
- class_name = decl.name.namespace.to_type_name.to_s
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- if klass
27
- constant = klass.constants.find do |const|
28
- const.name == decl.name.name.to_s
29
- end
30
-
31
- if constant&.documented?
32
- string = format_comment(constant.comment)
33
- RBS::AST::Comment.new(location: nil, string: string)
34
- end
35
- end
36
- end
37
-
38
- def comment_for_class(decl, stores:)
39
- name = decl.name.to_s
40
- klass = store_for_class(name, stores: stores)&.yield_self {|store|
41
- store.find_class_named(name) || store.find_module_named(name)
42
- }
43
-
44
- if klass&.documented?
45
- string = format_comment(klass.comment)
46
- RBS::AST::Comment.new(location: nil, string: string)
47
- end
48
- end
49
-
50
- def comment_for_method(klass, method, stores:)
51
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
52
-
53
- if method&.documented?
54
- out = RDoc::Markup::Document.new
55
-
56
- out << method.comment
57
-
58
- if method.arglists
59
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
60
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
61
- out << RDoc::Markup::Verbatim.new(*arglists)
62
- end
63
-
64
- string = out.accept(RDoc::Markup::ToMarkdown.new)
65
- RBS::AST::Comment.new(location: nil, string: string)
66
- end
67
-
68
- rescue RDoc::Store::MissingFileError
69
- puts " 👺 No document found for #{klass}#{method}"
70
- nil
71
- end
72
-
73
- if ARGV.empty?
74
- puts 'annotate-with-rdoc [RBS files...]'
75
- exit
76
- end
77
-
78
- def print_members(stores, klass_name, members)
79
- members.each do |member|
80
- case member
81
- when RBS::AST::Members::MethodDefinition
82
- puts " Processing #{member.name}..."
83
-
84
- method_name = case
85
- when member.instance?
86
- "##{member.name}"
87
- when member.singleton?
88
- "::#{member.name}"
89
- end
90
-
91
- comment = comment_for_method(klass_name, method_name, stores: stores)
92
-
93
- unless comment
94
- if member.instance? && member.name == :initialize
95
- comment = comment_for_method(klass_name, '::new', stores: stores)
96
- end
97
- end
98
-
99
- member.instance_variable_set(:@comment, comment)
100
- when RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor, RBS::AST::Members::AttrWriter
101
- puts " 👻 Attributes not supported (#{klass_name})"
102
- when RBS::AST::Members::Alias
103
- puts " Processing #{member.new_name}(alias)..."
104
- prefix = case
105
- when member.instance?
106
- "#"
107
- when member.singleton?
108
- "."
109
- end
110
- name = "#{prefix}#{member.new_name}"
111
-
112
- comment = comment_for_method(klass_name, name, stores: stores)
113
- member.instance_variable_set(:@comment, comment)
114
- end
115
- end
116
- end
117
-
118
- stores = []
119
- RDoc::RI::Paths.each true, true, false, false do |path, type|
120
- puts "Loading store from #{path}..."
121
- store = RDoc::RI::Store.new(path, type)
122
- store.load_all
123
- stores << store
124
- end
125
-
126
- ARGV.map {|f| Pathname(f) }.each do |path|
127
- puts "Opening #{path}..."
128
-
129
- buffer = RBS::Buffer.new(name: path, content: path.read)
130
- sigs = RBS::Parser.parse_signature(buffer)
131
-
132
- sigs.each do |decl|
133
- case decl
134
- when RBS::AST::Declarations::Constant
135
- puts " Importing documentation for #{decl.name}..."
136
- comment = comment_for_constant(decl, stores: stores)
137
- decl.instance_variable_set(:@comment, comment)
138
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
139
- puts " Importing documentation for #{decl.name}..."
140
- comment = comment_for_class(decl, stores: stores)
141
- decl.instance_variable_set(:@comment, comment)
142
-
143
- print_members stores, decl.name.to_s, decl.members
144
- end
145
- end
146
-
147
- puts "Writing #{path}..."
148
- path.open('w') do |out|
149
- writer = RBS::Writer.new(out: out)
150
- writer.write sigs
151
- end
152
- end
153
-
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
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(__FILE__)
data/bin/query-rdoc DELETED
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rdoc"
4
-
5
- def store_for_class(name, stores:)
6
- stores.find do |store|
7
- store.find_class_named(name) || store.find_module_named(name)
8
- end
9
- end
10
-
11
- def format_comment(comment)
12
- out = RDoc::Markup::Document.new
13
- out << comment
14
- formatter = RDoc::Markup::ToMarkdown.new
15
- out.accept(formatter)
16
- end
17
-
18
- def comment_for_constant(name, stores:)
19
- *class_components, const_name = name.split(/::/)
20
- class_name = class_components.join("::")
21
-
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- constant = klass.constants.find do |const|
27
- const.name == const_name
28
- end
29
-
30
- if constant&.documented?
31
- format_comment(constant.comment)
32
- end
33
- end
34
-
35
- def comment_for_class(class_name, stores:)
36
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
37
- store.find_class_named(class_name) || store.find_module_named(class_name)
38
- }
39
-
40
- if klass&.documented?
41
- format_comment(klass.comment)
42
- end
43
- end
44
-
45
- def comment_for_method(klass, method, stores:)
46
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
47
-
48
- if method&.documented?
49
- out = RDoc::Markup::Document.new
50
-
51
- out << method.comment
52
-
53
- if method.arglists
54
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
55
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
56
- out << RDoc::Markup::Verbatim.new(*arglists)
57
- end
58
-
59
- out.accept(RDoc::Markup::ToMarkdown.new)
60
- end
61
- rescue RDoc::Store::MissingFileError
62
- nil
63
- end
64
-
65
- if ARGV.empty?
66
- puts 'query-rdoc [subject]'
67
- puts " subject ::= ClassName (class, module, or constant)"
68
- puts " | ClassName.method (singleton method)"
69
- puts " | ClassName#method (instance method)"
70
- exit
71
- end
72
-
73
- stores = []
74
- RDoc::RI::Paths.each true, true, false, false do |path, type|
75
- STDERR.puts "Loading store from #{path}..."
76
- store = RDoc::RI::Store.new(path, type)
77
- store.load_all
78
- stores << store
79
- end
80
-
81
- subject = ARGV[0]
82
-
83
- case
84
- when match = subject.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
85
- STDERR.puts "Finding instance method #{match[:constant_name]} # #{match[:method_name]} ..."
86
- comment = comment_for_method(match[:constant_name], "##{match[:method_name]}", stores: stores)
87
- when match = subject.match(/(?<constant_name>[^.]+)\.(?<method_name>.+)/)
88
- STDERR.puts "Finding singleton method #{match[:constant_name]} . #{match[:method_name]} ..."
89
- comment = comment_for_method(match[:constant_name], "::#{match[:method_name]}", stores: stores)
90
- else
91
- STDERR.puts "Finding class/module/constant #{subject} ..."
92
- comment = comment_for_class(subject, stores: stores) || comment_for_constant(subject, stores: stores)
93
- end
94
-
95
- if comment
96
- STDERR.puts "Printing document..."
97
- comment.each_line do |line|
98
- puts "# #{line}"
99
- end
100
- else
101
- STDERR.puts "Nothing to print; failed to query the document..."
102
- exit 1
103
- end
data/bin/rbs-prof DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "stackprof"
4
-
5
- out = ENV["RBS_STACKPROF_OUT"] || 'tmp/stackprof-cpu-rbs.dump'
6
-
7
- StackProf.run(mode: :cpu, out: out, raw: true) do
8
- load File.join(__dir__, "../exe/rbs")
9
- end
data/bin/run_in_md.rb DELETED
@@ -1,49 +0,0 @@
1
- require "tmpdir"
2
- require "shellwords"
3
-
4
- ARGV.each do |path|
5
- puts "~~~~~~~ Checking #{path} ~~~~~~"
6
- content = File.read(path)
7
-
8
- snippets = []
9
- lines = []
10
- content.lines.each.with_index do |line, index|
11
- case line
12
- when /run-start:/
13
- lines = [[line, index+1]]
14
- when /run-end/
15
- lines << [line, index+1]
16
- snippets << lines
17
- lines = []
18
- else
19
- lines << [line, index+1]
20
- end
21
- end
22
-
23
- snippets.each do |lines|
24
- puts ">>> Code detected: "
25
- hd, _, *code_lines, _, _ = lines
26
-
27
- head = hd[0]
28
- head.gsub!(/^<!-- +/, "").gsub!(/ +-->$/, "")
29
- _,name,command = head.split(/:/)
30
-
31
- puts "# command=#{Shellwords.split(command).inspect}"
32
- puts "# name=#{name}"
33
- puts code_lines.map {|line, i| "#{"%4d" % i} #{line}" }.join
34
-
35
- code = code_lines.map(&:first).join
36
-
37
- puts ">>> Running..."
38
- Dir.mktmpdir do |dir|
39
- File.write(File.join(dir, name), code)
40
- pid = spawn({ "BUNDLE_GEMFILE" => File.join(__dir__, "../Gemfile") },
41
- *Shellwords.split(command),
42
- chdir: dir)
43
-
44
- _, status = Process.waitpid2(pid)
45
-
46
- status.success? or raise "Failed to execute code: #{code_lines.join}"
47
- end
48
- end
49
- end