fix(parser): deterministic order for remaining doc-comment tags

FormatDocComment emitted leftover tags by ranging a map, so multi-tag comments (@example/@see/@deprecated) rendered in random order run-to-run — nondeterministic output that defeats caching/diffing. Sort the remaining tag names before emitting.
This commit is contained in:
2026-06-20 00:33:34 +01:00
parent 85a539b18b
commit 5452cfce30
+8 -2
View File
@@ -3,6 +3,7 @@ package parser
import ( import (
"regexp" "regexp"
"sort"
"strings" "strings"
"github.com/lukaszraczylo/mcp-filepuff/pkg/protocol" "github.com/lukaszraczylo/mcp-filepuff/pkg/protocol"
@@ -530,11 +531,16 @@ func FormatDocComment(doc *DocComment) string {
written[t] = true written[t] = true
} }
for tagName, val := range doc.Tags { remaining := make([]string, 0, len(doc.Tags))
for tagName := range doc.Tags {
if !written[tagName] { if !written[tagName] {
sb.WriteString("@" + tagName + " " + val + "\n") remaining = append(remaining, tagName)
} }
} }
sort.Strings(remaining) // deterministic output (map order is random)
for _, tagName := range remaining {
sb.WriteString("@" + tagName + " " + doc.Tags[tagName] + "\n")
}
} }
return strings.TrimSpace(sb.String()) return strings.TrimSpace(sb.String())