Skip to content
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

chore: strip extra slashes when there is no package defined in the protofile #134

Merged

Conversation

satdeveloping
Copy link
Contributor

@satdeveloping satdeveloping commented May 12, 2024

Reason for This PR

Interfaces generated with no package defined in the .proto added an extra \ to message names.

Description of Changes

Strip extra slashes via a template function

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • Refactor

    • Updated method signatures in PHP gRPC templates to enhance readability and consistency.
  • Tests

    • Enhanced testing capabilities by adding file comparison functionality in test scenarios.
  • Documentation

    • Updated documentation to reflect changes in interface and method definitions.

Signed-off-by: Stuart Taylor <stuart@kadence.co>
Copy link

coderabbitai bot commented May 12, 2024

Walkthrough

The recent updates in the protoc-plugins project refine method signatures in PHP gRPC interfaces and enhance testing capabilities. These changes streamline type names in interfaces, improve testing robustness, and introduce specific method signatures for better code clarity.

Changes

Files Summary
.../php/template.go
.../NoPackage/Test/CustomImport/ServiceInterface.php
Updated method signatures in PHP gRPC interfaces to use strip_slashes function for cleaner type names and defined new interfaces with specific method signatures.
protoc_plugins/protoc_test.go Enhanced Test_NoPackage to include directory retrieval and file comparison for more thorough testing.

Poem

🐰✨
In the land of code, where the bits align,
A rabbit hopped, leaving changes behind.
Slashes stripped, types so clear,
Tests assert, no error near.
Hop, hop, hurray, let's compile and cheer!
🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1cabc0e and 47dba0c.
Files selected for processing (3)
  • protoc_plugins/protoc-gen-php-grpc/php/template.go (2 hunks)
  • protoc_plugins/protoc_test.go (2 hunks)
  • protoc_plugins/testdata/NoPackage/Test/CustomImport/ServiceInterface.php (1 hunks)
Additional comments not posted (4)
protoc_plugins/testdata/NoPackage/Test/CustomImport/ServiceInterface.php (1)

9-22: Interface ServiceInterface correctly extends GRPC\ServiceInterface and defines the SimpleMethod. Ensure that the \Message type is correctly defined elsewhere in the project as it's used here as both input and output type.

protoc_plugins/protoc-gen-php-grpc/php/template.go (2)

49-58: The template correctly applies the strip_slashes function to both input and output types in the method signature. This should effectively remove unnecessary backslashes, aligning with the PR's objectives.


94-96: The strip_slashes function implementation uses strings.ReplaceAll to replace double backslashes with a single one, which is a straightforward and effective way to clean up the type names.

protoc_plugins/protoc_test.go (1)

Line range hint 169-190: The updated Test_NoPackage function now includes a file comparison step, which is crucial for verifying that the generated files are correct. This is a good practice, especially when changes to the generation logic are made, as it ensures the output remains as expected.

@rustatian rustatian added the enhancement New feature or request label May 12, 2024
@rustatian
Copy link
Member

Hey @satdeveloping 👋 Thanks for the PR 👍
You're right, package directive is optional, but I see no reason not to use it. It might be we should warn users about that. Could you please attach a generated file sample without the package name and show where is the problem?

@rustatian rustatian changed the title Strip extra slashes when there is no package chore: strip extra slashes when there is no package defined in the protofile May 12, 2024
@satdeveloping
Copy link
Contributor Author

satdeveloping commented May 12, 2024

Current behaviour of generation without a package:

<?php
# Generated by the protocol buffer compiler (roadrunner-server/grpc). DO NOT EDIT!
# source: NoPackage/nopackage.proto

namespace Test\CustomImport;

use Spiral\RoadRunner\GRPC;

interface ServiceInterface extends GRPC\ServiceInterface
{
    // GRPC specific service name.
    public const NAME = "<nil>.Service";

    /**
    * @param GRPC\ContextInterface $ctx
    * @param \\Message $in
    * @return \\Message
    *
    * @throws GRPC\Exception\InvokeException
    */
    public function SimpleMethod(GRPC\ContextInterface $ctx, \\Message $in): \\Message;
}

if I tried to implement the interface, I'd get an error that:

Method 'MyService::SimpleMethod()' is not compatible with method 'GRPC\ServiceInterface::SimpleMethod()'.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 47dba0c and 7b4aa55.
Files selected for processing (3)
  • protoc_plugins/protoc-gen-php-grpc/php/template.go (2 hunks)
  • protoc_plugins/protoc_test.go (7 hunks)
  • protoc_plugins/testdata/NoPackage/Test/CustomImport/ServiceInterface.php (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protoc_plugins/protoc-gen-php-grpc/php/template.go
  • protoc_plugins/protoc_test.go
  • protoc_plugins/testdata/NoPackage/Test/CustomImport/ServiceInterface.php

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7b4aa55 and 53be8bb.
Files selected for processing (1)
  • protoc_plugins/protoc-gen-php-grpc/php/template.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protoc_plugins/protoc-gen-php-grpc/php/template.go

@rustatian rustatian self-requested a review May 13, 2024 00:01
Copy link
Member

@rustatian rustatian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @satdeveloping 👍

@rustatian rustatian merged commit e5e9205 into roadrunner-server:master May 13, 2024
5 checks passed
@satdeveloping satdeveloping deleted the fix/no-package-slashes branch May 13, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants