Skip to content

Conversation

@yordis
Copy link
Member

@yordis yordis commented Nov 8, 2025

No description provided.

@cursor
Copy link

cursor bot commented Nov 8, 2025

PR Summary

Adds --codecs support and multiline use GRPC.Server generation, with robust parameter parsing and comprehensive tests/docs.

  • Generator (cmd/protoc-gen-elixir-grpc):
    • Add --codecs flag; parse via parseCodecs and thread into generateServiceModule to emit codecs: [...].
    • Improve parameter parsing with parseKeyValuePairs to handle comma-containing values.
    • Change codegen to multiline use GRPC.Server with options (service, optional http_transcode, codecs).
    • Update CLI usage text to include --codecs.
  • Tests:
    • Add tests for codecs generation, spaced lists, and combined options.
    • Add unit tests for parseKeyValuePairs and parseCodecs.
    • Update existing expectations to multiline use GRPC.Server formatting.
  • Docs (README.md):
    • Document codecs option with examples and combined usage.
    • Reflect multiline use GRPC.Server examples.

Written by Cursor Bugbot for commit f629919. This will update automatically on new commits. Configure here.

@coderabbitai
Copy link

coderabbitai bot commented Nov 8, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new --codecs CLI flag and threads parsed codec module names through the Elixir code generator; updates generation and README to emit codecs: [...] in generated GRPC.Server options and extends tests to cover parsing and generation with codecs.

Changes

Cohort / File(s) Summary
Documentation
cmd/protoc-gen-elixir-grpc/README.md
Added "Custom Codecs" section with YAML and Elixir examples, showed codecs in server options, extended "Combining Options" to include codecs, and reformatted the use GRPC.Server example to multiline.
CLI & Generator
cmd/protoc-gen-elixir-grpc/main.go
Added --codecs flag and usage text; added parseKeyValuePairs and parseCodecs helpers; threaded codecs []string through generateElixirFilegenerateServiceModule; updated code emission to include codecs: [...] when present; adjusted server options formatting logic.
Tests
cmd/protoc-gen-elixir-grpc/main_test.go
Added tests for parseKeyValuePairs and parseCodecs; updated generated-server expectations to multiline GRPC.Server format; added scenarios: "with codecs option", "with codecs option with spaces", and "with all options combined".

Sequence Diagram

sequenceDiagram
    participant CLI as User/CLI
    participant Parser as Flag Parser
    participant Gen as Code Generator

    CLI->>Parser: receive --codecs="Mod.A, Mod.B"
    Parser->>Parser: parseCodecs -> split, trim
    Parser-->>Gen: []string{"Mod.A","Mod.B"}
    Gen->>Gen: generateElixirFile(..., codecs)
    Gen->>Gen: generateServiceModule emits server opts (http_transcode?, handler_module_prefix?, codecs?)
    Gen-->>CLI: output generated Elixir files with codecs in GRPC.Server options
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to review closely:
    • parseKeyValuePairs correctness for values containing commas and handling of whitespace/trailing commas
    • Threading of codecs through all generation paths (generateElixirFilegenerateServiceModule)
    • Test updates for multiline GRPC.Server formatting and combined-options expectations

Possibly related PRs

Poem

🐇 I nibbled flags at dawn,
Split commas, trimmed each lawn,
Modules tucked in server rows,
Elixir hums as codec flows,
Hops of joy where code now grows ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, making it impossible to assess relevance to the changeset. Provide a pull request description explaining the motivation, implementation details, and benefits of adding custom codecs support.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add support for custom codecs in gRPC server configuration' clearly describes the main change: adding codecs support to the gRPC server configuration.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yordis/feat-server-opts-1

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 725cd54 and f629919.

📒 Files selected for processing (3)
  • cmd/protoc-gen-elixir-grpc/README.md (3 hunks)
  • cmd/protoc-gen-elixir-grpc/main.go (7 hunks)
  • cmd/protoc-gen-elixir-grpc/main_test.go (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cmd/protoc-gen-elixir-grpc/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/protoc-gen-elixir-grpc/main.go
🔇 Additional comments (4)
cmd/protoc-gen-elixir-grpc/main_test.go (4)

113-114: Excellent formatting consistency!

The multi-line formatting for use GRPC.Server blocks improves readability and provides better structure for the additional options. The changes are applied consistently across all test cases.

Also applies to: 168-169, 220-222, 273-274, 325-326, 377-385, 628-629, 634-635, 686-687


387-545: Comprehensive codec test coverage!

The new codec test cases thoroughly verify the feature:

  • Basic codec parsing with multiple codecs
  • Space handling in codec lists
  • Integration with existing options (http_transcode, handler_module_prefix)

The expected Elixir output syntax is correct, and the test scenarios cover the essential use cases for the new functionality.


778-847: Well-designed parsing tests with excellent edge case coverage!

The TestParseKeyValuePairs function thoroughly tests the key-value parsing logic:

  • Handles edge cases: empty strings, trailing commas, multiple trailing commas
  • Tests space trimming for clean parsing
  • Cleverly handles values containing commas (lines 810-828), which is essential for the codecs feature

The test cases demonstrate thoughtful consideration of real-world usage patterns.


849-893: Robust codec parsing tests!

The TestParseCodecs function provides excellent coverage:

  • Tests various spacing scenarios (no spaces, spaces after commas, extra spaces)
  • Handles empty items gracefully (lines 881-884)
  • Returns nil for empty input, which is appropriate

The test cases cover realistic variations in how users might format codec lists.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yordis yordis marked this pull request as ready for review November 8, 2025 04:28
@yordis yordis force-pushed the yordis/feat-server-opts-1 branch from 3230f28 to 725cd54 Compare November 8, 2025 04:28
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

♻️ Duplicate comments (1)
cmd/protoc-gen-elixir-grpc/main.go (1)

78-123: Critical: Trailing comma bug loses the last key-value pair.

This issue was previously identified and remains unresolved. When a parameter string ends with a trailing comma (e.g., "http_transcode=true,"), the last valid key-value pair is lost because the empty final segment triggers continue at line 92, skipping the save logic at lines 117-118.

This affects all plugin parameters and could silently drop user configuration. For example:

  • Input: "http_transcode=true," → Result: empty map (http_transcode setting lost)
  • Input: "codecs=GRPC.Codec.Proto," → Result: empty map (codecs setting lost)

Apply this fix to save the key-value pair before processing the next segment:

 func parseKeyValuePairs(paramStr string) map[string]string {
 	result := make(map[string]string)
 
 	segments := strings.Split(paramStr, ",")
 	var currentKey string
 	var currentValue strings.Builder
 
 	for i, segment := range segments {
 		segment = strings.TrimSpace(segment)
-		if segment == "" {
-			continue
-		}
 
 		// Check if this segment contains an '=' sign
 		if idx := strings.Index(segment, "="); idx > 0 {
 			// This is a new key=value pair
 			// Save the previous key-value if exists
 			if currentKey != "" {
 				result[currentKey] = currentValue.String()
 			}
 
 			// Start new key-value
 			currentKey = strings.TrimSpace(segment[:idx])
 			valueStart := strings.TrimSpace(segment[idx+1:])
 			currentValue.Reset()
 			currentValue.WriteString(valueStart)
-		} else {
+		} else if segment != "" {
 			// This is a continuation of the current value
 			if currentKey != "" {
 				currentValue.WriteString(",")
 				currentValue.WriteString(segment)
 			}
 		}
-
-		// If this is the last segment, save the current key-value
-		if i == len(segments)-1 && currentKey != "" {
-			result[currentKey] = currentValue.String()
-		}
 	}
 
+	// Save the final key-value pair
+	if currentKey != "" {
+		result[currentKey] = currentValue.String()
+	}
+
 	return result
 }
🧹 Nitpick comments (2)
cmd/protoc-gen-elixir-grpc/main_test.go (1)

778-822: LGTM! Good coverage for parseCodecs.

The table-driven tests cover important edge cases including spaces and empty items.

However, consider adding tests for the parseKeyValuePairs function, especially the edge case where parameter strings have trailing commas (e.g., "key1=value1,key2=value2,"), which relates to the existing bug flagged in the past review.

Do you want me to generate test cases for parseKeyValuePairs?

cmd/protoc-gen-elixir-grpc/main.go (1)

59-59: Consider multi-line formatting for improved readability.

The usage string is quite long and could be difficult to read. Consider breaking it into multiple concatenated lines for better maintainability.

Example:

-	usage = "\n\nFlags:\n  -h, --help\tPrint this help and exit.\n      --version\tPrint the version and exit.\n      --handler_module_prefix\tCustom Elixir module prefix for handler modules instead of protobuf package.\n      --http_transcode\tEnable HTTP transcoding support (adds http_transcode: true to use GRPC.Server).\n      --codecs\tComma-separated list of codec modules (e.g., 'GRPC.Codec.Proto,GRPC.Codec.WebText,GRPC.Codec.JSON')."
+	usage = "\n\nFlags:\n" +
+		"  -h, --help\tPrint this help and exit.\n" +
+		"      --version\tPrint the version and exit.\n" +
+		"      --handler_module_prefix\tCustom Elixir module prefix for handler modules instead of protobuf package.\n" +
+		"      --http_transcode\tEnable HTTP transcoding support (adds http_transcode: true to use GRPC.Server).\n" +
+		"      --codecs\tComma-separated list of codec modules (e.g., 'GRPC.Codec.Proto,GRPC.Codec.WebText,GRPC.Codec.JSON')."
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2099f4 and 725cd54.

📒 Files selected for processing (3)
  • cmd/protoc-gen-elixir-grpc/README.md (3 hunks)
  • cmd/protoc-gen-elixir-grpc/main.go (7 hunks)
  • cmd/protoc-gen-elixir-grpc/main_test.go (9 hunks)
🔇 Additional comments (7)
cmd/protoc-gen-elixir-grpc/README.md (2)

84-109: LGTM! Clear documentation for custom codecs.

The documentation clearly explains the codecs feature with a practical example showing both configuration and generated output.


125-125: LGTM! Consistent with the new feature.

The updated example properly demonstrates combining the new codecs option with existing options.

cmd/protoc-gen-elixir-grpc/main_test.go (2)

113-114: LGTM! Improved formatting for GRPC.Server options.

The multi-line format improves readability and is consistent with Elixir formatting conventions, especially when multiple options are present.


387-545: LGTM! Comprehensive test coverage for codecs feature.

The tests cover key scenarios including basic usage, space handling, and combination with other options. The expected output correctly matches the documented format.

cmd/protoc-gen-elixir-grpc/main.go (3)

125-140: LGTM! Clean implementation of codec parsing.

The function correctly handles empty strings, spaces, and filters empty items. The logic is straightforward and aligns well with the test coverage.


176-180: LGTM! Clean integration of codecs through the generation pipeline.

The codecs parameter is properly threaded through the generation flow, following the same pattern as existing options.

Also applies to: 216-216, 234-234, 249-249, 263-263


278-292: LGTM! Correct generation of codecs option.

The multi-line format improves readability, and the conditional rendering of options is implemented correctly. The codecs list is properly formatted as an Elixir list with comma-separated codec module names.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the yordis/feat-server-opts-1 branch from 725cd54 to f629919 Compare November 8, 2025 04:35
@yordis yordis merged commit c14c47b into main Nov 8, 2025
4 checks passed
@yordis yordis deleted the yordis/feat-server-opts-1 branch November 8, 2025 04:39
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.

2 participants