|
| 1 | +local M = {} |
| 2 | + |
| 3 | +for _, mode in ipairs { "", "n", "v", "x", "s", "o", "!", "i", "l", "c", "t" } do |
| 4 | + M[mode] = {} |
| 5 | +end |
| 6 | +if vim.fn.has "nvim-0.10.0" == 1 then |
| 7 | + for _, abbr_mode in ipairs { "ia", "ca", "!a" } do |
| 8 | + M[abbr_mode] = {} |
| 9 | + end |
| 10 | +end |
| 11 | + |
| 12 | +M.n["<leader>ld"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" } |
| 13 | +M.n["[d"] = { function() vim.diagnostic.goto_prev() end, desc = "Previous diagnostic" } |
| 14 | +M.n["]d"] = { function() vim.diagnostic.goto_next() end, desc = "Next diagnostic" } |
| 15 | +M.n["gl"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" } |
| 16 | + |
| 17 | +M.n["<leader>lD"] = { |
| 18 | + function() require("telescope.builtin").diagnostics() end, |
| 19 | + desc = "Search diagnostics", |
| 20 | + cond = function(_, _) return true end, -- client, bufnr parameters |
| 21 | +} |
| 22 | + |
| 23 | +M.n["<leader>la"] = { |
| 24 | + function() vim.lsp.buf.code_action() end, |
| 25 | + desc = "LSP code action", |
| 26 | + cond = "testDocument/codeAction", -- LSP client capability string |
| 27 | +} |
| 28 | +M.v["<leader>la"] = M.n["<leader>la"] |
| 29 | + |
| 30 | +M.n["<leader>ll"] = |
| 31 | + { function() vim.lsp.codelens.refresh() end, desc = "LSP CodeLens refresh", cond = "textDocument/codeLens" } |
| 32 | +M.n["<leader>lL"] = { function() vim.lsp.codelens.run() end, desc = "LSP CodeLens run", cond = "textDocument/codeLens" } |
| 33 | + |
| 34 | +M.n["gD"] = { |
| 35 | + function() vim.lsp.buf.declaration() end, |
| 36 | + desc = "Declaration of current symbol", |
| 37 | + cond = "textDocument/declaration", |
| 38 | +} |
| 39 | +M.n["gd"] = { |
| 40 | + function() vim.lsp.buf.definition() end, |
| 41 | + desc = "Show the definition of current symbol", |
| 42 | + cond = "textDocument/definition", |
| 43 | +} |
| 44 | + |
| 45 | +-- TODO: Add proper conditions |
| 46 | +M.n["<leader>lf"] = { function() vim.lsp.buf.format(M.format_opts) end, desc = "Format buffer" } |
| 47 | +M.v["<leader>lf"] = M.n["<leader>lf"] |
| 48 | +M.n["<leader>uf"] = |
| 49 | + { function() require("astronvim.utils.ui").toggle_buffer_autoformat() end, desc = "Toggle autoformatting (buffer)" } |
| 50 | +M.n["<leader>uF"] = |
| 51 | + { function() require("astronvim.utils.ui").toggle_autoformat() end, desc = "Toggle autoformatting (global)" } |
| 52 | + |
| 53 | +M.n["K"] = { function() vim.lsp.buf.hover() end, desc = "Hover symbol details", cond = "textDocument/hover" } |
| 54 | + |
| 55 | +M.n["gI"] = { |
| 56 | + function() vim.lsp.buf.implementation() end, |
| 57 | + desc = "Implementation of current symbol", |
| 58 | + cond = "textDocument/implementation", |
| 59 | +} |
| 60 | + |
| 61 | +-- TODO: add proper conditions |
| 62 | +M.n["<leader>uH"] = { |
| 63 | + function() |
| 64 | + vim.b.inlay_hints_enabled = not vim.b.inlay_hints_enabled |
| 65 | + -- TODO: remove check after dropping support for Neovim v0.9 |
| 66 | + if vim.lsp.inlay_hint then |
| 67 | + vim.lsp.inlay_hint(0, vim.b.inlay_hints_enabled) |
| 68 | + vim.notify(("Inlay hints %s"):format(vim.b.inlay_hints_enabled and "on" or "off")) |
| 69 | + end |
| 70 | + end, |
| 71 | + desc = "Toggle LSP inlay hints (buffer)", |
| 72 | +} |
| 73 | + |
| 74 | +M.n["gr"] = |
| 75 | + { function() vim.lsp.buf.references() end, desc = "References of current symbol", cond = "textDocument/references" } |
| 76 | +M.n["<leader>lR"] = |
| 77 | + { function() vim.lsp.buf.references() end, desc = "Search references", cond = "textDocument/references" } |
| 78 | + |
| 79 | +M.n["<leader>lr"] = |
| 80 | + { function() vim.lsp.buf.rename() end, desc = "Rename current symbol", cond = "textDocument/rename" } |
| 81 | + |
| 82 | +M.n["<leader>lh"] = |
| 83 | + { function() vim.lsp.buf.signature_help() end, desc = "Signature help", cond = "textDocument/signatureHelp" } |
| 84 | + |
| 85 | +M.n["gT"] = { |
| 86 | + function() vim.lsp.buf.type_definition() end, |
| 87 | + desc = "Definition of current type", |
| 88 | + cond = "textDocument/typeDefinition", |
| 89 | +} |
| 90 | + |
| 91 | +M.n["<leader>lG"] = |
| 92 | + { function() vim.lsp.buf.workspace_symbol() end, desc = "Search workspace symbols", cond = "workspace/symbol" } |
| 93 | + |
| 94 | +M.n["<leader>uY"] = { |
| 95 | + function() |
| 96 | + vim.b.semantic_tokens_enabled = not vim.b.semantic_tokens_enabled |
| 97 | + for _, client in ipairs(vim.lsp.get_active_clients()) do |
| 98 | + if client.server_capabilities.semanticTokensProvider then |
| 99 | + vim.lsp.semantic_tokens[vim.b.semantic_tokens_enabled and "start" or "stop"](0, client.id) |
| 100 | + vim.notify(("Buffer lsp semantic highlighting %s"):format(vim.b.semantic_tokens_enabled and "on" or "off")) |
| 101 | + end |
| 102 | + end |
| 103 | + end, |
| 104 | + desc = "Toggle LSP semantic highlight (buffer)", |
| 105 | + cond = "textDocument/semanticTokens/full", |
| 106 | +} |
| 107 | + |
| 108 | +if not vim.tbl_isempty(M.v) then M.v["<leader>l"] = { desc = " LSP" } end |
| 109 | + |
| 110 | +-- if is_available "telescope.nvim" then |
| 111 | +-- lsp_mappings.n["<leader>lD"] = |
| 112 | +-- { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" } |
| 113 | +-- end |
| 114 | +-- |
| 115 | +-- if is_available "mason-lspconfig.nvim" then |
| 116 | +-- lsp_mappings.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" } |
| 117 | +-- end |
| 118 | +-- |
| 119 | +-- if is_available "null-ls.nvim" then |
| 120 | +-- lsp_mappings.n["<leader>lI"] = { "<cmd>NullLsInfo<cr>", desc = "Null-ls information" } |
| 121 | +-- end |
| 122 | + |
| 123 | +-- if is_available "telescope.nvim" then -- setup telescope mappings if available |
| 124 | +-- if lsp_mappings.n.gd then lsp_mappings.n.gd[1] = function() require("telescope.builtin").lsp_definitions() end end |
| 125 | +-- if lsp_mappings.n.gI then |
| 126 | +-- lsp_mappings.n.gI[1] = function() require("telescope.builtin").lsp_implementations() end |
| 127 | +-- end |
| 128 | +-- if lsp_mappings.n.gr then lsp_mappings.n.gr[1] = function() require("telescope.builtin").lsp_references() end end |
| 129 | +-- if lsp_mappings.n["<leader>lR"] then |
| 130 | +-- lsp_mappings.n["<leader>lR"][1] = function() require("telescope.builtin").lsp_references() end |
| 131 | +-- end |
| 132 | +-- if lsp_mappings.n.gT then |
| 133 | +-- lsp_mappings.n.gT[1] = function() require("telescope.builtin").lsp_type_definitions() end |
| 134 | +-- end |
| 135 | +-- if lsp_mappings.n["<leader>lG"] then |
| 136 | +-- lsp_mappings.n["<leader>lG"][1] = function() |
| 137 | +-- vim.ui.input({ prompt = "Symbol Query: " }, function(query) |
| 138 | +-- if query then require("telescope.builtin").lsp_workspace_symbols { query = query } end |
| 139 | +-- end) |
| 140 | +-- end |
| 141 | +-- end |
| 142 | +-- end |
| 143 | + |
| 144 | +return M |
0 commit comments