Skip to content

Resolve ignore comments for group fields - #4684

Merged
anuraaga merged 5 commits into
bufbuild:mainfrom
anuraaga:group-comment-ignroe
Sep 21, 2026
Merged

anuraaga merged 5 commits into
bufbuild:mainfrom
anuraaga:group-comment-ignroe

Conversation

@anuraaga

Copy link
Copy Markdown
Contributor

Currently ignore comments are missed when a group is defined inline on a field. This PR takes the approach exactly outlined, to resolve a source path in the descriptor, check if it's a group, and check it's message type for comments instead of only the field. Not ideal, but it's only needed on errors and should still generally be a relatively short traversal.

Fixes #4187

@anuraaga
anuraaga requested a review from emcfarlane September 16, 2026 08:56
Comment thread private/bufpkg/bufcheck/client.go Outdated
case parentMessageDescriptor != nil && tag == messageNestedMessagesTag:
messageDescriptors = parentMessageDescriptor.Messages()
default:
return nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While I think source paths are supposed to be valid here, I kept things lenient here since it seemed better that way

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a reasonable approach.

@emcfarlane emcfarlane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm! Small suggestions but feel free to resolve.

Comment thread private/bufpkg/bufcheck/client.go
Comment thread private/bufpkg/bufcheck/client.go Outdated
Comment thread private/bufpkg/bufcheck/client.go Outdated
case parentMessageDescriptor != nil && tag == messageNestedMessagesTag:
messageDescriptors = parentMessageDescriptor.Messages()
default:
return nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a reasonable approach.

Comment thread private/bufpkg/bufcheck/client.go Outdated
// A source path for a field declaration alternates a tag and an index, descending through
// message declarations before terminating at a field or an extension field, for example
// [4, 0, 3, 1, 2, 0] for .message_type(0).nested_type(1).field(0).
func fieldDescriptorForSourcePath(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be helpful to export a utility from protosourcepath for source path parsing/traversal, since those mechanisms already exist? I think that might help simplify the logic required for maintenance at this layer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks - I have extracted a helper, in doing so made it a bit more general (previously we only traversed for a group field, not any type of descriptor

anuraaga and others added 3 commits September 17, 2026 10:17
Co-authored-by: Edward McFarlane <3036610+emcfarlane@users.noreply.github.com>
@anuraaga
anuraaga merged commit 6e81ec6 into bufbuild:main Sep 21, 2026
9 of 10 checks passed
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.

Comment ignores are not being picked up by group fields

3 participants