From 3cf35586e567a46f9f67ef1ddcd34f08784fce90 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 24 Sep 2024 07:36:50 +0100 Subject: [PATCH] fix: support proto descriptors without source info included (#2) --- pkg/proto/options.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/proto/options.go b/pkg/proto/options.go index 087fa26..85eb355 100644 --- a/pkg/proto/options.go +++ b/pkg/proto/options.go @@ -100,12 +100,17 @@ func GetDescriptionOrComment(name NameWithSourceResolver, description Descriptio return description.GetDescription() } + srcInfo := name.SourceCodeInfo() + if srcInfo == nil { + return "" + } + builder := &strings.Builder{} - for _, comment := range name.SourceCodeInfo().LeadingDetachedComments() { + for _, comment := range srcInfo.LeadingDetachedComments() { builder.WriteString(comment) } - builder.WriteString(name.SourceCodeInfo().LeadingComments()) - builder.WriteString(name.SourceCodeInfo().TrailingComments()) + builder.WriteString(srcInfo.LeadingComments()) + builder.WriteString(srcInfo.TrailingComments()) comment := strings.TrimSpace(strings.Trim(builder.String(), "\n")) if comment != "" { @@ -113,6 +118,7 @@ func GetDescriptionOrComment(name NameWithSourceResolver, description Descriptio } return "" } + func GetEntrypointMessage(pluginOptions *PluginOptions, fileOptions *FileOptions) string { if fileOptions != nil && fileOptions.GetEntrypointMessage() != "" { return fileOptions.GetEntrypointMessage()