rbs_protobuf 0.3.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 9efd6a721c3cb1a7b88eb3281087e1ead753b4412976417734522f0418e91127
4
- data.tar.gz: c4182e3be30b8882b8f706e0885d6dbfc0bbb218655056bea90a6753311b05bf
3
+ metadata.gz: 563169bcedcc8c4392d8ad6c428c8fd4f31b5ca3373705439fa94a0e3f05b138
4
+ data.tar.gz: a55dd8d55cc9b866b101e51bb90ba88aa5e138251c3083b010671b03346d9db8
5
5
  SHA512:
6
- metadata.gz: 4d2183fb59feb4511635bf5fd85801721ecb120dd10a0fa7bd0757bfeed71a047ec6a849e96c66cfdc07101bf396f98d4e8d965c968fc379ccf3fc92ea2ab541
7
- data.tar.gz: f865435271dcf8fc3c9945400e932c84f32da998d56625c5039912ab9256bcc01b8801906e4a008be0788fa1e0153b76f61994712f346d2eeb5e3a865561a23a
6
+ metadata.gz: d0ea93fd55f7b9efb4a864156e428033da4116499c99ef8f222949ae301b16fe302cd00c022ce2ad91ac9216dca508a084a9c59fb5b296dbd5e41d4d8dd6b205
7
+ data.tar.gz: c143b93fce43ede0ff094a26f2e51d3d72e6b35853852cc11e1b571f74abbe68ec7f579af206bec8213c908bb34d1421986f57a6f14417d316d7b666491c04ce
@@ -30,7 +30,9 @@ jobs:
30
30
  unzip protoc-${{ matrix.protoc_version }}-linux-x86_64.zip
31
31
  mv bin/protoc /usr/local/bin/protoc
32
32
  protoc --version
33
- - uses: actions/checkout@v1
33
+ - uses: actions/checkout@v3
34
+ with:
35
+ submodules: true
34
36
  - name: Run test
35
37
  run: |
36
38
  ruby -v
data/.gitmodules CHANGED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/gem_rbs_collection"]
2
+ path = vendor/gem_rbs_collection
3
+ url = git@github.com:ruby/gem_rbs_collection.git
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0 (2022-04-25)
4
+
5
+ This is version 1.0.0. 🎉
6
+
7
+ It includes changes on `nil` handling on required fields. Passing `nil` to required fields is prohibited by default, but there is an option to allow it, define `$RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER` env var.
8
+
9
+ * Stop accepting `nil` to required fields ([\#16](https://github.com/square/rbs_protobuf/pull/16))
10
+ * Add an option to let required fields accept `nil` ([\#27](https://github.com/square/rbs_protobuf/pull/27))
11
+ * Fix extension generator ([\#21](https://github.com/square/rbs_protobuf/pull/21))
12
+ * Use overload for field write types ([\#22](https://github.com/square/rbs_protobuf/pull/22))
13
+ * Generate helper types and use them ([\#24](https://github.com/square/rbs_protobuf/pull/24))
14
+
3
15
  ## 0.3.0 (2022-04-05)
4
16
 
5
17
  * Put protobuf _options_ in RBS comment ([\#15](https://github.com/square/rbs_protobuf/pull/15))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_protobuf (0.3.0)
4
+ rbs_protobuf (1.0.0)
5
5
  activesupport (>= 4.0)
6
6
  rbs (>= 2.2.0)
7
7
 
@@ -25,7 +25,7 @@ GEM
25
25
  middleware (0.1.0)
26
26
  minitest (5.15.0)
27
27
  parallel (1.22.1)
28
- parser (3.1.1.0)
28
+ parser (3.1.2.0)
29
29
  ast (~> 2.4.1)
30
30
  protobuf (3.10.5)
31
31
  activesupport (>= 3.2)
@@ -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.3.1)
41
- steep (0.52.0)
40
+ rbs (2.3.2)
41
+ steep (0.52.1)
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.3.0)
48
+ rbs (>= 2.3.2)
49
49
  terminal-table (>= 2, < 4)
50
50
  terminal-table (3.0.2)
51
51
  unicode-display_width (>= 1.1.1, < 3)
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  steep
68
68
 
69
69
  BUNDLED WITH
70
- 2.1.4
70
+ 2.3.11
data/README.md CHANGED
@@ -95,12 +95,15 @@ gems:
95
95
  We assume that you don't type check the generated `.pb.rb` code.
96
96
  If you want to type check them, you need the definition of `Google::Protobuf`, which can be generated from [`descriptor.proto`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto).
97
97
 
98
+ Note: `rbs_protobuf` generates RBS files assuming some types added in [this PR](https://github.com/ruby/gem_rbs_collection/pull/145). Make sure you are using one of the newer versions of `rbs_gem_collection` definitions.
99
+
98
100
  ### Options
99
101
 
100
102
  * `RBS_PROTOBUF_BACKEND` specifies the Ruby code generator gem. Supported value is `protobuf`. (We will add `google-protobuf` for `google-protobuf` gem.)
101
103
  * `PB_UPCASE_ENUMS` is for `protobuf` gem support. Specify the environment variable to make enum value constants upper case.
102
104
  * `RBS_PROTOBUF_NO_NESTED_NAMESPACE` is to make the RBS declarations flat.
103
105
  * `RBS_PROTOBUF_EXTENSION` specifies what to do for extensions.
106
+ * `RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER` is to allow passing `nil` to required fields.
104
107
 
105
108
  ## Supported features
106
109
 
data/Steepfile CHANGED
@@ -2,6 +2,7 @@ D = Steep::Diagnostic
2
2
 
3
3
  target :lib do
4
4
  signature "sig"
5
+ signature "vendor/gem_rbs_collection/gems/protobuf"
5
6
  check "lib"
6
7
 
7
8
  configure_code_diagnostics do |hash|
data/bin/steep CHANGED
@@ -1,15 +1,17 @@
1
- #!/bin/sh
1
+ #!/usr/bin/env bash
2
2
 
3
- REPO_ROOT=$(cd $(dirname $0); pwd)/..
3
+ BINSTUB_DIR=$(cd $(dirname $0); pwd)
4
+ GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile)
5
+ ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)
4
6
 
5
- STEEP="bundle exec steep"
7
+ STEEP="bundle exec --gemfile=${GEMFILE} steep"
6
8
 
7
9
  if type "rbenv" > /dev/null 2>&1; then
8
10
  STEEP="rbenv exec ${STEEP}"
9
11
  else
10
12
  if type "rvm" > /dev/null 2>&1; then
11
- STEEP="rvm ${REPO_ROOT} do ${STEEP}"
13
+ STEEP="rvm ${ROOT_DIR} do ${STEEP}"
12
14
  fi
13
15
  fi
14
16
 
15
- exec $STEEP $*
17
+ exec $STEEP $@
data/example/Steepfile CHANGED
@@ -4,6 +4,7 @@ target :lib do
4
4
  collection_config "../rbs_collection.yaml"
5
5
 
6
6
  signature "protobuf-gem"
7
+ signature "../vendor/gem_rbs_collection/gems/protobuf"
7
8
  check "protobuf_gem_example.rb"
8
9
 
9
10
  configure_code_diagnostics do |hash|
data/exe/protoc-gen-rbs CHANGED
@@ -30,11 +30,14 @@ translator = case backend
30
30
  true
31
31
  end
32
32
 
33
+ accept_nil_writer = ENV.key?("RBS_PROTOBUF_ACCEPT_NIL_ATTR_WRITER")
34
+
33
35
  RBSProtobuf::Translator::ProtobufGem.new(
34
36
  input,
35
37
  upcase_enum: upcase_enum,
36
38
  nested_namespace: !no_nested_namespace,
37
- extension: extension
39
+ extension: extension,
40
+ accept_nil_writer: accept_nil_writer
38
41
  )
39
42
  when "google-protobuf"
40
43
  raise NotImplementedError
@@ -0,0 +1,68 @@
1
+ module RBSProtobuf
2
+ module Name
3
+ class Class
4
+ attr_reader :name
5
+
6
+ def initialize(name)
7
+ raise unless name.class?
8
+ @name = name
9
+ end
10
+
11
+ def instance_type(*args)
12
+ RBS::Types::ClassInstance.new(name: name, args: args, location: nil)
13
+ end
14
+
15
+ alias [] instance_type
16
+
17
+ def singleton_type
18
+ RBS::Types::ClassSingleton.new(name: name, location: nil)
19
+ end
20
+
21
+ def instance_type?(t)
22
+ t.is_a?(RBS::Types::ClassInstance) && t.name == name
23
+ end
24
+
25
+ def singleton_type?(t)
26
+ t.is_a?(RBS::Types::ClassSingleton) && t.name == name
27
+ end
28
+
29
+ def super_class(*args)
30
+ RBS::AST::Declarations::Class::Super.new(name: name, args: args, location: nil)
31
+ end
32
+ end
33
+
34
+ class Alias
35
+ attr_reader :name
36
+
37
+ def initialize(name)
38
+ raise unless name.alias?
39
+ @name = name
40
+ end
41
+
42
+ def [](*args)
43
+ RBS::Types::Alias.new(name: name, args: args, location: nil)
44
+ end
45
+
46
+ def type?(t)
47
+ t.is_a?(RBS::Types::Alias) && t.name == name
48
+ end
49
+ end
50
+
51
+ class Interface
52
+ attr_reader :name
53
+
54
+ def initialize(name)
55
+ raise unless name.interface?
56
+ @name = name
57
+ end
58
+
59
+ def [](*args)
60
+ RBS::Types::Interface.new(name: name, args: args, location: nil)
61
+ end
62
+
63
+ def type?(t)
64
+ t.is_a?(RBS::Types::Interface) && t.name == name
65
+ end
66
+ end
67
+ end
68
+ end