From 556fedaa0be63f64f30c704efd6b150c84af79ea Mon Sep 17 00:00:00 2001 From: afranco Date: Sun, 15 Dec 2024 23:46:12 +0000 Subject: [PATCH] chore(nvim): folds and better cmdline --- .config/nvim/lua/core/keymaps.lua | 4 + .config/nvim/lua/core/variables.lua | 4 +- .config/nvim/lua/plugins/cmp.lua | 37 ++-- .config/nvim/lua/plugins/lsp.lua | 253 +++++++++++----------------- .config/nvim/lua/plugins/misc.lua | 31 +++- .config/nvim/lua/plugins/ui.lua | 110 ++++++------ 6 files changed, 201 insertions(+), 238 deletions(-) diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua index 3ef2e92..be96bd2 100644 --- a/.config/nvim/lua/core/keymaps.lua +++ b/.config/nvim/lua/core/keymaps.lua @@ -19,3 +19,7 @@ vim.keymap.set('x', 'gp', '"+P', { desc = 'Paste from system clipboard' }) vim.keymap.set("n", "", "zz", {desc = "Center cursor after moving down half-page"}) vim.keymap.set("n", "", "zz", {desc = "Center cursor after moving down half-page"}) vim.keymap.set("n", "G", "Gzz", {desc = "Center cursor after moving down half-page"}) +--Run lua stuff (ty teej) +vim.keymap.set("n", "x", "source %") +vim.keymap.set("n", "x", ":.lua") +vim.keymap.set("v", "x", ":lua") diff --git a/.config/nvim/lua/core/variables.lua b/.config/nvim/lua/core/variables.lua index 718d8df..b904088 100644 --- a/.config/nvim/lua/core/variables.lua +++ b/.config/nvim/lua/core/variables.lua @@ -3,8 +3,8 @@ vim.g.mapleader = " " --termguicolors vim.opt.termguicolors = true --Relative line numbers -vim.wo.number=true -vim.wo.relativenumber= true +vim.wo.number = true +vim.wo.relativenumber = true --Remove search highlight vim.opt.hlsearch = false vim.opt.incsearch = true diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 7f96934..ba622d9 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -24,6 +24,28 @@ return { vim.opt.pumheight = 15 local lspkind = require("lspkind") + -- `/` cmdline setup. + cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, + }) + + -- `:` cmdline setup. + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { + name = "cmdline", + option = { + ignore_cmds = { "Man", "!" }, + }, + }, + }), + }) cmp.setup({ snippet = { expand = function(args) @@ -69,21 +91,6 @@ return { show_labelDetails = false })(entry, vim_item) formatted_entry.kind = (formatted_entry.kind or "") .. " " - -- local item = entry:get_completion_item() - -- if item.detail then - -- local detail = item.detail - -- if string.find(detail, "->") ~= nil then - -- local return_arrow = vim.split(detail, "->", { trimempty = true }) - -- detail = vim.trim(return_arrow[2] or "") - -- end - -- if string.len(detail) <= 10 then - -- print("<=10 " .. detail) - -- formatted_entry.menu = detail - -- else - -- print(">10 " .. detail) - -- formatted_entry.menu = nil - -- end - -- end return formatted_entry end }, diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index c7460f1..d3f949c 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,18 +1,31 @@ return { - -- Rename variable pop up { - "stevearc/dressing.nvim", - event = "VeryLazy", + "folke/lazydev.nvim", + ft = "lua", opts = { - input = { - override = function(conf) - conf.col = -1 - conf.row = 0 - return conf - end, + library = { + { path = "${3rd}/luv/library", words = { "vim%.uv" } } } } }, + { + 'nvim-java/nvim-java', + priority = 500, + config = function() + require('java').setup() + local lspconfig = require("lspconfig") + local lsp_defaults = lspconfig.util.default_config + local capabilities = + vim.tbl_deep_extend("force", lsp_defaults.capabilities, require("cmp_nvim_lsp").default_capabilities()) + capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true + } + lspconfig["jdtls"].setup({ + capabilities = capabilities, + }) + end + }, { "smjonas/inc-rename.nvim", opts = { @@ -27,151 +40,17 @@ return { }, lazy = false, config = function() - require("refactoring").setup() + require("refactoring").setup({}) end, }, { "williamboman/mason.nvim", event = "VeryLazy", - config = function() - local mason = require("mason") - vim.api.nvim_create_augroup("_mason", { clear = true }) - local options = { - PATH = "skip", - ui = { - icons = { - package_pending = " ", - package_installed = "󰄳 ", - package_uninstalled = " ", - }, - keymaps = { - toggle_server_expand = "", - install_server = "i", - update_server = "u", - check_server_version = "c", - update_all_servers = "U", - check_outdated_servers = "C", - uninstall_server = "X", - cancel_installation = "", - }, - }, - max_concurrent_installers = 10, - } - mason.setup(options) - end, - }, - { - "williamboman/mason-lspconfig.nvim", - event = "VeryLazy", - dependencies = { - "williamboman/mason.nvim" - }, - config = function() - local mason_lspconfig = require("mason-lspconfig") - local lspconfig = require("lspconfig") - - mason_lspconfig.setup({ - automatic_installation = false, - }) - - local lsp_defaults = lspconfig.util.default_config - local capabilities = - vim.tbl_deep_extend("force", lsp_defaults.capabilities, require("cmp_nvim_lsp").default_capabilities()) - - mason_lspconfig.setup_handlers({ - -- This is a default handler that will be called for each installed server (also for new servers that are installed during a session) - function(server_name) - lspconfig[server_name].setup({ - capabilities = capabilities, - }) - end, - ["gopls"] = function() - lspconfig["gopls"].setup({ - capabilities = capabilities, - settings = { - gopls = { - ["ui.completion.usePlaceholders"] = true, - ["ui.diagnostic.staticcheck"] = true, - ["ui.inlayhint.hints"] = { - assignVariablesTypes = true, - compositeLiteralFields = true, - compositeLiteralTypes = true, - constantValues = true, - functionTypeParameters = true, - parameterNames = true, - rangeVariableTypes = true - }, - } - } - }) - end, - ["lua_ls"] = function() - lspconfig["lua_ls"].setup({ - capabilities = capabilities, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - hint = { enable = true } - }, - }, - }) - end, - ["ltex"] = function() - lspconfig["ltex"].setup({ - capabilities = capabilities, - --Local on attach - on_attach = function(_, _) - -- rest of your on_attach process. - require("ltex_extra").setup() - end, - settings = { - ltex = { - language = "en-GB", - }, - additionalRules = { - enablePickyRules = true, - }, - }, - }) - end, - ["basedpyright"] = function() - lspconfig["basedpyright"].setup({ - capabilities = capabilities, - settings = { - verboseOutput = true, - autoImportCompletion = true, - basedpyright = { - analysis = { - typeCheckingMode = "all", - autoSearchPaths = true, - useLibraryCodeForTypes = true, - diagnosticMode = "openFilesOnly", - indexing = true, - }, - }, - }, - }) - end, - }) - end + opts = {} }, { "neovim/nvim-lspconfig", event = { "BufReadPost", "BufNewFile" }, - dependencies = { - "williamboman/mason-lspconfig.nvim" - }, config = function() local lspconfig = require("lspconfig") @@ -216,10 +95,83 @@ return { end, }) - -- ADD NVIM CMP AS A CAPABILITY local lsp_defaults = lspconfig.util.default_config local capabilities = vim.tbl_deep_extend("force", lsp_defaults.capabilities, require("cmp_nvim_lsp").default_capabilities()) + capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true + } + lspconfig["gopls"].setup({ + capabilities = capabilities, + settings = { + gopls = { + ["ui.completion.usePlaceholders"] = true, + ["ui.diagnostic.staticcheck"] = true, + ["ui.inlayhint.hints"] = { + assignVariablesTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + constantValues = true, + functionTypeParameters = true, + parameterNames = true, + rangeVariableTypes = true + }, + } + } + }) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + hint = { enable = true } + }, + }, + }) + lspconfig["ltex"].setup({ + capabilities = capabilities, + --Local on attach + on_attach = function(_, _) + -- rest of your on_attach process. + require("ltex_extra").setup() + end, + settings = { + ltex = { + language = "en-GB", + }, + additionalRules = { + enablePickyRules = true, + }, + }, + }) + lspconfig["basedpyright"].setup({ + capabilities = capabilities, + settings = { + verboseOutput = true, + autoImportCompletion = true, + basedpyright = { + analysis = { + typeCheckingMode = "all", + autoSearchPaths = true, + useLibraryCodeForTypes = true, + diagnosticMode = "openFilesOnly", + indexing = true, + }, + }, + }, + }) lspconfig["hls"].setup({ capabilities = capabilities, @@ -232,15 +184,6 @@ return { version = '^5', lazy = false }, - { - 'akinsho/flutter-tools.nvim', - lazy = false, - dependencies = { - 'nvim-lua/plenary.nvim', - 'stevearc/dressing.nvim', -- optional for vim.ui.select - }, - config = true, - }, { "rcarriga/nvim-dap-ui", event = "VeryLazy", diff --git a/.config/nvim/lua/plugins/misc.lua b/.config/nvim/lua/plugins/misc.lua index 3e75761..8595d5b 100644 --- a/.config/nvim/lua/plugins/misc.lua +++ b/.config/nvim/lua/plugins/misc.lua @@ -21,9 +21,30 @@ return { }, }, { - 'eandrju/cellular-automaton.nvim', - config = function() - vim.keymap.set("n", "fml", "CellularAutomaton make_it_rain") - end - } + "folke/snacks.nvim", + priority = 1000, + lazy = false, + opts = { + bigfile = { enabled = true }, + notifier = { enabled = true }, + notify = { enabled = true }, + quickfile = { enabled = true }, + statuscolumn = { enabled = true }, + dashboard = { enabled = true }, + input = { enabled = true }, + lazygit = { + enabled = true, + vim.keymap.set('n', 'lg', function() + Snacks.lazygit.open() + end) + }, + words = { + enabled = true, + debounce = 10, + vim.keymap.set('n', 'gn', function() + Snacks.words.jump(1, true) + end) + }, + }, + }, } diff --git a/.config/nvim/lua/plugins/ui.lua b/.config/nvim/lua/plugins/ui.lua index bd98dc4..1c90e13 100644 --- a/.config/nvim/lua/plugins/ui.lua +++ b/.config/nvim/lua/plugins/ui.lua @@ -19,25 +19,9 @@ return { "folke/noice.nvim", event = "VeryLazy", opts = { - views = { - cmdline_popup = { - position = { - row = "100%", - col = "0%", - }, - size = { - min_width = 60, - width = "97%", - height = "auto", - }, - }, - cmdline_popupmenu = { - relative = "editor", - position = { - row = "85%", - col = "0%", - }, - }, + cmdline = { + enabled = true, + view = "cmdline", }, lsp = { override = { @@ -47,50 +31,13 @@ return { }, }, presets = { - command_palette = true, - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = true, -- enables an input dialog for inc-rename.nvim + inc_rename = true, }, }, dependencies = { "MunifTanjim/nui.nvim", } }, - - -- { - -- "OXY2DEV/markview.nvim", - -- ft = "markdown", - -- dependencies = { - -- "nvim-treesitter/nvim-treesitter", - -- "nvim-tree/nvim-web-devicons", - -- }, - -- opts = { - -- modes = { "n", "no", "c" }, - -- callbacks = { - -- on_enable = function(_, win) - -- vim.wo[win].conceallevel = 2; - -- vim.wo[win].concealcursor = "c"; - -- end - -- } - -- } - -- }, - { - "karb94/neoscroll.nvim", - config = function() - local neoscroll = require('neoscroll') - neoscroll.setup({ - hide_cursor = false, - }) - local keymap = { - [""] = function() neoscroll.ctrl_u({ duration = 150 }) end, - [""] = function() neoscroll.ctrl_d({ duration = 150 }) end, - } - local modes = { 'n', 'v', 'x' } - for key, func in pairs(keymap) do - vim.keymap.set(modes, key, func) - end - end - }, { "folke/zen-mode.nvim", event = "VeryLazy", @@ -99,8 +46,49 @@ return { }, }, { - "NStefan002/screenkey.nvim", - lazy = false, - version = "*", -- or branch = "dev", to use the latest commit - }, + 'kevinhwang91/nvim-ufo', + dependencies = 'kevinhwang91/promise-async', + config = function() + vim.o.foldcolumn = '1' + vim.o.foldlevel = 99 + vim.o.foldlevelstart = 99 + vim.o.foldenable = true + vim.keymap.set('n', 'zR', require('ufo').openAllFolds) + vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) + local handler = function(virtText, lnum, endLnum, width, truncate) + local newVirtText = {} + local suffix = (' %d '):format(endLnum - lnum) + local sufWidth = vim.fn.strdisplaywidth(suffix) + local targetWidth = width - sufWidth + local curWidth = 0 + for _, chunk in ipairs(virtText) do + local chunkText = chunk[1] + local chunkWidth = vim.fn.strdisplaywidth(chunkText) + if targetWidth > curWidth + chunkWidth then + table.insert(newVirtText, chunk) + else + chunkText = truncate(chunkText, targetWidth - curWidth) + local hlGroup = chunk[2] + table.insert(newVirtText, { chunkText, hlGroup }) + chunkWidth = vim.fn.strdisplaywidth(chunkText) + -- str width returned from truncate() may less than 2nd argument, need padding + if curWidth + chunkWidth < targetWidth then + suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth) + end + break + end + curWidth = curWidth + chunkWidth + end + table.insert(newVirtText, { suffix, 'MoreMsg' }) + return newVirtText + end + + -- global handler + -- `handler` is the 2nd parameter of `setFoldVirtTextHandler`, + -- check out `./lua/ufo.lua` and search `setFoldVirtTextHandler` for detail. + require('ufo').setup({ + fold_virt_text_handler = handler + }) + end + } }