@@ -392,4 +392,186 @@ T["single_diagnostic_lifecycle"]["handles diagnostic replacement"] = function()
392392 end )
393393end
394394
395+ T [" multiple_lsp_diagnostics" ] = MiniTest .new_set ()
396+
397+ T [" multiple_lsp_diagnostics" ][" DiagnosticChanged preserves diagnostics from all namespaces" ] = function ()
398+ H .with_win_buf ({ " test line" }, { 1 , 0 }, nil , function (buf , win )
399+ local tiny = require (" tiny-inline-diagnostic" )
400+ local cache = require (" tiny-inline-diagnostic.cache" )
401+ tiny .setup (create_test_opts ())
402+
403+ local ns1 = vim .api .nvim_create_namespace (" lsp1" )
404+ local ns2 = vim .api .nvim_create_namespace (" lsp2" )
405+
406+ vim .diagnostic .set (ns1 , buf , {
407+ { lnum = 0 , col = 0 , message = " error from lsp1" , severity = vim .diagnostic .severity .ERROR },
408+ })
409+
410+ vim .wait (100 )
411+
412+ vim .diagnostic .set (ns2 , buf , {
413+ { lnum = 0 , col = 5 , message = " warn from lsp2" , severity = vim .diagnostic .severity .WARN },
414+ })
415+
416+ vim .wait (100 )
417+
418+ local cached = cache .get (buf )
419+ MiniTest .expect .equality (# cached , 2 )
420+
421+ local messages = { cached [1 ].message , cached [2 ].message }
422+ table.sort (messages )
423+ MiniTest .expect .equality (messages [1 ], " error from lsp1" )
424+ MiniTest .expect .equality (messages [2 ], " warn from lsp2" )
425+ end )
426+ end
427+
428+ T [" multiple_lsp_diagnostics" ][" updates from one LSP do not erase diagnostics from other LSPs" ] = function ()
429+ H .with_win_buf ({ " test line" }, { 1 , 0 }, nil , function (buf , win )
430+ local tiny = require (" tiny-inline-diagnostic" )
431+ local cache = require (" tiny-inline-diagnostic.cache" )
432+ tiny .setup (create_test_opts ())
433+
434+ local ns1 = vim .api .nvim_create_namespace (" lsp_a" )
435+ local ns2 = vim .api .nvim_create_namespace (" lsp_b" )
436+
437+ vim .diagnostic .set (ns1 , buf , {
438+ { lnum = 0 , col = 0 , message = " first lsp error" , severity = vim .diagnostic .severity .ERROR },
439+ })
440+
441+ vim .wait (100 )
442+
443+ vim .diagnostic .set (ns2 , buf , {
444+ { lnum = 0 , col = 5 , message = " second lsp error" , severity = vim .diagnostic .severity .ERROR },
445+ })
446+
447+ vim .wait (100 )
448+
449+ local cached_before = cache .get (buf )
450+ MiniTest .expect .equality (# cached_before , 2 )
451+
452+ vim .diagnostic .set (ns1 , buf , {
453+ {
454+ lnum = 0 ,
455+ col = 0 ,
456+ message = " updated first lsp error" ,
457+ severity = vim .diagnostic .severity .WARN ,
458+ },
459+ })
460+
461+ vim .wait (100 )
462+
463+ local cached_after = cache .get (buf )
464+ MiniTest .expect .equality (# cached_after , 2 )
465+
466+ local has_first_lsp = false
467+ local has_second_lsp = false
468+ for _ , diag in ipairs (cached_after ) do
469+ if diag .message == " updated first lsp error" then
470+ has_first_lsp = true
471+ end
472+ if diag .message == " second lsp error" then
473+ has_second_lsp = true
474+ end
475+ end
476+
477+ MiniTest .expect .equality (has_first_lsp , true )
478+ MiniTest .expect .equality (has_second_lsp , true )
479+ end )
480+ end
481+
482+ T [" multiple_lsp_diagnostics" ][" clearing one LSP namespace preserves others" ] = function ()
483+ H .with_win_buf ({ " test line" }, { 1 , 0 }, nil , function (buf , win )
484+ local tiny = require (" tiny-inline-diagnostic" )
485+ local cache = require (" tiny-inline-diagnostic.cache" )
486+ tiny .setup (create_test_opts ())
487+
488+ local ns1 = vim .api .nvim_create_namespace (" lsp_x" )
489+ local ns2 = vim .api .nvim_create_namespace (" lsp_y" )
490+ local ns3 = vim .api .nvim_create_namespace (" lsp_z" )
491+
492+ vim .diagnostic .set (ns1 , buf , {
493+ { lnum = 0 , col = 0 , message = " lsp x error" , severity = vim .diagnostic .severity .ERROR },
494+ })
495+
496+ vim .diagnostic .set (ns2 , buf , {
497+ { lnum = 0 , col = 5 , message = " lsp y error" , severity = vim .diagnostic .severity .WARN },
498+ })
499+
500+ vim .diagnostic .set (ns3 , buf , {
501+ { lnum = 0 , col = 10 , message = " lsp z error" , severity = vim .diagnostic .severity .INFO },
502+ })
503+
504+ vim .wait (100 )
505+
506+ local cached_all = cache .get (buf )
507+ MiniTest .expect .equality (# cached_all , 3 )
508+
509+ vim .diagnostic .set (ns2 , buf , {})
510+
511+ vim .wait (100 )
512+
513+ local cached_after_clear = cache .get (buf )
514+ MiniTest .expect .equality (# cached_after_clear , 2 )
515+
516+ local has_ns1 = false
517+ local has_ns2 = false
518+ local has_ns3 = false
519+ for _ , diag in ipairs (cached_after_clear ) do
520+ if diag .message == " lsp x error" then
521+ has_ns1 = true
522+ end
523+ if diag .message == " lsp y error" then
524+ has_ns2 = true
525+ end
526+ if diag .message == " lsp z error" then
527+ has_ns3 = true
528+ end
529+ end
530+
531+ MiniTest .expect .equality (has_ns1 , true )
532+ MiniTest .expect .equality (has_ns2 , false )
533+ MiniTest .expect .equality (has_ns3 , true )
534+ end )
535+ end
536+
537+ T [" multiple_lsp_diagnostics" ][" rapid DiagnosticChanged events preserve all diagnostics" ] = function ()
538+ H .with_win_buf ({ " test line" , " line 2" , " line 3" }, { 1 , 0 }, nil , function (buf , win )
539+ local tiny = require (" tiny-inline-diagnostic" )
540+ local cache = require (" tiny-inline-diagnostic.cache" )
541+ tiny .setup (create_test_opts ())
542+
543+ local namespaces = {}
544+ for i = 1 , 5 do
545+ namespaces [i ] = vim .api .nvim_create_namespace (" rapid_lsp_" .. i )
546+ end
547+
548+ for i , ns in ipairs (namespaces ) do
549+ vim .diagnostic .set (ns , buf , {
550+ {
551+ lnum = (i - 1 ) % 3 ,
552+ col = 0 ,
553+ message = " diagnostic from lsp " .. i ,
554+ severity = vim .diagnostic .severity .ERROR ,
555+ },
556+ })
557+ end
558+
559+ vim .wait (150 )
560+
561+ local cached = cache .get (buf )
562+ MiniTest .expect .equality (# cached , 5 )
563+
564+ for i = 1 , 5 do
565+ local found = false
566+ for _ , diag in ipairs (cached ) do
567+ if diag .message == " diagnostic from lsp " .. i then
568+ found = true
569+ break
570+ end
571+ end
572+ MiniTest .expect .equality (found , true )
573+ end
574+ end )
575+ end
576+
395577return T
0 commit comments