How can I ignore "~/.cargo/registry/src..." in "vim.diagnostic.setqflist()"? #22167
Replies: 1 comment 1 reply
|
So the practical fix is to filter diagnostics on the Neovim side before converting them to quickfix items. Example: local function rust_workspace_diagnostics_qf()
local cargo_registry = vim.fs.normalize(vim.fn.expand("~/.cargo/registry/src"))
local diagnostics = vim.tbl_filter(function(diagnostic)
local name = vim.api.nvim_buf_get_name(diagnostic.bufnr)
if name == "" then
return true
end
local path = vim.fs.normalize(name)
return not vim.startswith(path, cargo_registry)
end, vim.diagnostic.get(nil))
vim.fn.setqflist(vim.diagnostic.toqflist(diagnostics), "r")
vim.cmd.copen()
end
vim.keymap.set("n", "<leader>q", rust_workspace_diagnostics_qf)If you only want diagnostics for the current project, an even stricter version is to keep only paths under The reason your current config does not help is that diagnostics from |


rust-analyzer.files.excludewill not filter whatvim.diagnostic.setqflist()shows. That setting affects files rust-analyzer watches/loads; the quickfix list is built by Neovim from diagnostics it has already received.So the practical fix is to filter diagnostics on the Neovim side before converting them to quickfix items.
Example: