From a5095db20d5bd4e8ce946ef7d1ea18e15b86bd23 Mon Sep 17 00:00:00 2001 From: Benedikt Schnatterbeck Date: Mon, 1 Aug 2022 20:13:48 +0100 Subject: feat(whichkey): add default keybindings to cycle to next buffer (#2873) --- lua/lvim/core/which-key.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index 3015781b..8f0f964f 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -1,5 +1,4 @@ local M = {} - M.config = function() lvim.builtin.which_key = { ---@usage disable which-key completely [not recommended] @@ -92,6 +91,7 @@ M.config = function() j = { "BufferLinePick", "Jump" }, f = { "Telescope buffers", "Find" }, b = { "BufferLineCyclePrev", "Previous" }, + n = { "BufferLineCycleNext", "Next" }, -- w = { "BufferWipeout", "Wipeout" }, -- TODO: implement this for bufferline e = { "BufferLinePickClose", -- cgit v1.2.3 From eefde00ae80f91ecf88a93e869e346fdd04c7ba4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:41:17 +0200 Subject: refactor!: migrate to mason.nvim (#2880) --- lua/lvim/core/builtins/init.lua | 1 + lua/lvim/core/info.lua | 4 ++-- lua/lvim/core/mason.lua | 41 +++++++++++++++++++++++++++++++++++++++++ lua/lvim/core/which-key.lua | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lua/lvim/core/mason.lua (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/builtins/init.lua b/lua/lvim/core/builtins/init.lua index e219d45e..5cad2a00 100644 --- a/lua/lvim/core/builtins/init.lua +++ b/lua/lvim/core/builtins/init.lua @@ -16,6 +16,7 @@ local builtins = { "lvim.core.notify", "lvim.core.lualine", "lvim.core.alpha", + "lvim.core.mason", } function M.config(config) diff --git a/lua/lvim/core/info.lua b/lua/lvim/core/info.lua index ac7d690a..da9ddbe6 100644 --- a/lua/lvim/core/info.lua +++ b/lua/lvim/core/info.lua @@ -111,9 +111,9 @@ local function make_auto_lsp_info(ft) return info_lines end - local available = lsp_utils.get_supported_servers_per_filetype(ft) + local supported = lsp_utils.get_supported_servers(ft) local skipped = vim.tbl_filter(function(name) - return vim.tbl_contains(available, name) + return vim.tbl_contains(supported, name) end, skipped_servers) if #skipped == 0 then diff --git a/lua/lvim/core/mason.lua b/lua/lvim/core/mason.lua new file mode 100644 index 00000000..39be4f42 --- /dev/null +++ b/lua/lvim/core/mason.lua @@ -0,0 +1,41 @@ +local M = {} + +function M.config() + lvim.builtin.mason = { + ui = { + keymaps = { + toggle_package_expand = "", + install_package = "i", + update_package = "u", + check_package_version = "c", + update_all_packages = "U", + check_outdated_packages = "C", + uninstall_package = "X", + cancel_installation = "", + apply_language_filter = "", + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, + + github = { + -- The template URL to use when downloading assets from GitHub. + -- The placeholders are the following (in order): + -- 1. The repository (e.g. "rust-lang/rust-analyzer") + -- 2. The release version (e.g. "v0.3.0") + -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz") + download_url_template = "https://github.com/%s/releases/download/%s/%s", + }, + } +end + +function M.setup() + local status_ok, mason = pcall(require, "mason") + if not status_ok then + return + end + + mason.setup(lvim.builtin.mason) +end + +return M diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index 8f0f964f..6d0dc9fc 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -160,7 +160,7 @@ M.config = function() w = { "Telescope diagnostics", "Diagnostics" }, f = { require("lvim.lsp.utils").format, "Format" }, i = { "LspInfo", "Info" }, - I = { "LspInstallInfo", "Installer Info" }, + I = { "Mason", "Mason Info" }, j = { vim.diagnostic.goto_next, "Next Diagnostic", -- cgit v1.2.3 From 5f9a0a5b203fa16acf433296f11a3fb93725785e Mon Sep 17 00:00:00 2001 From: Dlani Date: Tue, 9 Aug 2022 08:15:20 -0300 Subject: fix: handle deprecated telescope.builtin.internal (#2885) --- lua/lvim/core/which-key.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index 6d0dc9fc..b1cfdc03 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -252,7 +252,7 @@ M.config = function() k = { "Telescope keymaps", "Keymaps" }, C = { "Telescope commands", "Commands" }, p = { - "lua require('telescope.builtin.internal').colorscheme({enable_preview = true})", + "lua require('telescope.builtin').colorscheme({enable_preview = true})", "Colorscheme with Preview", }, }, -- cgit v1.2.3 From 3bc52f9988a58e3e1a2a48ee2299383d967a1573 Mon Sep 17 00:00:00 2001 From: Myles Mo <54089360+emxxjnm@users.noreply.github.com> Date: Tue, 9 Aug 2022 19:32:35 +0800 Subject: fix(lualine): set icon color according to the status of treesitter (#2754) Co-authored-by: emxxjnm --- lua/lvim/core/lualine/components.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/lualine/components.lua b/lua/lvim/core/lualine/components.lua index 49a8ff81..5095cfb4 100644 --- a/lua/lvim/core/lualine/components.lua +++ b/lua/lvim/core/lualine/components.lua @@ -70,13 +70,13 @@ return { }, treesitter = { function() - local b = vim.api.nvim_get_current_buf() - if next(vim.treesitter.highlighter.active[b]) then - return "" - end - return "" + return "" + end, + color = function() + local buf = vim.api.nvim_get_current_buf() + local ts = vim.treesitter.highlighter.active[buf] + return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red } end, - color = { fg = colors.green }, cond = conditions.hide_in_width, }, lsp = { -- cgit v1.2.3 From 0fc1e423097485035bd6c1f19d64ce8424387ca9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 20 Aug 2022 11:06:34 +0200 Subject: chore: bump plugins version (#2895) --- lua/lvim/core/bufferline.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/bufferline.lua b/lua/lvim/core/bufferline.lua index 28e0f06d..7e8f1376 100644 --- a/lua/lvim/core/bufferline.lua +++ b/lua/lvim/core/bufferline.lua @@ -45,10 +45,10 @@ M.config = function() }, highlights = { background = { - gui = "italic", + italic = true, }, buffer_selected = { - gui = "bold", + bold = true, }, }, options = { -- cgit v1.2.3 From 06fa62e6e9ea9b362d3c2340f4f4f843eb3cbc14 Mon Sep 17 00:00:00 2001 From: "Ed (Wright) Rosewright" Date: Mon, 22 Aug 2022 22:24:38 +0900 Subject: fix: update key bindings for comment.nvim to use new api (#2926) --- lua/lvim/core/which-key.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index b1cfdc03..2301943f 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -76,13 +76,13 @@ M.config = function() -- NOTE: Prefer using : over as the latter avoids going back in normal-mode. -- see https://neovim.io/doc/user/map.html#:map-cmd vmappings = { - ["/"] = { "lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())", "Comment" }, + ["/"] = { "(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" }, }, mappings = { [";"] = { "Alpha", "Dashboard" }, ["w"] = { "w!", "Save" }, ["q"] = { "lua require('lvim.utils.functions').smart_quit()", "Quit" }, - ["/"] = { "lua require('Comment.api').toggle_current_linewise()", "Comment" }, + ["/"] = { "(comment_toggle_linewise_current)", "Comment toggle current line" }, ["c"] = { "BufferKill", "Close Buffer" }, ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" }, ["h"] = { "nohlsearch", "No Highlight" }, -- cgit v1.2.3 From 9fcb6bbd8116caa498433f6ecb47e7acccfd0dcd Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 29 Aug 2022 13:53:58 +0200 Subject: refactor(cmp)!: adapt new recommendations (#2913) --- lua/lvim/core/autopairs.lua | 4 ++ lua/lvim/core/cmp.lua | 101 +++++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 52 deletions(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/autopairs.lua b/lua/lvim/core/autopairs.lua index 4d9f33f4..469a38a4 100644 --- a/lua/lvim/core/autopairs.lua +++ b/lua/lvim/core/autopairs.lua @@ -79,6 +79,10 @@ M.setup = function() if lvim.builtin.autopairs.on_config_done then lvim.builtin.autopairs.on_config_done(autopairs) end + pcall(function() + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end) end return M diff --git a/lua/lvim/core/cmp.lua b/lua/lvim/core/cmp.lua index 942a72f6..10cf56be 100644 --- a/lua/lvim/core/cmp.lua +++ b/lua/lvim/core/cmp.lua @@ -1,24 +1,23 @@ local M = {} M.methods = {} ----checks if the character preceding the cursor is a space character ----@return boolean true if it is a space character, false otherwise -local check_backspace = function() - local col = vim.fn.col "." - 1 - return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil end -M.methods.check_backspace = check_backspace +M.methods.has_words_before = has_words_before -local function T(str) +---@deprecated use M.methods.has_words_before instead +M.methods.check_backspace = function() + return not has_words_before() +end + +local T = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end ----wraps vim.fn.feedkeys while replacing key codes with escape codes ----Ex: feedkeys("", "n") becomes feedkeys("^M", "n") ----@param key string ----@param mode string local function feedkeys(key, mode) - vim.fn.feedkeys(T(key), mode) + vim.api.nvim_feedkeys(T(key), mode, true) end M.methods.feedkeys = feedkeys @@ -28,39 +27,21 @@ M.methods.feedkeys = feedkeys local function jumpable(dir) local luasnip_ok, luasnip = pcall(require, "luasnip") if not luasnip_ok then - return + return false end local win_get_cursor = vim.api.nvim_win_get_cursor local get_current_buf = vim.api.nvim_get_current_buf - local function inside_snippet() - -- for outdated versions of luasnip - if not luasnip.session.current_nodes then - return false - end - - local node = luasnip.session.current_nodes[get_current_buf()] - if not node then - return false - end - - local snip_begin_pos, snip_end_pos = node.parent.snippet.mark:pos_begin_end() - local pos = win_get_cursor(0) - pos[1] = pos[1] - 1 -- LuaSnip is 0-based not 1-based like nvim for rows - return pos[1] >= snip_begin_pos[1] and pos[1] <= snip_end_pos[1] - end - ---sets the current buffer's luasnip to the one nearest the cursor ---@return boolean true if a node is found, false otherwise local function seek_luasnip_cursor_node() + -- TODO(kylo252): upstream this -- for outdated versions of luasnip if not luasnip.session.current_nodes then return false end - local pos = win_get_cursor(0) - pos[1] = pos[1] - 1 local node = luasnip.session.current_nodes[get_current_buf()] if not node then return false @@ -69,6 +50,9 @@ local function jumpable(dir) local snippet = node.parent.snippet local exit_node = snippet.insert_nodes[0] + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 + -- exit early if we're past the exit node if exit_node then local exit_pos_end = exit_node.mark:pos_end() @@ -124,9 +108,9 @@ local function jumpable(dir) end if dir == -1 then - return inside_snippet() and luasnip.jumpable(-1) + return luasnip.in_snippet() and luasnip.jumpable(-1) else - return inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() + return luasnip.in_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable(1) end end M.methods.jumpable = jumpable @@ -241,48 +225,61 @@ M.config = function() mapping = cmp.mapping.preset.insert { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, { "i" }), + [""] = cmp.mapping(cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, { "i" }), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping { + i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, + c = function(fallback) + if cmp.visible() then + cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } + else + fallback() + end + end, + }, [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif jumpable() then + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + elseif jumpable(1) then luasnip.jump(1) - elseif check_backspace() then - fallback() + elseif has_words_before() then + cmp.complete() else fallback() end - end, { - "i", - "s", - }), + end, { "i", "s" }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() - elseif jumpable(-1) then + elseif luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end - end, { - "i", - "s", - }), - + end, { "i", "s" }), [""] = cmp.mapping.complete(), [""] = cmp.mapping.abort(), [""] = cmp.mapping(function(fallback) - if cmp.visible() and cmp.confirm(lvim.builtin.cmp.confirm_opts) then - if jumpable() then + if cmp.visible() then + local confirm_opts = lvim.builtin.cmp.confirm_opts + local is_insert_mode = function() + return vim.api.nvim_get_mode().mode:sub(1, 1) == "i" + end + if is_insert_mode() then -- prevent overwriting brackets + confirm_opts.behavior = cmp.ConfirmBehavior.Insert + end + cmp.confirm(confirm_opts) + if jumpable(1) then luasnip.jump(1) end return end - if jumpable() then + if jumpable(1) then if not luasnip.jump(1) then fallback() end -- cgit v1.2.3 From 68e8132b909dab6a748340f81c4b3a6ef452079d Mon Sep 17 00:00:00 2001 From: zenVentzi <11378653+zenVentzi@users.noreply.github.com> Date: Mon, 29 Aug 2022 15:13:57 +0300 Subject: fix(ts_context_commentstring): block comment match new api (#2948) --- lua/lvim/core/comment.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'lua/lvim/core') diff --git a/lua/lvim/core/comment.lua b/lua/lvim/core/comment.lua index 86a2091a..d07739c6 100644 --- a/lua/lvim/core/comment.lua +++ b/lua/lvim/core/comment.lua @@ -3,8 +3,24 @@ local M = {} function M.config() local pre_hook = nil if lvim.builtin.treesitter.context_commentstring.enable then - pre_hook = function(_ctx) - return require("ts_context_commentstring.internal").calculate_commentstring() + pre_hook = function(ctx) + local U = require "Comment.utils" + + -- Determine whether to use linewise or blockwise commentstring + local type = ctx.ctype == U.ctype.linewise and "__default" or "__multiline" + + -- Determine the location where to calculate commentstring from + local location = nil + if ctx.ctype == U.ctype.blockwise then + location = require("ts_context_commentstring.utils").get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require("ts_context_commentstring.utils").get_visual_start_location() + end + + return require("ts_context_commentstring.internal").calculate_commentstring { + key = type, + location = location, + } end end lvim.builtin.comment = { -- cgit v1.2.3