From 407f9c2c9647fb8ae7d0eb509563981762e6aa53 Mon Sep 17 00:00:00 2001 From: ignuki Date: Sat, 29 Mar 2025 13:54:48 +0100 Subject: [PATCH] update nvim config for 0.11 --- README.md | 1 + nvim/.config/nvim/.luacheckrc | 6 ++ nvim/.config/nvim/lsp/lua.lua | 12 ---- nvim/.config/nvim/lsp/luals.lua | 17 ++++++ nvim/.config/nvim/lua/ink/init.lua | 8 ++- nvim/.config/nvim/lua/ink/lsp.lua | 72 ++++++++++++++++------- nvim/.config/nvim/lua/ink/tabline.lua | 2 +- nvim/.config/nvim/lua/plugins/linting.lua | 7 +++ 8 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 nvim/.config/nvim/.luacheckrc delete mode 100644 nvim/.config/nvim/lsp/lua.lua create mode 100644 nvim/.config/nvim/lsp/luals.lua diff --git a/README.md b/README.md index ed14780..911a3d7 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ - tmux - tmux-plugin-manager - neovim +- lua-language-server - stylua - luacheck - prettier diff --git a/nvim/.config/nvim/.luacheckrc b/nvim/.config/nvim/.luacheckrc new file mode 100644 index 0000000..1d8367d --- /dev/null +++ b/nvim/.config/nvim/.luacheckrc @@ -0,0 +1,6 @@ +globals = { + "vim", +} +read_globals = { + "Snacks", +} diff --git a/nvim/.config/nvim/lsp/lua.lua b/nvim/.config/nvim/lsp/lua.lua deleted file mode 100644 index 13f1d07..0000000 --- a/nvim/.config/nvim/lsp/lua.lua +++ /dev/null @@ -1,12 +0,0 @@ -return { - cmd = { "lua-language-server" }, - root_markers = { ".luarc.json", ".luarc.jsonc" }, - filetypes = { "lua" }, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - }, - }, - }, -} diff --git a/nvim/.config/nvim/lsp/luals.lua b/nvim/.config/nvim/lsp/luals.lua new file mode 100644 index 0000000..84fe9ee --- /dev/null +++ b/nvim/.config/nvim/lsp/luals.lua @@ -0,0 +1,17 @@ +return { + cmd = { "lua-language-server" }, + root_markers = { ".luarc.json", ".luarc.jsonc" }, + filetypes = { "lua" }, + settings = { + Lua = { + completion = { callSnippet = "Both" }, + hint = { enable = true }, + workspace = { + library = { + vim.env.VIMRUNTIME, + }, + }, + runtime = { version = "LuaJIT" }, + }, + }, +} diff --git a/nvim/.config/nvim/lua/ink/init.lua b/nvim/.config/nvim/lua/ink/init.lua index a30e5bd..79e3e72 100644 --- a/nvim/.config/nvim/lua/ink/init.lua +++ b/nvim/.config/nvim/lua/ink/init.lua @@ -15,7 +15,9 @@ vim.w.signcolumn = "yes" -- Keep signcolumn on by default vim.opt.updatetime = 250 -- Decrease update time vim.opt.timeoutlen = 300 -- time to wait for a mapped sequence to complete (in milliseconds) vim.opt.backup = false -- creates a backup file -vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited +-- if a file is being edited by another program (or was written to file while editing with another program), it is not +-- allowed to be edited +vim.opt.writebackup = false vim.opt.completeopt = "menuone,noselect" -- Set completeopt to have a better completion experience vim.opt.termguicolors = true -- set termguicolors to enable highlight groups vim.opt.whichwrap = "bs<>[]hl" -- which "horizontal" keys are allowed to travel to prev/next line @@ -43,7 +45,9 @@ vim.opt.autoindent = true vim.opt.shortmess:append("c") -- don't give |ins-completion-menu| messages vim.opt.iskeyword:append("-") -- hyphenated words recognized by searches -vim.opt.formatoptions:remove({ "c", "r", "o" }) -- don't insert the current comment leader automatically for auto-wrapping comments using 'textwidth', hitting in insert mode, or hitting 'o' or 'O' in normal mode. +-- don't insert the current comment leader automatically for auto-wrapping comments using 'textwidth', hitting +-- in insert mode, or hitting 'o' or 'O' in normal mode. +vim.opt.formatoptions:remove({ "c", "r", "o" }) vim.opt.runtimepath:remove("/usr/share/vim/vimfiles") -- separate vim plugins from neovim in case vim still in use vim.opt.foldmethod = "expr" diff --git a/nvim/.config/nvim/lua/ink/lsp.lua b/nvim/.config/nvim/lua/ink/lsp.lua index 207911f..f21f4f5 100644 --- a/nvim/.config/nvim/lua/ink/lsp.lua +++ b/nvim/.config/nvim/lua/ink/lsp.lua @@ -1,3 +1,4 @@ +--- [[ LSP setup]] vim.lsp.config("*", { capabilities = { textDocument = { @@ -6,37 +7,68 @@ vim.lsp.config("*", { }, }, }, - root_markers = { ".git" }, -}) - -vim.lsp.config("lua", { - filetypes = { "lua" }, }) vim.lsp.config("rust", { filetypes = { "rust" }, }) -vim.lsp.enable("lua") +vim.lsp.enable("luals") vim.lsp.enable("rust") --- vim.lsp.completion.enable(true) + +---[[AUTOCOMPLETION SETUP +vim.o.completeopt = "menuone,noinsert,popup,fuzzy" vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("my.lsp", {}), 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 - + client.server_capabilities.completionProvider.triggerCharacters = vim.split("qwertyuiopasdfghjklzxcvbnm. ", "") + vim.api.nvim_create_autocmd({ "TextChangedI" }, { + buffer = args.buf, + callback = function() + vim.lsp.completion.get() + end, + }) + -- if client:supports_method("textDocument/implementation") then + -- Create a keymap for vim.lsp.buf.implementation ... + -- end if client.server_capabilities.inlayHintProvider then - vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + vim.lsp.inlay_hint.enable(true, { bufnr = vim.fn.bufnr() }) end + vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) + --- + ---[[Code required to add documentation popup for an item + local _, cancel_prev = nil, function() end + vim.api.nvim_create_autocmd("CompleteChanged", { + buffer = args.buf, + callback = function() + if client:supports_method("textDocument/implementation") then + cancel_prev() + local info = vim.fn.complete_info({ "selected" }) + local completionItem = + vim.tbl_get(vim.v.completed_item, "user_data", "nvim", "lsp", "completion_item") + if nil == completionItem then + return + end + _, cancel_prev = vim.lsp.buf_request( + args.buf, + vim.lsp.protocol.Methods.completionItem_resolve, + completionItem, + function(err, item, ctx) + if not item then + return + end + local docs = (item.documentation or {}).value + local win = vim.api.nvim__complete_set(info["selected"], { info = docs }) + if win.winid and vim.api.nvim_win_is_valid(win.winid) then + vim.treesitter.start(win.bufnr, "markdown") + vim.wo[win.winid].conceallevel = 3 + end + end + ) + end + end, + }) + ---]] end, }) +---AUTOCOMPLETION SETUP END]] diff --git a/nvim/.config/nvim/lua/ink/tabline.lua b/nvim/.config/nvim/lua/ink/tabline.lua index c0c821d..c5b450d 100644 --- a/nvim/.config/nvim/lua/ink/tabline.lua +++ b/nvim/.config/nvim/lua/ink/tabline.lua @@ -18,7 +18,7 @@ local function filestatus() return "" end -TabLine = function() +function _G.TabLine() return table.concat({ tab_info(), filestatus(), diff --git a/nvim/.config/nvim/lua/plugins/linting.lua b/nvim/.config/nvim/lua/plugins/linting.lua index ede4976..2f03ae0 100644 --- a/nvim/.config/nvim/lua/plugins/linting.lua +++ b/nvim/.config/nvim/lua/plugins/linting.lua @@ -22,6 +22,13 @@ return { vim.keymap.set("n", "l", function() lint.try_lint() end, { desc = "Trigger linting for current file" }) + vim.keymap.set("n", "d", function() + if vim.diagnostic.config().virtual_lines then + vim.diagnostic.config({ virtual_lines = false }) + else + vim.diagnostic.config({ virtual_lines = { current_line = true } }) + end + end, { desc = "Toggle inline diagnostics" }) end, }, }