Move some LSP keymaps out of LspAttach event

Jump to dianostic locations can be used for nvim-lint, for example.
This commit is contained in:
Hoang Nguyen 2024-01-06 00:00:00 +07:00
parent ba1990d45b
commit 2639ec991e
Signed by: folliehiyuki
GPG Key ID: B0567C20730E9B11
6 changed files with 31 additions and 28 deletions

View File

@ -3,7 +3,7 @@
"SchemaStore.nvim": { "branch": "main", "commit": "7ccffe69a8c24fcd8637788955e13d7fd8aa2f46" },
"aerial.nvim": { "branch": "master", "commit": "e2e3bc2df4490690ea005395eecdc8eeb30c4def" },
"alpha-nvim": { "branch": "main", "commit": "29074eeb869a6cbac9ce1fbbd04f5f5940311b32" },
"better-escape.nvim": { "branch": "master", "commit": "2d75c375e93ce58b07826a0575a5a33fd2cebbda" },
"better-escape.nvim": { "branch": "master", "commit": "d62cf3c04163a46f3895c70cc807f5ae68dd8ca1" },
"carbon-now.nvim": { "branch": "main", "commit": "16e843489ba00493466170919abfe144fc9aa158" },
"ccc.nvim": { "branch": "main", "commit": "ec6e23fd2c0bf4ffcf71c1271acdcee6e2c6f49c" },
"cmp-async-path": { "branch": "main", "commit": "d8229a93d7b71f22c66ca35ac9e6c6cd850ec61d" },
@ -16,7 +16,7 @@
"dial.nvim": { "branch": "master", "commit": "27eb570085db2ef44bff4f620d3806039184651c" },
"diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" },
"dressing.nvim": { "branch": "master", "commit": "94b0d24483d56f3777ee0c8dc51675f21709318c" },
"emmylua-nvim": { "branch": "master", "commit": "71837746d9972dda066c490ae2ae4f2a1c771a02" },
"emmylua-nvim": { "branch": "master", "commit": "4004329f332c442513991b9f91b9bc902a9b7e22" },
"flash.nvim": { "branch": "main", "commit": "48817af25f51c0590653bbc290866e4890fe1cbe" },
"friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
"git-conflict.nvim": { "branch": "main", "commit": "690879ba23741f21646e97ba287333ff56137c4d" },
@ -56,26 +56,26 @@
"nvim-dap-ui": { "branch": "master", "commit": "7e5e16427aaf814dc2d58e1b219def9ef2fa2435" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "d4542ac257d3c7ee4131350db6179ae6340ce40b" },
"nvim-lint": { "branch": "master", "commit": "d44185d3e57e00c164485a454174294b36ef7067" },
"nvim-lspconfig": { "branch": "master", "commit": "ce0e625df61be77abe1340fbc9afe9ad39b31dd8" },
"nvim-lspconfig": { "branch": "master", "commit": "796394fd19fb878e8dbc4fd1e9c9c186ed07a5f4" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
"nvim-notify": { "branch": "master", "commit": "1576123bff3bed67bc673a3076e591abfe5d8ca9" },
"nvim-scrollbar": { "branch": "main", "commit": "35f99d559041c7c0eff3a41f9093581ceea534e8" },
"nvim-spectre": { "branch": "master", "commit": "d8906855f1949ac97b1e77aaf8d3fe12ed158ddc" },
"nvim-tree.lua": { "branch": "master", "commit": "f1b3e6a7eb92da492bd693257367d9256839ed3d" },
"nvim-tree.lua": { "branch": "master", "commit": "6a99f5af78b5dd531d49ec0a5158dd0f9a7c992b" },
"nvim-treesitter": { "branch": "master", "commit": "49f1b9a7efc794be143f7ddcd60ce18e8164a7f8" },
"nvim-treesitter-context": { "branch": "master", "commit": "652ec514d6ba8bc4a3c2de76c855fe668e2c7196" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "85b9d0cbd4ff901abcda862b50dbb34e0901848b" },
"nvim-ts-autotag": { "branch": "main", "commit": "8515e48a277a2f4947d91004d9aa92c29fdc5e18" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "1277b4a1f451b0f18c0790e1a7f12e1e5fdebfee" },
"nvim-web-devicons": { "branch": "master", "commit": "3e24abe1ae66532135cec911562f553fe247cb56" },
"orgmode": { "branch": "master", "commit": "9ada64e05c1d0ea5c373c2d69cf2e5b5017b311c" },
"nvim-web-devicons": { "branch": "master", "commit": "db0c864375c198cacc171ff373e76bfce2a85045" },
"orgmode": { "branch": "master", "commit": "c60cf77031a5a9a3c590c6f7b876bc7117603e57" },
"overseer.nvim": { "branch": "master", "commit": "78e893394cef6efee05f31bd65f6dff08b0bac09" },
"pantran.nvim": { "branch": "main", "commit": "461799624948bfb66f73b20b6fffa7e4c8ca6d08" },
"parinfer-rust": { "branch": "master", "commit": "0e4d52e712641ad351a1bfe6cee3d34d63ed087b" },
"persistence.nvim": { "branch": "main", "commit": "ad538bfd5336f1335cdb6fd4e0b0eebfa6e12f32" },
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
"project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" },
"rainbow-delimiters.nvim": { "branch": "master", "commit": "4a90ac83c7c8e0ba8a1b6af38bed6d5ee1b04e08" },
"rainbow-delimiters.nvim": { "branch": "master", "commit": "f7a55274a74053ccfafc24005b6f46303d543288" },
"rest.nvim": { "branch": "main", "commit": "84e81a19ab24ccf05c9233d34d4dfce61c233abe" },
"scope.nvim": { "branch": "main", "commit": "cd27af77ad61a7199af5c28d27013fb956eb0e3e" },
"sniprun": { "branch": "master", "commit": "551f5839c1ccc8b4d3143ae03f58757d3047e391" },

View File

@ -46,6 +46,24 @@ if not util.has('trouble.nvim') then
map('n', ']q', vim.cmd.cnext, { desc = 'Next quickfix' })
end
-- LSP keymaps that can be used without an LSP server attached to the buffer (.e.g with nvim-lint)
local diagnostic_goto = function(next, severity)
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
severity = severity and vim.diagnostic.severity[severity] or nil
return function()
go { severity = severity }
end
end
map('n', '<leader>le', vim.diagnostic.open_float, { desc = 'Line diagnostic' })
map('n', '<leader>ld', '<cmd>Trouble document_diagnostics<CR>', { desc = 'Document diagnostics' })
map('n', '<leader>lw', '<cmd>Trouble workspace_diagnostics<CR>', { desc = 'Workspace diagnostics' })
map('n', ']d', diagnostic_goto(true), { desc = 'Next diagnostic' })
map('n', '[d', diagnostic_goto(false), { desc = 'Previous diagnostic' })
map('n', ']e', diagnostic_goto(true, 'ERROR'), { desc = 'Next error' })
map('n', '[e', diagnostic_goto(false, 'ERROR'), { desc = 'Previous error' })
map('n', ']w', diagnostic_goto(true, 'WARN'), { desc = 'Next warning' })
map('n', '[w', diagnostic_goto(false, 'WARN'), { desc = 'Previous warning' })
-- toggle LSP settings
map('n', '<leader>ud', require('user.plugins.lsp.lspconfig.diagnostic').toggle, { desc = 'Toggle diagnostics' })
map('n', '<leader>uv', require('user.plugins.lsp.lspconfig.diagnostic').toggle_virtual_lines, { desc = 'Toggle virtual lines diagnostics' })

View File

@ -22,6 +22,7 @@ return {
lua = { 'stylua' },
c = { 'clang_format' },
cpp = { 'clang_format' },
-- rego = { 'opa_fmt' },
-- ['*'] = { 'codespell' },
},
formatters = {

View File

@ -15,7 +15,8 @@ return {
},
-- org = { 'proselint' },
-- asciidoc = { 'proselint' },
proto = { 'buf' },
proto = { 'buf_lint' },
-- rego = { 'opa_check', 'regal' },
sql = { 'sqlfluff' },
['*'] = { 'codespell', 'cspell' },
},

View File

@ -5,12 +5,8 @@ M._keys = nil
function M.get()
if not M._keys then
M._keys = {
{ '<leader>le', vim.diagnostic.open_float, desc = 'Line diagnostic' },
{ '<leader>la', vim.lsp.buf.code_action, desc = 'Code action', mode = { 'n', 'x' }, has = 'codeAction' },
{ '<leader>ll', vim.lsp.codelens.run, desc = 'Codelens action', mode = 'n', has = 'codeLens' },
{ '<leader>ld', '<cmd>Trouble document_diagnostics<CR>', desc = 'Document diagnostics' },
{ '<leader>lw', '<cmd>Trouble workspace_diagnostics<CR>', desc = 'Workspace diagnostics' },
{ 'gd', '<cmd>Trouble lsp_definitions<CR>', desc = 'Goto definition', has = 'definition' },
{ 'gr', '<cmd>Trouble lsp_references<CR>', desc = 'References' },
{ 'gD', vim.lsp.buf.declaration, desc = 'Goto declaration' },
@ -19,12 +15,6 @@ function M.get()
{ 'K', vim.lsp.buf.hover, desc = 'Hover' },
{ 'gK', vim.lsp.buf.signature_help, desc = 'Signature help', has = 'signatureHelp' },
{ '<C-k>', vim.lsp.buf.signature_help, mode = 'i', desc = 'Signature help', has = 'signatureHelp' },
{ ']d', M.diagnostic_goto(true), desc = 'Next diagnostic' },
{ '[d', M.diagnostic_goto(false), desc = 'Previous diagnostic' },
{ ']e', M.diagnostic_goto(true, 'ERROR'), desc = 'Next error' },
{ '[e', M.diagnostic_goto(false, 'ERROR'), desc = 'Previous error' },
{ ']w', M.diagnostic_goto(true, 'WARN'), desc = 'Next warning' },
{ '[w', M.diagnostic_goto(false, 'WARN'), desc = 'Previous warning' },
}
if require('user.util.misc').has('inc-rename.nvim') then
@ -67,12 +57,4 @@ function M.on_attach(client, buffer)
end
end
function M.diagnostic_goto(next, severity)
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
severity = severity and vim.diagnostic.severity[severity] or nil
return function()
go { severity = severity }
end
end
return M

View File

@ -27,6 +27,7 @@ end
return {
beancount = { init_options = { journalFile = os.getenv('HOME') .. '/Documents/Ledger/ledger.beancount' } },
clangd = {
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
keys = {
{ '<localleader>h', '<cmd>ClangdSwitchSourceHeader<CR>', mode = 'n', desc = 'Switch source header' },
},
@ -202,7 +203,7 @@ return {
-- },
-- },
-- volar = {
-- { cmd = { servers_path .. '/volar/node_modules/.bin/vue-language-server', '--stdio' } },
-- cmd = { servers_path .. '/volar/node_modules/.bin/vue-language-server', '--stdio' },
-- filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
-- on_new_config = function(config, root_dir)
-- local lsputil = require('lspconfig.util')
@ -243,7 +244,7 @@ return {
nickel_ls = {},
-- pylyzer = {},
qmlls = {}, -- from qt6-qtdeclarative-dev package in Alpine
regols = {},
-- regols = {},
biome = {},
taplo = {},
terraformls = {},