Avoid retaining hidden simple deferred messages

This commit is contained in:
2026-10-26 14:35:44 +00:00
parent 135d8da2b9
commit 473fb027a1
3 changed files with 108 additions and 18 deletions

View File

@@ -249,6 +249,16 @@ func (r DeferredReporter) enqueue(category messageCategory, message string, deta
if state.closed {
return ErrReporterClosed
}
if !hasDetails(details) {
if message == "" {
return nil
}
if !state.visible(category) {
state.diagnostics.submitted = true
state.diagnostics.suppressed = true
return nil
}
}
state.deferred = append(state.deferred, deferredMessage{
category: category,
message: message,
@@ -268,12 +278,16 @@ func (r *Reporter) finalize(outcome Outcome, completion func(*Reporter)) Outcome
state.mu.Unlock()
return normalizeOutcome(outcome)
}
deferred := append([]deferredMessage(nil), state.deferred...)
deferred := state.deferred
state.deferred = nil
state.mu.Unlock()
for _, message := range deferred {
_ = r.submitMessage(message.category, message.message, message.details)
for index := range deferred {
message := deferred[index]
deferred[index] = deferredMessage{}
state.mu.Lock()
_ = state.submitMessageLocked(message.category, message.message, message.details)
state.mu.Unlock()
}
if completion != nil {
completion(r)
@@ -339,10 +353,11 @@ func ensureFallbackExplanation(outcome Outcome) Outcome {
}
func hasExplanation(explanation Explanation) bool {
if explanation.Message != "" {
return true
}
for _, detail := range explanation.Details {
return explanation.Message != "" || hasDetails(explanation.Details)
}
func hasDetails(details []Detail) bool {
for _, detail := range details {
if detail != nil {
return true
}
@@ -405,16 +420,16 @@ func (r *Reporter) submitMessage(category messageCategory, message string, detai
if state.closed {
return ErrReporterClosed
}
return state.submitMessageLocked(category, message, append([]Detail(nil), details...))
}
details = append([]Detail(nil), details...)
hasDetails := false
for _, detail := range details {
if detail != nil {
hasDetails = true
break
}
// Queued detail lists have already been captured; delivery need not copy them.
func (state *reportingState) submitMessageLocked(category messageCategory, message string, details []Detail) error {
if state.closed {
return ErrReporterClosed
}
if message == "" && !hasDetails {
rich := hasDetails(details)
if message == "" && !rich {
return nil
}
@@ -423,7 +438,7 @@ func (r *Reporter) submitMessage(category messageCategory, message string, detai
destination.submitted = true
if !visible {
destination.suppressed = true
if !hasDetails {
if !rich {
return nil
}
}