diff --git a/after/ftplugin/go.vim b/after/ftplugin/go.vim new file mode 100644 index 0000000..d944013 --- /dev/null +++ b/after/ftplugin/go.vim @@ -0,0 +1 @@ +set formatoptions+=r " auto add comments on line return diff --git a/after/plugin/theme.lua b/after/plugin/theme.lua index 4505493..cdc565a 100644 --- a/after/plugin/theme.lua +++ b/after/plugin/theme.lua @@ -1,10 +1,7 @@ local c = require("base46.colors") -local g = vim.g -local M = {} local colors = require("base46").get_theme_tb "base_30" -local theme = require("base46").get_theme_tb "base_16" - +-- local theme = require("base46").get_theme_tb "base_16" local ts_context_hl = c.change_hex_saturation(colors["yellow"], -20) local ts_context_hl = c.change_hex_lightness(ts_context_hl, -55) @@ -30,3 +27,4 @@ end -- setup section set_hl() + diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 465df34..baed9a3 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -22,7 +22,7 @@ M.general = { --{{{ [""] = { " update ", "update file (save on changes)" }, -- luasnip change choice - [""] = { "luasnip-next-choice", "change luasnip choice" }, + [""] = { "luasnip-next-choice", "change luasnip choice" }, -- [""] = { "lua require('luasnip.extras.select_choice')()", "change luasnip choice" }, },--}}} diff --git a/lua/core/options.lua b/lua/core/options.lua index 0cade04..4cf1698 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -98,7 +98,7 @@ g.netrw_winsize = 20 -- width of the window (25%) opt.signcolumn = "yes" -opt.signcolumn = "auto:1-3" -- accommodate up to 3 icons +-- opt.signcolumn = "auto:1-3" -- accommodate up to 3 icons opt.splitbelow = true opt.splitright = true opt.termguicolors = true diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index 78a8c29..2e6f83a 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -102,7 +102,12 @@ M.ui = { }, DapBreakpointRejected = { fg = "purple" - } + }, + LuaSnipChoice = { + fg = "#ff4848", + bg = "one_bg3", + }, + }, -- hl_override = { -- CursorLine = { diff --git a/lua/custom/plugins/configs/luasnip.lua b/lua/custom/plugins/configs/luasnip.lua new file mode 100644 index 0000000..70dbf23 --- /dev/null +++ b/lua/custom/plugins/configs/luasnip.lua @@ -0,0 +1,37 @@ +local present, luasnip = pcall(require, "luasnip") + +if not present then + return +end + +local types = require("luasnip.util.types") + +local options = { + history = true, + updateevents = "TextChanged,TextChangedI", + ext_opts = { + [types.choiceNode] = { + passive = { + virt_text = { { " ", "LuaSnipChoice" } }, + } + } + }, +} + +M.setup = function() + luasnip.config.set_config(options) + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } + + vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, + }) +end + +return M diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua index 74fd203..5f3c863 100644 --- a/lua/custom/plugins/configs/navigator.lua +++ b/lua/custom/plugins/configs/navigator.lua @@ -32,6 +32,7 @@ local config = { { key = 'ct', func = require('navigator.ctags').ctags, desc = 'lsp ctags' }, { key = 'K', func = vim.lsp.buf.hover, desc = 'lsp hover' }, { key = '', mode = 'n', func = require('navigator.codeAction').code_action, desc = 'lsp code_action' }, + { key = '', mode = 'i', func = require('navigator.codeAction').code_action, desc = 'lsp code_action' }, { key = '', mode = 'v', diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 8acaafd..376cb4e 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -116,17 +116,18 @@ return { lock = false, config = function() -- load default config first - require("plugins.configs.others").luasnip() + require("custom.plugins.configs.luasnip").setup() vim.g.my_snippets_paths = { "./custom_snippets" } require("luasnip").filetype_extend("markdown", { "markdown_zk" }) -- load snippets from "honza/vim-snippets" -- includes ultisnips and snipmate snippets - require("luasnip.loaders.from_snipmate").lazy_load({ override_priority = 800 }) + -- default priority for snipmate is 1000 + require("luasnip.loaders.from_snipmate").lazy_load({ override_priority = 500 }) require("luasnip.loaders.from_snipmate").lazy_load { paths = vim.g.my_snippets_paths, - override_priority = 800 + override_priority = 600 } end }, -- }}} diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 99eca8d..f3fa96b 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -1,7 +1,7 @@ local present, cmp = pcall(require, "cmp") if not present then - return + return end require("base46").load_highlight "cmp" @@ -9,143 +9,154 @@ require("base46").load_highlight "cmp" vim.opt.completeopt = "menuone,noselect" local function border(hl_name) - return { - { "╭", hl_name }, - { "─", hl_name }, - { "╮", hl_name }, - { "│", hl_name }, - { "╯", hl_name }, - { "─", hl_name }, - { "╰", hl_name }, - { "│", hl_name }, - } + return { + { "╭", hl_name }, + { "─", hl_name }, + { "╮", hl_name }, + { "│", hl_name }, + { "╯", hl_name }, + { "─", hl_name }, + { "╰", hl_name }, + { "│", hl_name }, + } end local cmp_window = require "cmp.utils.window" +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 + cmp_window.info_ = cmp_window.info cmp_window.info = function(self) - local info = self:info_() - info.scrollable = false - return info + local info = self:info_() + info.scrollable = false + return info end local options = { - window = { - completion = { - border = border "CmpBorder", - winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + -- preselect = cmp.PreselectMode.None, + window = { + completion = { + border = border "CmpBorder", + winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + }, + documentation = { + border = border "CmpDocBorder", + }, }, - documentation = { - border = border "CmpDocBorder", + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, }, - }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - formatting = { - format = function(entry, vim_item) - local icons = require("nvchad_ui.icons").lspkind - vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) - -- show source - vim_item.menu = ({ - buffer = ":buf", - nvim_lsp = ":lsp", - luasnip = ":lsnp", - nvim_lua = ":lua", - latex_symbols = ":ltx", - })[entry.source.name] - return vim_item - end, - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - -- Try to emulate native neovim C-x completion style behavior - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = false, + formatting = { + format = function(entry, vim_item) + local icons = require("nvchad_ui.icons").lspkind + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) + -- show source + vim_item.menu = ({ + buffer = ":buf", + nvim_lsp = ":lsp", + luasnip = ":LuaS", + nvim_lua = ":lua", + latex_symbols = ":ltx", + })[entry.source.name] + return vim_item + end, }, - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = false, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + -- Try to emulate native neovim C-x completion style behavior + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + + -- luasnip forward jump + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.confirm() + else + fallback() + end + end, { + "i", + "s", + }), + -- luasnip reverse jump + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.confirm() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), }, - -- luasnip forward jump - [""] = cmp.mapping(function(fallback) - local luasnip = require("luasnip") - if luasnip.jumpable(1) then - luasnip.jump(1) - elseif luasnip.expandable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { - "i", - "s", - }), - -- luasnip reverse jump - [""] = cmp.mapping(function(fallback) - local luasnip = require("luasnip") - if luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { - "i", - "s", - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif require("luasnip").expand_or_jumpable() then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") - else - fallback() - end - end, { - "i", - "s", - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif require("luasnip").jumpable(-1) then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") - else - fallback() - end - end, { - "i", - "s", - }), - }, - sources = { - { name = "luasnip" }, - { name = "nvim_lsp" }, - { - name = "buffer", - option = { - get_bufnrs = function() - local bufs = {} - for _, win in ipairs(vim.api.nvim_list_wins()) do - bufs[vim.api.nvim_win_get_buf(win)] = true - end - return vim.tbl_keys(bufs) - end - }, + sources = { + { name = "luasnip", priority = 1000 }, + { name = "nvim_lsp", priority = 800 }, + { + name = "buffer", + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + bufs[vim.api.nvim_win_get_buf(win)] = true + end + return vim.tbl_keys(bufs) + end + }, + }, + { name = "nvim_lua", priority = 900 }, + { name = "path" }, }, - { name = "nvim_lua" }, - { name = "path" }, - }, } -- check for any override diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index ab7ad78..32a5fd7 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -106,35 +106,6 @@ M.comment = function() nvim_comment.setup(options) end -M.luasnip = function() - local present, luasnip = pcall(require, "luasnip") - - if not present then - return - end - - local options = { - history = true, - updateevents = "TextChanged,TextChangedI", - } - - options = load_override(options, "L3MON4D3/LuaSnip") - luasnip.config.set_config(options) - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.luasnippets_path or "" } - - vim.api.nvim_create_autocmd("InsertLeave", { - callback = function() - if - require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] - and not require("luasnip").session.jump_active - then - require("luasnip").unlink_current() - end - end, - }) -end - M.gitsigns = function() local present, gitsigns = pcall(require, "gitsigns") diff --git a/lua/plugins/configs/whichkey.lua b/lua/plugins/configs/whichkey.lua index 3bdbf8c..d4fa7ff 100644 --- a/lua/plugins/configs/whichkey.lua +++ b/lua/plugins/configs/whichkey.lua @@ -33,8 +33,8 @@ local options = { triggers_blacklist = { -- list of mode / prefixes that should never be hooked by WhichKey i = { "j", "k" }, - v = { "j", "k" }, - -- n = { "\"", "@" }, -- disable registers + v = { "j", "k", "" }, + n = { "\"", "@" }, -- disable registers }, } diff --git a/lua/spike/dap/dapmode.lua b/lua/spike/dap/dapmode.lua index 0be8931..01aa884 100644 --- a/lua/spike/dap/dapmode.lua +++ b/lua/spike/dap/dapmode.lua @@ -64,7 +64,12 @@ local config = { end, desc = '[dapui] float watches' }, - B = { + P = { + rhs = function() + require('dapui').float_element('scopes') + end, + desc = '[dapui] float scopes' + },B = { rhs = function() require('dapui').float_element('breakpoints') end, diff --git a/lua/spike/lsp/go.lua b/lua/spike/lsp/go.lua index cc84bbc..1cb1c6c 100644 --- a/lua/spike/lsp/go.lua +++ b/lua/spike/lsp/go.lua @@ -17,7 +17,8 @@ function M.gopls_onattach(client, bufnr) end - autocmd({"BufWritePre", "InsertLeave"}, { + -- autocmd({"BufWritePre", "InsertLeave"}, { + autocmd({"BufWritePre"}, { group = augroup(augroupname, {clear = true}), buffer = bufnr, callback = function()