rbs_protobuf 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 56ace4b5dcb20700d6a42b22cac53d5a2fd7a73db0ce0817352c19ac02653aa1
4
- data.tar.gz: cbb834ca61e52d95574a4136332ceccfae623a64d438e3fec552dfc9d8250190
3
+ metadata.gz: 9efd6a721c3cb1a7b88eb3281087e1ead753b4412976417734522f0418e91127
4
+ data.tar.gz: c4182e3be30b8882b8f706e0885d6dbfc0bbb218655056bea90a6753311b05bf
5
5
  SHA512:
6
- metadata.gz: d652ba346051a94d4b3364047cbe3b6d02048a3dd5bcc911eb6041480d7b2f24f94fd4eaf306fad73e199066da4aafc18b745045da4025d11dec8854924b2aee
7
- data.tar.gz: 61660f34ee55a04ed35b2f05f94b9f6ffcbacc93abc1666185f06ba66dd9079a6fdbc47f626b51fb859cfaa57d85b55267b222271d7903a60c6afd50d006620a
6
+ metadata.gz: 4d2183fb59feb4511635bf5fd85801721ecb120dd10a0fa7bd0757bfeed71a047ec6a849e96c66cfdc07101bf396f98d4e8d965c968fc379ccf3fc92ea2ab541
7
+ data.tar.gz: f865435271dcf8fc3c9945400e932c84f32da998d56625c5039912ab9256bcc01b8801906e4a008be0788fa1e0153b76f61994712f346d2eeb5e3a865561a23a
@@ -38,5 +38,3 @@ jobs:
38
38
  bin/setup
39
39
  bundle exec rake
40
40
  bundle exec rake install
41
- mkdir -p tmp/out
42
- RBS_PROTOBUF_BACKEND=protobuf protoc --rbs_out=tmp/out -Iexample example/*.proto
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /example/protobuf-gem/
10
+ .gem_rbs_collection
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0 (2022-04-05)
4
+
5
+ * Put protobuf _options_ in RBS comment ([\#15](https://github.com/square/rbs_protobuf/pull/15))
6
+ * Add `!` methods type definitions ([\#14](https://github.com/square/rbs_protobuf/pull/14))
7
+
3
8
  ## 0.2.0 (2022-03-18)
4
9
 
5
10
  This is a maintenance release to support the latest version of RBS.
data/Gemfile CHANGED
@@ -6,5 +6,6 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
8
  gem "steep"
9
+ gem "rbs"
9
10
 
10
11
  gem "protobuf", "~> 3.10"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_protobuf (0.2.0)
4
+ rbs_protobuf (0.3.0)
5
5
  activesupport (>= 4.0)
6
6
  rbs (>= 2.2.0)
7
7
 
@@ -14,7 +14,7 @@ GEM
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
16
  ast (2.4.2)
17
- concurrent-ruby (1.1.9)
17
+ concurrent-ruby (1.1.10)
18
18
  ffi (1.15.5)
19
19
  i18n (1.10.0)
20
20
  concurrent-ruby (~> 1.0)
@@ -24,7 +24,7 @@ GEM
24
24
  rb-inotify (~> 0.9, >= 0.9.10)
25
25
  middleware (0.1.0)
26
26
  minitest (5.15.0)
27
- parallel (1.21.0)
27
+ parallel (1.22.1)
28
28
  parser (3.1.1.0)
29
29
  ast (~> 2.4.1)
30
30
  protobuf (3.10.5)
@@ -37,15 +37,15 @@ GEM
37
37
  rb-fsevent (0.11.1)
38
38
  rb-inotify (0.10.1)
39
39
  ffi (~> 1.0)
40
- rbs (2.2.2)
41
- steep (0.49.1)
40
+ rbs (2.3.1)
41
+ steep (0.52.0)
42
42
  activesupport (>= 5.1)
43
43
  language_server-protocol (>= 3.15, < 4.0)
44
44
  listen (~> 3.0)
45
45
  parallel (>= 1.0.0)
46
46
  parser (>= 3.0)
47
47
  rainbow (>= 2.2.2, < 4.0)
48
- rbs (>= 2.2.0)
48
+ rbs (>= 2.3.0)
49
49
  terminal-table (>= 2, < 4)
50
50
  terminal-table (3.0.2)
51
51
  unicode-display_width (>= 1.1.1, < 3)
@@ -62,6 +62,7 @@ DEPENDENCIES
62
62
  minitest (~> 5.0)
63
63
  protobuf (~> 3.10)
64
64
  rake (~> 12.0)
65
+ rbs
65
66
  rbs_protobuf!
66
67
  steep
67
68
 
data/Rakefile CHANGED
@@ -13,6 +13,9 @@ task :default => [:test, "example:typecheck"]
13
13
  namespace :example do
14
14
  desc "Generate Ruby code with protobuf-gem"
15
15
  task :protobufgem do
16
+ spec = Gem::Specification.find_by_name("protobuf")
17
+ proto_path = File.join(spec.gem_dir, "proto")
18
+
16
19
  sh("rm -rf example/protobuf-gem")
17
20
  sh("mkdir", "-p", "example/protobuf-gem")
18
21
  sh(
@@ -21,8 +24,10 @@ namespace :example do
21
24
  "--plugin=protoc-gen-ruby-protobuf=#{__dir__}/bin/protoc-gen-ruby",
22
25
  "--ruby-protobuf_out=example/protobuf-gem",
23
26
  "-Iexample",
27
+ "-I#{proto_path}",
24
28
  "example/a.proto",
25
- "example/b.proto"
29
+ "example/b.proto",
30
+ "example/c.proto"
26
31
  )
27
32
  sh(
28
33
  { "RBS_PROTOBUF_BACKEND" => "protobuf", "RBS_PROTOBUF_EXTENSION" => "true" },
@@ -32,6 +37,14 @@ namespace :example do
32
37
  "example/a.proto",
33
38
  "example/b.proto"
34
39
  )
40
+ sh(
41
+ { "RBS_PROTOBUF_BACKEND" => "protobuf", "RBS_PROTOBUF_EXTENSION" => "true", "RUBYOPT" => "-rbundler/setup -Iexample/protobuf-gem -rc.pb" },
42
+ "protoc",
43
+ "--rbs_out=example/protobuf-gem",
44
+ "-Iexample",
45
+ "-I#{proto_path}",
46
+ "example/c.proto"
47
+ )
35
48
  end
36
49
 
37
50
  desc "Type check generated code"
data/Steepfile CHANGED
@@ -4,18 +4,9 @@ target :lib do
4
4
  signature "sig"
5
5
  check "lib"
6
6
 
7
- library "rbs"
8
- library "monitor"
9
- library "logger"
10
- library "set"
11
- library "json"
12
- library "tsort"
13
- library "pathname"
14
- library "optparse"
15
- library "rubygems"
16
-
17
7
  configure_code_diagnostics do |hash|
18
8
  hash[D::Ruby::FallbackAny] = :hint
19
9
  hash[D::Ruby::MethodDefinitionMissing] = :hint
10
+ hash[D::Ruby::UnknownConstant] = :information
20
11
  end
21
12
  end
data/bin/setup CHANGED
@@ -17,3 +17,5 @@ else
17
17
  mkdir -p $REPODIR/..
18
18
  git clone https://github.com/ruby/gem_rbs_collection.git ${REPODIR}
19
19
  fi
20
+
21
+ bundle exec rbs collection install
data/example/Steepfile CHANGED
@@ -1,9 +1,14 @@
1
- repo = (Pathname(__dir__) + "../tmp/rbs/gem_rbs_collection/gems").to_s
1
+ D = Steep::Diagnostic
2
+
3
+ target :lib do
4
+ collection_config "../rbs_collection.yaml"
2
5
 
3
- target :protobuf_gem do
4
- check "protobuf_gem_example.rb", "protobuf-gem"
5
6
  signature "protobuf-gem"
7
+ check "protobuf_gem_example.rb"
6
8
 
7
- repo_path repo
8
- library "protobuf"
9
+ configure_code_diagnostics do |hash|
10
+ hash[D::Ruby::FallbackAny] = :hint
11
+ hash[D::Ruby::MethodDefinitionMissing] = :hint
12
+ hash[D::Ruby::UnknownConstant] = :information
13
+ end
9
14
  end
data/example/c.proto ADDED
@@ -0,0 +1,12 @@
1
+ syntax = "proto2";
2
+
3
+ import "google/protobuf/descriptor.proto";
4
+
5
+ extend google.protobuf.FieldOptions {
6
+ optional bool super_custom_option = 22300;
7
+ }
8
+
9
+ message Message {
10
+ option deprecated = true;
11
+ optional string name = 1 [(super_custom_option) = true];
12
+ }
@@ -118,10 +118,14 @@ module RBSProtobuf
118
118
  end
119
119
 
120
120
  def optional_type(type, location: nil)
121
- Types::Optional.new(
122
- type: type,
123
- location: location
124
- )
121
+ if type.is_a?(Types::Optional)
122
+ type
123
+ else
124
+ Types::Optional.new(
125
+ type: type,
126
+ location: location
127
+ )
128
+ end
125
129
  end
126
130
 
127
131
  def type_var(name, location: nil)
@@ -42,10 +42,12 @@ module RBSProtobuf
42
42
  raise NotImplementedError
43
43
  end
44
44
 
45
- def comment_for_path(source_code_info, path)
45
+ def comment_for_path(source_code_info, path, options:)
46
46
  loc = source_code_info.location.find {|loc| loc.path == path }
47
+
48
+ comments = []
49
+
47
50
  if loc
48
- comments = []
49
51
  if loc.leading_comments.length > 0
50
52
  comments << loc.leading_comments.strip
51
53
  end
@@ -55,9 +57,31 @@ module RBSProtobuf
55
57
  if comments.empty? && !loc.leading_detached_comments.empty?
56
58
  comments << loc.leading_detached_comments.join("\n\n").strip
57
59
  end
60
+ end
61
+
62
+ if options
63
+ # @type var opts: Array[[Symbol, untyped]]
64
+ opts = []
65
+ options.each_field do |key, value|
66
+ if options.field?(key.fully_qualified_name)
67
+ opts << [key.fully_qualified_name, value]
68
+ end
69
+ end
70
+
71
+ unless opts.empty?
72
+ unless comments.empty?
73
+ comments << "----"
74
+ end
75
+ comments << "Protobuf options:"
76
+ list = opts.map {|key, value| "- `#{key} = #{value.inspect}`" }
77
+ comments << list.join("\n")
78
+ end
79
+ end
80
+
81
+ unless comments.empty?
58
82
  RBS::AST::Comment.new(
59
83
  location: nil,
60
- string: comments.join("\n\n")
84
+ string: comments.join("\n\n") + "\n\n"
61
85
  )
62
86
  end
63
87
  end
@@ -146,7 +146,7 @@ module RBSProtobuf
146
146
  super_class: message_base_class,
147
147
  type_params: [],
148
148
  location: nil,
149
- comment: comment_for_path(source_code_info, path),
149
+ comment: comment_for_path(source_code_info, path, options: message.options),
150
150
  members: [],
151
151
  annotations: []
152
152
  ).tap do |class_decl|
@@ -182,7 +182,7 @@ module RBSProtobuf
182
182
 
183
183
  message.field.each_with_index do |field, index|
184
184
  field_name = field.name.to_sym
185
- comment = comment_for_path(source_code_info, path + [2, index])
185
+ comment = comment_for_path(source_code_info, path + [2, index], options: field.options)
186
186
 
187
187
  read_type, write_type = field_type(field, maps)
188
188
 
@@ -220,6 +220,20 @@ module RBSProtobuf
220
220
  kind: :instance
221
221
  )
222
222
  end
223
+
224
+ class_decl.members << RBS::AST::Members::MethodDefinition.new(
225
+ name: :"#{field_name}!",
226
+ types: [
227
+ factory.method_type(
228
+ type: factory.function(factory.optional_type(read_type))
229
+ )
230
+ ],
231
+ annotations: [],
232
+ comment: nil,
233
+ location: nil,
234
+ overload: false,
235
+ kind: :instance
236
+ )
223
237
  end
224
238
 
225
239
  class_decl.members << RBS::AST::Members::MethodDefinition.new(
@@ -414,7 +428,7 @@ module RBSProtobuf
414
428
  super_class: enum_base_class(),
415
429
  type_params: factory.module_type_params(),
416
430
  members: [],
417
- comment: comment_for_path(source_code_info, path),
431
+ comment: comment_for_path(source_code_info, path, options: enum_type.options),
418
432
  location: nil,
419
433
  annotations: []
420
434
  ).tap do |enum_decl|
@@ -491,7 +505,7 @@ module RBSProtobuf
491
505
  )
492
506
 
493
507
  enum_type.value.each.with_index do |v, index|
494
- comment = comment_for_path(source_code_info, path + [2, index])
508
+ comment = comment_for_path(source_code_info, path + [2, index], options: v.options)
495
509
 
496
510
  enum_decl.members << RBS::AST::Declarations::Constant.new(
497
511
  name: factory.type_name(enum_name(v.name).to_s),
@@ -608,7 +622,7 @@ module RBSProtobuf
608
622
  super_class: service_base_class,
609
623
  type_params: factory.module_type_params(),
610
624
  members: [],
611
- comment: comment_for_path(source_code_info, path),
625
+ comment: comment_for_path(source_code_info, path, options: nil),
612
626
  location: nil,
613
627
  annotations: []
614
628
  )
@@ -1,3 +1,3 @@
1
1
  module RBSProtobuf
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,116 @@
1
+ ---
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+ path: ".gem_rbs_collection"
8
+ gems:
9
+ - name: rbs
10
+ version: 2.3.1
11
+ source:
12
+ type: rubygems
13
+ - name: activesupport
14
+ version: '6.0'
15
+ source:
16
+ type: git
17
+ name: ruby/gem_rbs_collection
18
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
19
+ remote: https://github.com/ruby/gem_rbs_collection.git
20
+ repo_dir: gems
21
+ - name: protobuf
22
+ version: 3.10.3
23
+ source:
24
+ type: git
25
+ name: ruby/gem_rbs_collection
26
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
27
+ remote: https://github.com/ruby/gem_rbs_collection.git
28
+ repo_dir: gems
29
+ - name: ast
30
+ version: '2.4'
31
+ source:
32
+ type: git
33
+ name: ruby/gem_rbs_collection
34
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
35
+ remote: https://github.com/ruby/gem_rbs_collection.git
36
+ repo_dir: gems
37
+ - name: i18n
38
+ version: '1.10'
39
+ source:
40
+ type: git
41
+ name: ruby/gem_rbs_collection
42
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
43
+ remote: https://github.com/ruby/gem_rbs_collection.git
44
+ repo_dir: gems
45
+ - name: listen
46
+ version: '3.2'
47
+ source:
48
+ type: git
49
+ name: ruby/gem_rbs_collection
50
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
51
+ remote: https://github.com/ruby/gem_rbs_collection.git
52
+ repo_dir: gems
53
+ - name: parallel
54
+ version: '1.20'
55
+ source:
56
+ type: git
57
+ name: ruby/gem_rbs_collection
58
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
59
+ remote: https://github.com/ruby/gem_rbs_collection.git
60
+ repo_dir: gems
61
+ - name: rainbow
62
+ version: '3.0'
63
+ source:
64
+ type: git
65
+ name: ruby/gem_rbs_collection
66
+ revision: f43bb5ffee382df94113f44c7555027d7089912a
67
+ remote: https://github.com/ruby/gem_rbs_collection.git
68
+ repo_dir: gems
69
+ - name: logger
70
+ version: '0'
71
+ source:
72
+ type: stdlib
73
+ - name: set
74
+ version: '0'
75
+ source:
76
+ type: stdlib
77
+ - name: pathname
78
+ version: '0'
79
+ source:
80
+ type: stdlib
81
+ - name: json
82
+ version: '0'
83
+ source:
84
+ type: stdlib
85
+ - name: optparse
86
+ version: '0'
87
+ source:
88
+ type: stdlib
89
+ - name: rubygems
90
+ version: '0'
91
+ source:
92
+ type: stdlib
93
+ - name: tsort
94
+ version: '0'
95
+ source:
96
+ type: stdlib
97
+ - name: monitor
98
+ version: '0'
99
+ source:
100
+ type: stdlib
101
+ - name: date
102
+ version: '0'
103
+ source:
104
+ type: stdlib
105
+ - name: singleton
106
+ version: '0'
107
+ source:
108
+ type: stdlib
109
+ - name: mutex_m
110
+ version: '0'
111
+ source:
112
+ type: stdlib
113
+ - name: time
114
+ version: '0'
115
+ source:
116
+ type: stdlib
@@ -0,0 +1,18 @@
1
+ # Download sources
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+
8
+ # A directory to install the downloaded RBSs
9
+ path: .gem_rbs_collection
10
+
11
+ gems:
12
+ # Skip loading rbs gem's RBS.
13
+ # It's unnecessary if you don't use rbs as a library.
14
+ - name: rbs
15
+ - name: activesupport
16
+ - name: protobuf
17
+ - name: rbs_protobuf
18
+ ignore: true
@@ -23,7 +23,9 @@ module RBSProtobuf
23
23
 
24
24
  def rbs_content: (String file) -> String
25
25
 
26
- def comment_for_path: (untyped source_code_info, Array[Integer] path) -> RBS::AST::Comment?
26
+ def comment_for_path: (untyped source_code_info, Array[Integer] path, options: untyped) -> RBS::AST::Comment?
27
+
28
+ def each_options_field: (untyped) { (Symbol, untyped) -> void } -> void
27
29
 
28
30
  def base_type: (untyped `type`) -> RBS::Types::t
29
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -68,6 +68,7 @@ files:
68
68
  - example/Steepfile
69
69
  - example/a.proto
70
70
  - example/b.proto
71
+ - example/c.proto
71
72
  - example/protobuf_gem_example.rb
72
73
  - exe/protoc-gen-rbs
73
74
  - lib/rbs_protobuf.rb
@@ -75,13 +76,14 @@ files:
75
76
  - lib/rbs_protobuf/translator/base.rb
76
77
  - lib/rbs_protobuf/translator/protobuf_gem.rb
77
78
  - lib/rbs_protobuf/version.rb
79
+ - rbs_collection.lock.yaml
80
+ - rbs_collection.yaml
78
81
  - rbs_protobuf.gemspec
79
82
  - sig/rbs_protobuf.rbs
80
83
  - sig/rbs_protobuf/rbs_factory.rbs
81
84
  - sig/rbs_protobuf/translator/base.rbs
82
85
  - sig/rbs_protobuf/translator/protobuf_gem.rbs
83
86
  - sig/rbs_protobuf/version.rbs
84
- - sig/stub/_activesupport.rbs
85
87
  homepage: https://github.com/square/rbs_protobuf
86
88
  licenses:
87
89
  - MIT
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  - !ruby/object:Gem::Version
105
107
  version: '0'
106
108
  requirements: []
107
- rubygems_version: 3.3.3
109
+ rubygems_version: 3.3.7
108
110
  signing_key:
109
111
  specification_version: 4
110
112
  summary: Generate RBS files from .proto files
@@ -1,7 +0,0 @@
1
- module ActiveSupport
2
- module Inflector
3
- def self?.upcase_first: (String) -> String
4
-
5
- def self?.camelize: (String) -> String
6
- end
7
- end