Skip to content

ruby codegen: support generation of rbs files (#15633) #23061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

copybara-service[bot]
Copy link

ruby codegen: support generation of rbs files (#15633)

this introduces support for a new protoc option, --rbs_out, which points to a directory where ruby type definition files, defined in the RBS format, are stored.

rbs is the type signature syntax blessed by the ruby core team, used by static analysis tools such as steep, which integrates with VS Code, the irb console (for features such as autocompletion). and typeprof.

It relies on type definitions written into .rbs files.

The protobuf library already exposes type definitions in gem_rbs_collection, which is used to source type definitions for libraries which do not want, or can't maintain type definitions themselves.

(protobuf could arguably import these into this repository, lmk if you're interested).

This should fix gaps such as better IDE integration, such as the ones described
here.

The plan is to do roughly the same type of integration as was done for .pyi annotations, which also write to separate files: add the cli option and the rbs generator.

protobuf classes in ruby rely on dynamic attribution of the base class, which makes what I'm trying to achieve a bit difficult. Ideally the type hierarchy could be specified statically in the ruby source code.

class Bar < AbstractMessage
class Bar <
Google::Protobuf::DescriptorPool.generated_pool.lookup("Bar").msgclass

Closes #15633

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15633 from HoneyryderChuck:ruby-rbs-integration 2167aa91e5de2999536dd036cb3e7bfddab720fd
FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15633 from HoneyryderChuck:ruby-rbs-integration 2167aa91e5de2999536dd036cb3e7bfddab720fd

this introduces support for a new protoc option, `--rbs_out`, which points to a directory where ruby type definition files, defined in the RBS format, are stored.

[rbs](https://github.com/ruby/rbs) is the type signature syntax blessed by the ruby core team, used by static analysis tools such as [steep](https://github.com/soutaro/steep), which integrates with VS Code, the `irb` console (for features such as autocompletion). and [typeprof](https://github.com/ruby/typeprof).

It relies on type definitions written into `.rbs` files.

The `protobuf` library already exposes type definitions in [gem_rbs_collection](https://github.com/ruby/gem_rbs_collection/tree/main/gems/google-protobuf/3.22), which is used to source type definitions for libraries which do not want, or can't maintain type definitions themselves.

(`protobuf` could arguably import these into this repository, lmk if you're interested).

This should fix gaps such as better IDE integration, such as the ones described
[here](#9495).

The plan is to do roughly the same type of integration as was done for `.pyi` annotations, which also write to separate files: add the cli option and the rbs generator.

protobuf classes in ruby rely on dynamic attribution of the base class, which makes what I'm trying to achieve a bit difficult. Ideally the type hierarchy could be specified statically in the ruby source code.

```ruby
class Bar < AbstractMessage
class Bar <
Google::Protobuf::DescriptorPool.generated_pool.lookup("Bar").msgclass
```

```

Closes #15633

FUTURE_COPYBARA_INTEGRATE_REVIEW=#15633 from HoneyryderChuck:ruby-rbs-integration 2167aa9
PiperOrigin-RevId: 792682000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant