File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -231,11 +231,32 @@ local linter_proc_mt = {
231231}
232232
233233
234+ --- @param  diagnostics  vim.Diagnostic[] 
234235function  LintProc :publish (diagnostics )
235-   --  By the time the linter is finished the user might have deleted the buffer
236-   if  api .nvim_buf_is_valid (self .bufnr ) and  not  self .cancelled  then 
237-     vim .diagnostic .set (self .ns , self .bufnr , diagnostics )
236+   if  not  self .cancelled  then 
237+     --  A map where the key is the bufnr and the value is a list of all diagnostics
238+     --  in that buffer.
239+     --- @type  table<integer,vim.Diagnostic[]> 
240+     local  buffer_diagnostics  =  {}
241+ 
242+     for  _ , item  in  ipairs (diagnostics ) do 
243+       local  bufnr  =  item .bufnr  or  self .bufnr 
244+ 
245+       if  nil  ==  buffer_diagnostics [bufnr ] then 
246+         buffer_diagnostics [bufnr ] =  {}
247+       end 
248+ 
249+       table.insert (buffer_diagnostics [bufnr ], item )
250+     end 
251+ 
252+     for  buf , diags  in  pairs (buffer_diagnostics ) do 
253+       --  By the time the linter is finished some buffers may be deleted.
254+       if  api .nvim_buf_is_valid (buf ) then 
255+         vim .diagnostic .set (self .ns , buf , diags )
256+       end 
257+     end 
238258  end 
259+ 
239260  self .stdout :shutdown ()
240261  self .stdout :close ()
241262  self .stderr :shutdown ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments