MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / extractPublishedDiagnostics

Function extractPublishedDiagnostics

pkg/lsp/handler_functional_test.go:278–321  ·  view source on GitHub ↗
(t *testing.T, output string)

Source from the content-addressed store, hash-verified

276}
277
278func 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}

Calls 1

HelperMethod · 0.65

Tested by

no test coverage detected