@@ -1249,10 +1249,10 @@ function M.reset(client_id, buffer_client_map)
1249
1249
end )
1250
1250
end
1251
1251
1252
- --- Sets the location list
1252
+ --- Gets diagnostics, converts them to quickfix/location list items, and applies the item_handler callback to the items.
1253
+ --- @param item_handler function Callback to apply to the diagnostic items
1254
+ --- @param command string | nil Command to execute after applying the item_handler
1253
1255
--- @param opts table | nil Configuration table. Keys :
1254
- --- - {open_loclist}: (boolean, default true)
1255
- --- - Open loclist after set
1256
1256
--- - {client_id}: (number)
1257
1257
--- - If nil, will consider all clients attached to buffer.
1258
1258
--- - {severity}: (DiagnosticSeverity)
@@ -1261,9 +1261,8 @@ end
1261
1261
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
1262
1262
--- - {workspace}: (boolean, default false)
1263
1263
--- - Set the list with workspace diagnostics
1264
- function M . set_loclist ( opts )
1264
+ local function apply_to_diagnostic_items ( item_handler , command , opts )
1265
1265
opts = opts or {}
1266
- local open_loclist = if_nil (opts .open_loclist , true )
1267
1266
local current_bufnr = api .nvim_get_current_buf ()
1268
1267
local diags = opts .workspace and M .get_all (opts .client_id ) or {
1269
1268
[current_bufnr ] = M .get (current_bufnr , opts .client_id )
@@ -1280,13 +1279,51 @@ function M.set_loclist(opts)
1280
1279
return true
1281
1280
end
1282
1281
local items = util .diagnostics_to_items (diags , predicate )
1283
- local win_id = vim .api .nvim_get_current_win ()
1284
- util .set_loclist (items , win_id )
1285
- if open_loclist then
1286
- vim .cmd [[ lopen]]
1282
+ item_handler (items )
1283
+ if command then
1284
+ vim .cmd (command )
1287
1285
end
1288
1286
end
1289
1287
1288
+ --- Sets the quickfix list
1289
+ --- @param opts table | nil Configuration table. Keys :
1290
+ --- - {open}: (boolean, default true)
1291
+ --- - Open quickfix list after set
1292
+ --- - {client_id}: (number)
1293
+ --- - If nil, will consider all clients attached to buffer.
1294
+ --- - {severity}: (DiagnosticSeverity)
1295
+ --- - Exclusive severity to consider. Overrides {severity_limit}
1296
+ --- - {severity_limit}: (DiagnosticSeverity)
1297
+ --- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
1298
+ --- - {workspace}: (boolean, default true)
1299
+ --- - Set the list with workspace diagnostics
1300
+ function M .set_qflist (opts )
1301
+ opts = opts or {}
1302
+ opts .workspace = if_nil (opts .workspace , true )
1303
+ local open_qflist = if_nil (opts .open , true )
1304
+ local command = open_qflist and [[ copen]] or nil
1305
+ apply_to_diagnostic_items (util .set_qflist , command , opts )
1306
+ end
1307
+
1308
+ --- Sets the location list
1309
+ --- @param opts table | nil Configuration table. Keys :
1310
+ --- - {open}: (boolean, default true)
1311
+ --- - Open loclist after set
1312
+ --- - {client_id}: (number)
1313
+ --- - If nil, will consider all clients attached to buffer.
1314
+ --- - {severity}: (DiagnosticSeverity)
1315
+ --- - Exclusive severity to consider. Overrides {severity_limit}
1316
+ --- - {severity_limit}: (DiagnosticSeverity)
1317
+ --- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
1318
+ --- - {workspace}: (boolean, default false)
1319
+ --- - Set the list with workspace diagnostics
1320
+ function M .set_loclist (opts )
1321
+ opts = opts or {}
1322
+ local open_loclist = if_nil (opts .open , true )
1323
+ local command = open_loclist and [[ lopen]] or nil
1324
+ apply_to_diagnostic_items (util .set_loclist , command , opts )
1325
+ end
1326
+
1290
1327
--- Disable diagnostics for the given buffer and client
1291
1328
--- @param bufnr (optional , number ): Buffer handle , defaults to current
1292
1329
--- @param client_id (optional , number ): Disable diagnostics for the given
0 commit comments