From bc32353a7072085ea68eee27ab9cdb69482fd697 Mon Sep 17 00:00:00 2001 From: Scott Moeller Date: Fri, 16 Jan 2026 18:03:07 +0000 Subject: [PATCH] fix(gazelle): generate target names from proto file name, not directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix target name generation in the buf gazelle plugin's `CrossResolve` function to use the proto file name instead of the directory name. This aligns with the official Bazel proto_library naming convention documented at: https://bazel.build/reference/be/protocol-buffer Per Bazel's convention: "A file named foo.proto will be in a rule named foo_proto, which is located in the same package." The original code used `proto.RuleName(path.Dir(importSpec.Imp))` which incorrectly derived target names from the directory path. Example import: `logical/interface.proto` Before (wrong): `@buf_deps//logical:logical_proto` (from directory) After (correct): `@buf_deps//logical:interface_proto` (from file) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- gazelle/buf/cross_resolve.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gazelle/buf/cross_resolve.go b/gazelle/buf/cross_resolve.go index 3d6ffe7..d59103a 100644 --- a/gazelle/buf/cross_resolve.go +++ b/gazelle/buf/cross_resolve.go @@ -16,10 +16,10 @@ package buf import ( "path" + "strings" "github.com/bazelbuild/bazel-gazelle/config" "github.com/bazelbuild/bazel-gazelle/label" - "github.com/bazelbuild/bazel-gazelle/language/proto" "github.com/bazelbuild/bazel-gazelle/resolve" ) @@ -46,9 +46,15 @@ func (*bufLang) CrossResolve(gazelleConfig *config.Config, ruleIndex *resolve.Ru // Fall back to default buf_deps resolution config := GetConfigForGazelleConfig(gazelleConfig) depRepo := getRepoNameForPath(config.BufConfigFile.Pkg) + + // Generate target name from the proto file name, not the directory name + // e.g., "nmts/v1/proto/ek/logical/interface.proto" -> "interface_proto" + protoFile := path.Base(importSpec.Imp) + targetName := strings.TrimSuffix(protoFile, ".proto") + "_proto" + return []resolve.FindResult{ { - Label: label.New(depRepo, path.Dir(importSpec.Imp), proto.RuleName(path.Dir(importSpec.Imp))), + Label: label.New(depRepo, path.Dir(importSpec.Imp), targetName), }, } }