neovim configuration using rocks.nvim plugin manager
at main 3.0 kB view raw
1local Util = require("utils") 2local ls = require("luasnip") 3 4vim.snippet.expand = ls.lsp_expand 5 6---@diagnostic disable-next-line: duplicate-set-field 7vim.snippet.active = function(filter) 8 filter = filter or {} 9 filter.direction = filter.direction or 1 10 11 -- if filter.direction == 1 then 12 -- return ls.expand_or_locally_jumpable() 13 -- else 14 -- return ls.locally_jumpable(filter.direction) 15 -- end 16 return ls.locally_jumpable(filter.direction) 17end 18 19-- ---@diagnostic disable-next-line: duplicate-set-field 20-- vim.snippet.jump = function(direction) 21-- if direction == 1 then 22-- if ls.expandable() then 23-- return ls.expand_or_jump() 24-- else 25-- return ls.locally_jumpable(1) and ls.jump(1) 26-- end 27-- else 28-- return ls.locally_jumpable(-1) and ls.jump(-1) 29-- end 30-- end 31---@diagnostic disable-next-line: duplicate-set-field 32vim.snippet.jump = ls.jump 33 34vim.snippet.stop = ls.unlink_current 35 36ls.config.set_config({ 37 update_events = "TextChanged,TextChangedI", 38 history = true, 39 delete_check_events = "InsertLeave", 40 ext_opts = {}, 41}) 42 43vim.g.ls_next_choice_map = "<c-j>" 44 45vim.keymap.set({ "i", "s" }, "<c-]>", function() 46 if ls.expandable() then 47 vim.schedule(function() 48 ls.expand() 49 end) 50 else 51 return "<c-]>" 52 end 53end, { silent = true, expr = true }) 54vim.keymap.set({ "i", "s" }, vim.g.ls_next_choice_map, function() 55 if ls.choice_active() then 56 ls.change_choice(1) 57 end 58end) 59-- vim.keymap.set({ "i", "s" }, "<c-k>", function() 60-- if ls.choice_active() then 61-- ls.change_choice(-1) 62-- end 63-- end) 64 65local group = vim.api.nvim_create_augroup("UserLuasnip", { clear = true }) 66local ns = vim.api.nvim_create_namespace("UserLuasnip") 67vim.api.nvim_create_autocmd("User", { 68 group = group, 69 pattern = "LuasnipChoiceNodeEnter", 70 callback = function() 71 local node = ls.session.event_node 72 local line = node:get_buf_position()[1] 73 vim.api.nvim_buf_set_extmark(0, ns, line, -1, { 74 end_line = line, 75 end_right_gravity = true, 76 right_gravity = false, 77 virt_text = { { " " .. vim.g.ls_next_choice_map .. " to toggle ", "LspInfoTip" } }, 78 }) 79 end, 80}) 81local function delete_extmarks() 82 local extmarks = vim.api.nvim_buf_get_extmarks(0, ns, 0, -1, {}) 83 for _, extmark in ipairs(extmarks) do 84 vim.api.nvim_buf_del_extmark(0, ns, extmark[1]) 85 end 86end 87vim.api.nvim_create_autocmd("User", { 88 group = group, 89 pattern = "LuasnipChoiceNodeLeave", 90 callback = delete_extmarks, 91}) 92vim.api.nvim_create_autocmd("ModeChanged", { 93 group = group, 94 pattern = "*[isS\19]*:*[^isS\19]*", 95 callback = Util.debounce(50, function() 96 if vim.fn.mode():match("[^isS\19]") then 97 delete_extmarks() 98 end 99 end), 100}) 101 102for _, ft_path in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua", true)) do 103 loadfile(ft_path)() 104end