diff options
| author | jdhao <jdhao@hotmail.com> | 2023-07-22 14:57:43 +0200 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2023-07-22 15:01:41 +0200 |
| commit | fc8175d32d0261393b184001b04109c8257609d1 (patch) | |
| tree | 79e45c70824840ce9ca5b41f3959179552eadfe6 /lua/config/lsp.lua | |
| parent | 4034b6b6731bcd9e575c2faea46b350c73965cd9 (diff) | |
feat: update diagnostic mappings
Use separate key mappings to show diagnostics for the current buffer and
all opened files.
Diffstat (limited to 'lua/config/lsp.lua')
| -rw-r--r-- | lua/config/lsp.lua | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index be4fd33..728455a 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -6,6 +6,18 @@ local diagnostic = vim.diagnostic local utils = require("utils") +-- set quickfix list from diagnostics in a certain buffer, not the whole workspace +local set_qflist = function(buf_num, severity) + local diagnostics = nil + diagnostics = diagnostic.get(buf_num, { severity = severity }) + + local qf_items = diagnostic.toqflist(diagnostics) + vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items }) + + -- open quickfix by default + vim.cmd[[copen]] +end + local custom_attach = function(client, bufnr) -- Mappings. local map = function(mode, l, r, opts) @@ -23,7 +35,10 @@ local custom_attach = function(client, bufnr) map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" }) map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" }) - map("n", "<space>q", diagnostic.setqflist, { desc = "put diagnostic to qf" }) + -- this puts diagnostics from opened files to quickfix + map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) + -- this puts diagnostics from current buffer to quickfix + map("n", "<space>qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" }) map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) |
