diff options
| author | ache <ache@ache.one> | 2025-05-18 03:34:51 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2025-05-18 03:34:51 +0200 |
| commit | 3268a00c27b1881e7cb26118b4b20fb790cd211f (patch) | |
| tree | 6e108f19cf23d5509517b78f528c24a1a2e45e86 | |
| parent | Update configuration to add LSP nvim 0.11 support (diff) | |
Correct cmd validation
| -rw-r--r-- | lua/ache/lazy.lua | 98 | ||||
| -rw-r--r-- | lua/ache/plugins/nvim-cmp.lua | 2 |
2 files changed, 99 insertions, 1 deletions
diff --git a/lua/ache/lazy.lua b/lua/ache/lazy.lua index e92b092..be9ad75 100644 --- a/lua/ache/lazy.lua +++ b/lua/ache/lazy.lua @@ -12,6 +12,11 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then }) end +-- NOTE: Refer to :h vim.lsp.config() for more information. +vim.lsp.config("*", { + capabilities = vim.lsp.protocol.make_client_capabilities(), +}) + vim.opt.rtp:prepend(lazypath) require("lazy").setup({ @@ -63,3 +68,96 @@ require("lazy").setup({ }, }, }) -- Will list every Lua file in the directory and load them. + +-- LSP config + +vim.lsp.enable("pyright") +vim.lsp.enable("rust_analyzer") +vim.lsp.enable("lua_ls") +vim.lsp.enable("clangd") +vim.lsp.enable("gopls") +vim.lsp.enable("html") +vim.lsp.enable("cssls") + +local capabilities = require("cmp_nvim_lsp").default_capabilities() +vim.lsp.config("*", { + capabilities = capabilities, +}) + +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(args) + --[[ + local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) + if client:supports_method("textDocument/implementation") then + -- Create a keymap for vim.lsp.buf.implementation ... + end + -- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y| + if client:supports_method("textDocument/completion") then + -- Optional: trigger autocompletion on EVERY keypress. May be slow! + -- local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end + -- client.server_capabilities.completionProvider.triggerCharacters = chars + vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) + end + -- Auto-format ("lint") on save. + -- Usually not needed if server supports "textDocument/willSaveWaitUntil". + if + not client:supports_method("textDocument/willSaveWaitUntil") + and client:supports_method("textDocument/formatting") + then + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("UserLspConfig", { clear = false }), + buffer = args.buf, + callback = function() + vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) + end, + }) + end + --]] + + local map = function(keys, func, desc) + vim.keymap.set("n", keys, func, { buffer = args.buf, desc = "Lsp: " .. desc }) + end + + local tele_defs_action = "<cmd>Telescope lsp_definitions<CR>" + local tele_impl_action = "<cmd>Telescope lsp_implementations<CR>" + local tele_typedefs_action = "<cmd>Telescope lsp_type_definitions<CR>" + local tele_diag_action = "<cmd>Telescope diagnostics bufnr=0<CR>" + + local tele = require("telescope.builtin") + -- map("g", tele.lsp_definitions, "Goto Definition") + map("<leader>ls", tele.lsp_document_symbols, "Doc Symbols") + map("<leader>lS", tele.lsp_dynamic_workspace_symbols, "Dynamic Symbols") + -- map("<leader>fh", tele.lsp_dynamic_help, "Help") + map("<leader>lr", tele.lsp_references, "Goto References") + map("<leader>li", tele.lsp_implementations, "Goto Implementations") + + map("K", vim.lsp.buf.hover, "Show documentation") + map("<leader>E", vim.diagnostic.open_float, "Open Diagnostics") + map("<leader>k", vim.lsp.buf.signature_help, "Signature Help") + map("<leader>rn", vim.lsp.buf.rename, "Rename") + map("<leader>f", vim.lsp.buf.format, "Format") + + map("<leader>gR", "<cmd>Telescope lsp_references<CR>", "Show LSP references") + map("<leader>gD", vim.lsp.buf.declaration, "Go to declaration") + map("<leader>gd", tele_defs_action, "Show LSP definitions") + map("<leader>gi", tele_impl_action, "Show LSP implementations") + map("<leader>gt", tele_typedefs_action, "Show LSP type definitions") + + map("<leader>D", tele_diag_action, "Show buffer diagnostics") + map("<leader>d", vim.diagnostic.open_float, "Show line diagnostics") + map("<leader><d", vim.diagnostic.goto_prev, "Go to previous diagnostic") + map("<leader>>d", vim.diagnostic.goto_next, "Go to next diagnostic") + map("<leader>rs", "<cmd>LspRestart<CR>", "Restart LSP") + + map("<leader>ss", "<cmd>LspStop harper_ls<CR>", "Stop harper-ls, The spell checking plugin") + map("<leader>sS", "<cmd>LspRestart harper_ls<CR>", "(Re)-start harper-ls, The spell checking plugin") + + vim.keymap.set( + { "n", "v" }, + "<leader>ca", + vim.lsp.buf.code_action, + { buffer = args.buf, desc = "Lsp: See available code actions" } + ) + end, +}) diff --git a/lua/ache/plugins/nvim-cmp.lua b/lua/ache/plugins/nvim-cmp.lua index 8523d72..b6918ef 100644 --- a/lua/ache/plugins/nvim-cmp.lua +++ b/lua/ache/plugins/nvim-cmp.lua @@ -143,7 +143,7 @@ return { cmp.setup.cmdline(":", { -- mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline({ - ["<CR>"] = { + ["<S-CR>"] = { c = function(default) if cmp.visible() then return cmp.confirm({ select = true }) |