mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	refactor(diagnostic): DRY for loop #21521
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
		| @@ -429,32 +429,31 @@ local function get_diagnostics(bufnr, opts, clamp) | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  |   ---@private | ||||||
|  |   local function add_all_diags(buf, diags) | ||||||
|  |     for _, diagnostic in pairs(diags) do | ||||||
|  |       add(buf, diagnostic) | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  |  | ||||||
|   if namespace == nil and bufnr == nil then |   if namespace == nil and bufnr == nil then | ||||||
|     for b, t in pairs(diagnostic_cache) do |     for b, t in pairs(diagnostic_cache) do | ||||||
|       for _, v in pairs(t) do |       for _, v in pairs(t) do | ||||||
|         for _, diagnostic in pairs(v) do |         add_all_diags(b, v) | ||||||
|           add(b, diagnostic) |  | ||||||
|         end |  | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   elseif namespace == nil then |   elseif namespace == nil then | ||||||
|     bufnr = get_bufnr(bufnr) |     bufnr = get_bufnr(bufnr) | ||||||
|     for iter_namespace in pairs(diagnostic_cache[bufnr]) do |     for iter_namespace in pairs(diagnostic_cache[bufnr]) do | ||||||
|       for _, diagnostic in pairs(diagnostic_cache[bufnr][iter_namespace]) do |       add_all_diags(bufnr, diagnostic_cache[bufnr][iter_namespace]) | ||||||
|         add(bufnr, diagnostic) |  | ||||||
|       end |  | ||||||
|     end |     end | ||||||
|   elseif bufnr == nil then |   elseif bufnr == nil then | ||||||
|     for b, t in pairs(diagnostic_cache) do |     for b, t in pairs(diagnostic_cache) do | ||||||
|       for _, diagnostic in pairs(t[namespace] or {}) do |       add_all_diags(b, t[namespace] or {}) | ||||||
|         add(b, diagnostic) |  | ||||||
|       end |  | ||||||
|     end |     end | ||||||
|   else |   else | ||||||
|     bufnr = get_bufnr(bufnr) |     bufnr = get_bufnr(bufnr) | ||||||
|     for _, diagnostic in pairs(diagnostic_cache[bufnr][namespace] or {}) do |     add_all_diags(bufnr, diagnostic_cache[bufnr][namespace] or {}) | ||||||
|       add(bufnr, diagnostic) |  | ||||||
|     end |  | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if opts.severity then |   if opts.severity then | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Raphael
					Raphael