(t *testing.T, output string)
| 276 | } |
| 277 | |
| 278 | func extractPublishedDiagnostics(t *testing.T, output string) []Diagnostic { |
| 279 | t.Helper() |
| 280 | // Output may contain multiple LSP messages; find the publishDiagnostics one. |
| 281 | // Each message is prefixed with Content-Length header. |
| 282 | parts := strings.Split(output, "Content-Length:") |
| 283 | for _, part := range parts { |
| 284 | if !strings.Contains(part, "publishDiagnostics") { |
| 285 | continue |
| 286 | } |
| 287 | // Find the JSON body |
| 288 | idx := strings.Index(part, "{") |
| 289 | if idx < 0 { |
| 290 | continue |
| 291 | } |
| 292 | body := part[idx:] |
| 293 | // May have trailing data; find balanced braces |
| 294 | var msg struct { |
| 295 | Params struct { |
| 296 | Diagnostics []Diagnostic `json:"diagnostics"` |
| 297 | } `json:"params"` |
| 298 | } |
| 299 | if err := json.Unmarshal([]byte(body), &msg); err != nil { |
| 300 | // Try to find end of JSON |
| 301 | depth := 0 |
| 302 | end := 0 |
| 303 | for i, c := range body { |
| 304 | if c == '{' { |
| 305 | depth++ |
| 306 | } else if c == '}' { |
| 307 | depth-- |
| 308 | if depth == 0 { |
| 309 | end = i + 1 |
| 310 | break |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | if end > 0 { |
| 315 | _ = json.Unmarshal([]byte(body[:end]), &msg) |
| 316 | } |
| 317 | } |
| 318 | return msg.Params.Diagnostics |
| 319 | } |
| 320 | return nil |
| 321 | } |
no test coverage detected