Skip to content

Commit bc32353

Browse files
electronjoeclaude
authored andcommitted
fix(gazelle): generate target names from proto file name, not directory
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 <noreply@anthropic.com>
1 parent 7b3b1f0 commit bc32353

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gazelle/buf/cross_resolve.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ package buf
1616

1717
import (
1818
"path"
19+
"strings"
1920

2021
"github.com/bazelbuild/bazel-gazelle/config"
2122
"github.com/bazelbuild/bazel-gazelle/label"
22-
"github.com/bazelbuild/bazel-gazelle/language/proto"
2323
"github.com/bazelbuild/bazel-gazelle/resolve"
2424
)
2525

@@ -46,9 +46,15 @@ func (*bufLang) CrossResolve(gazelleConfig *config.Config, ruleIndex *resolve.Ru
4646
// Fall back to default buf_deps resolution
4747
config := GetConfigForGazelleConfig(gazelleConfig)
4848
depRepo := getRepoNameForPath(config.BufConfigFile.Pkg)
49+
50+
// Generate target name from the proto file name, not the directory name
51+
// e.g., "nmts/v1/proto/ek/logical/interface.proto" -> "interface_proto"
52+
protoFile := path.Base(importSpec.Imp)
53+
targetName := strings.TrimSuffix(protoFile, ".proto") + "_proto"
54+
4955
return []resolve.FindResult{
5056
{
51-
Label: label.New(depRepo, path.Dir(importSpec.Imp), proto.RuleName(path.Dir(importSpec.Imp))),
57+
Label: label.New(depRepo, path.Dir(importSpec.Imp), targetName),
5258
},
5359
}
5460
}

0 commit comments

Comments
 (0)